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

How to change parameters and keep dimensione of an object?

Durval
Booster
This is an experimental object whose purpose is to test a code that changes parameters (by means of 'GLOB_MODPAR_NAME') in order to keep objects parts unchanged. Once resolved, I intend to apply the concept to other real life objects.

It draws two rectangles. The second rectangle is always the height of the first plus a constant 'gap'.

There is a parameter called 'method', whose value can be 1 ou 2.

If method = 1, the 'B' parameter will be the height of first rectangle (h1=B), so the second rectangle has a height of B+gap.

If method = 2, then ' B' should be the height of the second rectangle (h2=B), so h1=B-gap.

I don't want the heights change when method is changed. Instead, I want the 'B' is recalculated so that the heights remain the same.

For instance, method=1, so h1=B=1000 and h2=1500. When method is changed to 2, then h1 should remain =1000 and h2=1500, but B must change from 1000 to 1500.

I wrote these scripts:
 
!---- Master Script 
 
gap = 0.5 
 
IF method = 1 THEN 
	h1 = B 
	h2 = B+gap 
ELSE 
	h1 = B-gap 
	h2 = B 
ENDIF 
 
 
 
!--- Parameter Script 
 
VALUES "method" 1, 2 
 
IF GLOB_MODPAR_NAME = "method" THEN  
   IF method = 1 THEN  
      PARAMETERS B = B-gap 
   ELSE  
      PARAMETERS B = B+gap 
   ENDIF  
ENDIF 
 
 
!--- 2D Script 

RECT2 0, 0, A, h1  
ADD2 1, 0 
RECT2 0, 0, A, h2 
DEL 1



What happens is that 'gap' is added/subtracted TWICE every time I change 'method' (in my example, B goes from 1000 to 2000 instead of 1500 when method goes from 1 to 2).

So I changed the Parameter Script to this:
!--- Parameter Script 
 
VALUES "method" 1, 2 
 
IF GLOB_MODPAR_NAME = "method" THEN  
   IF method = 1 THEN  
      PARAMETERS B = B-(gap/2) 
   ELSE  
      PARAMETERS B = B+(gap/2) 
   ENDIF  
ENDIF 


And the code works as expected. But in the real-life objects I intend to write, it won't be so easy to compensate this difference.

So the question is: why the code within 'IF GLOB_MODPAR_NAME....' is executed twice when I change the parameter only onceand how could I correct this misbehavior?
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
LGreen
Booster
Hi Durval,

This happens because the parameter script can be run multiple times, thus resulting in the calculation occurring twice or more. I had this exact problem last year and it's a simple solution. Here is the topic I started. It has a working object in my last reply. Essentially you need to insert the code below from Michael Rensing (Found in this topic) which only runs part of the script if it is the first time the script is being run.
Michael wrote:
This should do it.

	n = APPLICATION_QUERY ("PARAMETER_SCRIPT", "FIRSTOCCASION_IN_PROGRESS", isFirstRun)
	IF isFirstRun THEN
		A=A+1
	ELSE
		A=A
	ENDIF
Lachlan Green | Architect | Drafter
AusBuild
AC23 & 25 | Windows 10 | Intel 11Gen Core i7 | 2.5GHz | 32GB RAM | Nvidia T1200

View solution in original post

3 REPLIES 3
Durval
Booster
The object is attached.
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14
Solution
LGreen
Booster
Hi Durval,

This happens because the parameter script can be run multiple times, thus resulting in the calculation occurring twice or more. I had this exact problem last year and it's a simple solution. Here is the topic I started. It has a working object in my last reply. Essentially you need to insert the code below from Michael Rensing (Found in this topic) which only runs part of the script if it is the first time the script is being run.
Michael wrote:
This should do it.

	n = APPLICATION_QUERY ("PARAMETER_SCRIPT", "FIRSTOCCASION_IN_PROGRESS", isFirstRun)
	IF isFirstRun THEN
		A=A+1
	ELSE
		A=A
	ENDIF
Lachlan Green | Architect | Drafter
AusBuild
AC23 & 25 | Windows 10 | Intel 11Gen Core i7 | 2.5GHz | 32GB RAM | Nvidia T1200
LiHigh
Newcomer
Create 2 new Parameters:
h = 1000
gap = 500
---------------------------------

h1 = h
h2 = h+gap

IF method=1 THEN
PARAMETERS B=h1
ELSE
PARAMETERS B=h2
ENDIF
Howard Phua

Win 10, Archicad 19 INT