GDL
About building parametric objects with GDL.

Keep A/B ratio while streching an object?

Mats Knutsson
Advocate

Hi, 

How can I lock the ratio A/B of an object so it's now skewable?

Again I can't choose GDL asa label when posting...

/Mats

7 REPLIES 7
DGSketcher
Legend

Do you mean so it sticks as A = 100mm & B = 200mm and can't be changed or have it so if after stretching A = 200mm so B will change to 400mm?  

 

Are you using stretchy hotspots or just typing in A/B?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)

@DGSketcher wrote:

Do you mean so it sticks as A = 100mm & B = 200mm and can't be changed or have it so if after stretching A = 200mm so B will change to 400mm?  

 

Are you using stretchy hotspots or just typing in A/B?


Yes, it's a rescale basically...

Stretchy hotspots 🙂 (sounds cool btw)

DGSketcher
Legend

You need to store a variable objRatio = A/B

 

Then in the Parameter Script use GLOB_MODPAR_NAME to do something along the lines of...

 

objRatio = A/B !stores current ratio

 

if GLOB_MODPAR_NAME = "A" then

 B = A / objRatio

parameters B = B

endif

if GLOB_MODPAR_NAME = "B" then

 A = B * objRatio

parameters A = A

endif

 

This will give priority to the A value if both are changed. I haven't tested this but it should point you in the right direction.

 

You should have a look in the GDL guide for HOTSPOTS if you aren't already using them.

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)
Barry Kelly
Moderator

@Mats Knutsson wrote:

Again I can't choose GDL asa label when posting...


There is a separate GDL forum in the Developer Hub section.

The other forum is just about the use of the libraries and object, not the scripting of them.

 

I have moved this post there.

 

Barry.

 

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Lingwisyer
Guru

Alternatively, given it is just scaling, do you even need to have the two variables editable? Could you just use a single variable and a MUL command?

 

Using a scale factor of x: MUL2 A(x), B(x)

Using the original size x of A: MUL2 x/A, x/A

 

MUL A/0.24, A/0.24, A/0.24
BRICK 0.24, 0.09, 0.086

 

 

Ling.

 

Derp, none of the available fonts are cursive.... sad x....

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660

If I script them myself I do control stretching but this is just for quick and dirty DYI-objects that any user can create just by drawing something, select it and save as an object. If the code as DGSketcher kindly wrote down can be copied and pasted it into the object then I'm happy.

If it is an object that is made simply by using the menu command, they already use MUL to scale. Edit 3 lines and you're done.

 

2D Script:

 

!mul2     A/1.000000, B/1.000000

mul2     A/1.000000, A/1.000000  !Line 1

 

 

3D Script

 

!mulx	A/           1
!muly	B/           1
!mulz	ZZYZX/       1

mulx	A/           1
muly	A/           1  !Line 2
mulz	A/           1  !Line 3

 

ie. You just change all the MUL commands to reference only A. B and ZZYZX will now do nothing. You can swap around to use which ever you want.

Example is from a 1x1x1 box

 

If you want, you can also hide the now useless parameters by adding the following to the Master Script.

 

 

HIDEPARAMTER "B"
HIDEPARAMTER "ZZYZX"

 

 

 

 

Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660