BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Help with script

Anonymous
Not applicable
I may be being stupid but, I hope that someone v. kind can assist.

I have two variables h and lg, both controlled by user input and by hotspots in 3D. h is always less than lg, but the difference between the variables is not always the same, because the user can set either independently.

BUT... I want the difference between the two variables to remain the same when the user varies the larger of the two i.e. lg. The problem seems to be that if I establish the relationship, any increase in lg automatically affects the difference. I have tried PUTs and GETs but this one has me completely stumped.

Can anyone, PLEASE, help?
13 REPLIES 13
Anonymous
Not applicable
Mikes, what you said is too difficult to understand.

Would you like to show me some code?
Rob
Graphisoft
Graphisoft
mate, you have to write dependency script in the parameter script window, something like this:

IF GLOB_MODPAR_NAME="lg" THEN PARAMETERS h=*whatever formula here to get it right*

so, it means when lg gets changed (GLOB_MODPAR_NAME stores the very last changed parameter name, be careful it's case sensitive) it will 'force' parameter h to a defined equation
::rk
Anonymous
Not applicable
Tanks for the reply. I am getting somewhere with this. I have tried the GLOB_MODPAR_NAME technique, but it doesn't quite work because the important thing is that it is the difference before the parameter is changed that determines the later relationship. As soon as you change the parameter the difference has changed!
Wolf (see earlier reply from him in this topic) helped me towards this with some suggestions we traded by private messaging, but I haven't got it to work perfectly yet. His original idea didn't work, but it steered me in the right direction.
One problem I encountered was that GLOB_MODPAR_NAME didn't seem to work until I used a 'workaround' provided by my reseller. This involved setting up a new text parameter (in the Parameters script) to read and store the value of GLOB_MODPAR_NAME. I used a new parameter called var.

The current status of the in the master script is as follows:

IF var="lg" THEN
PARAMETERS old_diff=h-lg
ENDIF

IF var="h" THEN
lg=h-old_diff
ENDIF

This may seem somewhat confusing based on my first post on this topic, because, in fact, h must always be greater than lg.

This little script does not achieve the required effect when h is changed for the first time after lg has changed, but if the parameter h is varied for a second time, then the relationship of lg to h is maintained. So my task is now to find out why that happens and to try to fix it. Any ideas would be greatly appreciated.

The curious thing is that although old_diff is now defined as a (hidden) parameter, if the script is changed as follows:

IF var="lg" THEN
PARAMETERS old_diff=h-lg
ENDIF

IF var="h" THEN
PARAMETERS lg=h-old_diff
ENDIF

the script doesn't work even on the second 'iteration'!! (N.B. h, and lg, are both parameters)
Anonymous
Not applicable
Mike,

It might help if you explain what you are trying to do in real terms. What is this part? Why does it need this particular relationship between the parameters?

It does seem that if you need a value existing before the parameter changes, just put it into a place holder variable that you only use if the parameter is changed.
Anonymous
Not applicable
Matthew

Thanks for your reply. For reasons I don't wish to go into in this forum, I don't want to disclose the nature of the object.

But in general terms, I have an object that has (amongst others) two parameters that the user can vary, either in the object's settings interface or by using stretchy hotspots in the 3D window.

One parameter, h, will always be longer than the other, lg. (This reverses the relationship described in my initial post here, but the principle remains the same.)

Both parameters are used to determine the length of inter-related parts of the object.

I want to be able to set things up such that lg (the smaller dimension) can be adjusted without affecting h, but that when h is adjusted, the difference - not the ratio - between h and lg is maintained - subject, of course, to control parameters to prevent impossibilities, which are established in a RANGE declaration.

I have failed to crack this 'little' problem and have been struggling for several hours now (and several more hours of trial-and-error before I resorted to seeking help via the forum).

Simply put as a script (not in GDL) with all 'changes' made by user input:

IF lg changes THEN, the difference between h and lg is then calculated and stored as, say, old_diff, and, of course, lg changes.

h remains unaffected by the change in lg

IF h changes THEN lg changes to h-old_diff, and, of course, h changes.

OR in GDL (theoretically, and ignoring the constraints established in a RANGE declaration)

IF GLOB_MODPAR_NAME="lg" THEN old_diff=h-lg

IF GLOB_MODPAR_NAME="h" THEN lg=h-old_diff

Put like that it seems very simple, but the reality seems to be very different. As far as I can tell there are no script steps or evaluations elsewhere that are going to affect either h or lg, other than the RANGE statement. I have tried omitting the RANGE declaration with virtually every attaempt, but still haven't had success!!

I hope this helps to clarify things, but if I haven't made myself clear enough I would be only too pleased to be able to try to explain again.
__archiben
Booster
in the parameters script:
!! control your "lg" parameter
IF lg > h THEN
lg = h/2 !! or how ever you want to control it
ENDIF

!! establish the difference between the two
msDiff= h - lg  !! set difference regardless of "lg" changing or not!
IF GLOB_MODPAR_NAME = "lg" THEN
msDIff = h - lg
ENDIF

!! redefine "lg" if "h" changes as described before
IF GLOB_MODPAR_NAME = "h" THEN
lg = h - msDiff
PARAMETERS lg = lg
ENDIF
unless you've got some other super-secret stuff going on in there that affects it, this ought to work right?

~/archiben
b e n f r o s t
b f [a t ] p l a n b a r c h i t e c t u r e [d o t] n z
archicad | sketchup! | coffeecup
Anonymous
Not applicable
I am still not having success!! I have now stripped the scripts to the bare bones.

Here are the scripts:

Firstly the parameters are: h; lg; BrktDst; swan; d; old_diff - these are all length parameters. The last one is var, to ensure that GLOB_MODPAR_NAME works and is a text parameter.

Set the metric initial values as follows, for example: h=1600; lg=1200; BrktDst=50; swan=300; d=50; old_diff and var are calculated and would normally be hidden parameters.

The Master script is as follows:
r=d/2
v=22.5
ang=v/2
cosv=COS(v)
sinv=SIN(v)
tanv=TAN(v)
k=swan-(r+BrktDst)

!IF var="lg" THEN
!PARAMETERS old_diff=h-lg
!ENDIF

!IF var="h" THEN
!lg=h-old_diff
!ENDIF


The parameters script is as follows, along the lines described by archiben, earlier:

VALUES "var" GLOB_MODPAR_NAME

VALUES "lg" RANGE (0,h-k*tanv-2*d)

!! establish the difference between the two
old_diff=h-lg !! set difference regardless of "lg" changing or not!
IF var="lg" THEN
old_diff=h-lg
ENDIF

!! redefine "lg" if "h" changes as described before
IF var="h" THEN
lg=h-old_diff
PARAMETERS lg=lg
ENDIF


The 3D script is as follows:

unID=1

HOTSPOT 0,0,0,unID,h,1+256: unID=unID+1
HOTSPOT 0,0,-h,unID,h,3: unID=unID+1
HOTSPOT 0,0,h,unID,h,2+128: unID=unID+1

HOTSPOT 0,0,0,unID,lg,1+128: unID=unID+1
HOTSPOT 0,0,-lg,unID,lg,3: unID=unID+1
HOTSPOT 0,0,lg,unID,lg,2: unID=unID+1
LIN_ 0,0,lg,0,0,lg+0.06
LIN_ 0.004,0,lg+0.05,0,0,lg+0.06
LIN_ -0.004,0,lg+0.05,0,0,lg+0.06

ADDY -BrktDst
HOTSPOT 0,swan,0,unID,h,1+128: unID=unID+1
HOTSPOT 0,swan,-h,unID,h,3: unID=unID+1
HOTSPOT 0,swan,h,unID,h,2: unID=unID+1
LIN_ 0,swan,h,0,swan,h+0.015
LIN_ 0.003,swan,h+0.01,0,swan,h+0.015
LIN_ -0.003,swan,h+0.01,0,swan,h+0.015
DEL 1

IF swan>0 THEN
ADDY -BrktDst-r
FOR ct=1 to 2
HOTSPOT r,0,h,unID,swan,1+128: unID=unID+1
HOTSPOT r,-swan,h,unID,swan,3: unID=unID+1
HOTSPOT r,swan,h,unID,swan,2: unID=unID+1
MUL -1,1,1
NEXT ct
DEL 3
ENDIF

rotz 90
cone lg,r,r,90,90+v+ang

add k,0,lg+(k*tanv)
cone h-(lg+k*tanv),r,r,90+v+ang,90
del 2

addz lg
rotx -(v+45)
rotz 90

cone k/cosv,r,r,90-(v+ang),90-(v+ang)
del 3

END

I think that you will find that the relationship that I require is not maintained i.e when h changes lg follows at the same distance, but when lg changes h remains the same.

If you convert the emboldened script steps in the Parameters script to comments; and un-comment the emboldened steps in the Master script, you will find that the script works - but ONLY when you change h for the SECOND (or successive) time(s), without having changed lg!!

Can anyone spot where this is going wrong? It's driving me nuts!!
Rob
Graphisoft
Graphisoft
Mike,

try this in the parameter script window:

PARAMETERS old_diff=h-lg
IF GLOB_MODPAR_NAME="h" THEN PARAMETERS lg=h-old_diff
IF GLOB_MODPAR_NAME="lg" THEN PARAMETERS h=lg+old_diff
::rk
Anonymous
Not applicable
Rob

That works, but only if the value of h is reduced, if h is increased the upper part of the object extends upwards without the lower part following!

I do appreciate your input, and many thanks for looking at this!!

Mike
Learn and get certified!