We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

"semi" global variable

Anonymous
Not applicable
This one has been bugging me for a while now and just can't figure it out. I'm having trouble with an object I made some time ago, the Multi Group Sequential Numberer (in the depository)

It has proven to be invaluable when numbering parking spaces when there are over 1000 in several stories and the layout keeps changing. Because of the way it was coded, there is a variable that gets calculated inside the 2D script that counts the total number of parking spaces and displays it as text. Back then I used a user_global_variable to be able to read that value and pass it to the parameter script, so I the could use this value in schedules.

It had been working great until I noticed that the global variable value gets carried over to the next object I select. The parameter shows the carried value upon first opening the settings for the object, hit ok or cancel and open it again and it shows the correct value, as the global_variable gets recalculated. I just hadn't picked on that one. Somehow rebuilds took care of this, but now I'm seeing count errors because of this.

So... after a large explanation:
Is there a way to pass a value from the 2D script to the parameter so it can be scheduled without using a global variable? or a "semi" global variable that has a scope of master, 2d, 3d or parameter script but not outside the object?

What I'm really trying to avoid is to rewrite a great deal of code just to put all calculations in the master script (which now I know I should've done) and leave only lines and such in the 2D script. And because of the way it works, I can't find a way to calculate the value in the master_script.

I tried to put the whole thing in the master script and erased the use of the global variable, and works great in 2D, but even though it has no 3D info, there's an error saying I can't delete transformations above TOP when opening the 3D window, so I would need to review the whole thing anyway to check transformations.

I also tried GLOB_CONTEXT to limit the extents to the floor plan and editing window but it just locks the whole thing, and can't be edited anymore.

Any pointers would be appreciated.
Best Regards.
7 REPLIES 7
Anonymous
Not applicable
Got this thing working the way I wanted. Didn't find a way to access the value from the 2D script and give it back to a parameter (using PARAMETERS), so moved again the whole code to the master script and worked out the GLOB_CONTEXT issue.

It's logical now, but I guess it should be noted in the GDL reference guide that not including EVERY context the object will be working on kinda locks it. I had used GLOB_CONTEXT 2 for the floor plan, but didn't work on the library part editor, so I added GLOB_CONTEXT 1 also; but this didn't solve the locked graphical hotspots, until I added GLOB_CONTEXT 22... graphical editing mode in the floor plan. In the end, the code was:
IF GLOB_CONTEXT=1|GLOB_CONTEXT=2|GLOB_CONTEXT=5|GLOB_CONTEXT=22 THEN
	GOTO "START"
ELSE
	END
ENDIF
and then added a label for the beginning of the script. Still gives the transformations DEL error when switching to side view or 3d view in the settings dialog (GLOB_CONTEXT 5)... but I can live with that for now.

Still, any other ideas are welcome.
Cheers!

*will update the object in the depository as soon as I clean up the code a little.
rocorona
Booster
Not clever solutions, from me, but it is clear the origin of the error message. Every command that "can be" executed in the 3D Script, will be executed from the Master Script when the 3D has to be interpreted.
So, ADD2 ROT2 and MUL2 are ignored, but DEL are executed, as this command (like PEN and a few more) doesn't have different names for 2D and 3D Scripts.
As a "brute solution" I suggest you to simply add something like this, on top of your Master Script
FOR f=1 TO 50 
   ADDx  1 
   ADDx -1 
NEXT f

so the 3D transformation stack doesn't run out of data...
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________
Anonymous
Not applicable
Spot on Roberto. Thanks! I just wasn't aware of that. It may be a little brute force, but it is a clever cheat on the stack, and actually makes sense now that you've explained the error source. I'll check it to see how it behaves, because the code is "loopy" enough already.

I did change some of the DEL commands to DEL TOP and those worked, but I would need to review every transformation because in some places it changes the original behavior of the 2Dscript.

In the end, I'm actually thinking of rewriting the whole thing, but just don't have the time right now.

Thanks for the info.
rocorona
Booster
You can also try to completely avoid DEL commands, simply performing the opposite transformation. Eg.:
ROT2 45  
ADD2 1, 0 
[commands] 
ADD2 -1, 0 
ROT2 -45 ! instead of DEL 2


OR
use a more complex form, substituting each
DEL 

(interpreted as DEL 1) with
DEL (MIN(NTR(),1)

that acts as DEL 0 if the transformation stack is empty... I can't test it now, not sure if it works! IF DEL 0 is not accepted, then an IF...THEN will solve, but this require an heavy job on the already written scripts
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________
Anonymous
Not applicable
Avoiding DEL commands is what I had thought also, after you explained the error source. I don't know if the complex form would work, because ending with a DEL 0 just wouldn't be useful if 2D transform commands are ignored, because the stack would always be empty when interpreting for 3D, right?... and I still need to delete transformations.

Thanks a lot for your help.
rocorona
Booster
I made some mistake (1st assuming from my memory that DEL would work also without argument, 2nd putting the wrong nr. of parenthesis in the last formula) but the "complex solution" works, in my test. The transformation stacks are not mixed, so the NTR() gives a positive result interpreting the 2D, and zero in the 3D.

These instructions in the Master Script are "(message) error free"
CIRCLE2 0, 0, 0.2  
BLOCK 1, 1, 1  
  ADD2 1, 0  
CIRCLE2 0, 0, 0.2  
SPHERE 0.5  
  DEL MIN(NTR(), 1)  
  ADD2 0, 1  
CIRCLE2 0, 0, 0.2  
  DEL MIN(NTR(), 1)  
CIRCLE2 0, 0, 0.1  
CIRCLE 1  


In 2D they are interpreted as
CIRCLE2 0, 0, 0.2  
  ADD2 1, 0  
CIRCLE2 0, 0, 0.2  
  DEL 1  
  ADD2 0, 1  
CIRCLE2 0, 0, 0.2  
  DEL 1  
CIRCLE2 0, 0, 0.1

resulting in 3 circles with a smaller 4th inside the firs one. And the origin point reset to the default 0,0 position.


In 3D the same are interpreted as
BLOCK 1,1,1  
SPHERE 0.5  
  DEL 0  
  DEL 0  
CIRCLE 1

resulting in a cube with a "saturn" on a corner. No error messages.
_________________

--Roberto Corona--
www.archiradar.com
AC18 - ITA full on Win10
_________________
_________________
Anonymous
Not applicable
For the 3D script error, you can change code with the 3d equivalent syntax and then insert Project2 in 2d script. No DEL errors and you don't have to rewrite everything.