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

Subroutine Defining a Parameter

JGoode
Expert
Hi,

I am trying to define a parameter (Boolean) either yes or no depending on the result of a subroutine.

Here is a simplified bit of my script.
		line1X1 = x[10]: line1Y1 = y[10]	! S1 segment
			line1X2 = x[1]: line1Y2 = y[1]
			line2X1 = x[8]: line2Y1 = y[8]	! S2 segment
			line2X2 = x[7]: line2Y2 = y[7]
			T = (line1X1-line1X2) * (line2Y1-line2Y2) - (line1Y1-line1Y2) * (line2X1-line2X2)
			gosub "T"

			line1X1 = x[1]: line1Y1 = y[1]	! S1 segment
			line1X2 = x[10]: line1Y2 = y[10]
			line2X1 = x[9]: line2Y1 = y[9]	! S2 segment
			line2X2 = x[8]: line2Y2 = y[8]
			T = (line1X1-line1X2) * (line2Y1-line2Y2) - (line1Y1-line1Y2) * (line2X1-line2X2)
			gosub "T"

!***************************************************************************************
END
!***************************************************************************************

"T":
	E= 0.00000001
	if (T > 0.00000000001) or (T < -0.000000001)then
		temp1 = line1X1 * line1Y2 - line1Y1 * line1X2
		temp2 = line2X1 * line2Y2 - line2Y1 * line2X2
		tempx = temp1 * (line2X1-line2X2) - (line1X1-line1X2) * temp2
		tempy = temp1 * (line2Y1-line2Y2) - (line1Y1-line1Y2) * temp2
		cx = (tempx / T)
		cy = (tempy / T)
if(cx>=min(line1X1,line1X2)-E)and(cx<=max(line1X1,line1X2)+E)and(cx>=min(line2X1,line2X2)-E)and(cx<=max(line2X1,line2X2)+E)and(cy>=min(line1Y1,line1Y2)-E)and(cy<=max(line1Y1,line1Y2)+E)and(cy>=min(line2Y1,line2Y2)-E)and(cy<=max(line2Y1,line2Y2)+E)then
	state = 1
else
	state = 0
endif
endif
return

This would be fine, however I have 100+ different gosubs rather than just 1 so my script will run the gosub once and that one might make state = 1 but the next time it does a gosub it can obviously make it 0 so it cancels out. I want to be able to essentially stop the script when state = 1. How can I achieve this? (This script has been written in the parameter script)

Any help would be extremely appreciated!

Thanks
ArchiCAD 23

Windows 10
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Barry Kelly
Moderator
I wasn't really thinking at the time.
An END in the parameter script will probably just stop the parameter script from running - maybe not a good idea.
The other scripts will still run - so this may not be the best solution.
Maybe checking the 'state' before going to the gosubs would be the way to go

I think an END in the master script will stop everything - so use with caution there.

Moving the code and gosubs to the 3D script is fine if you just want to set a variable value in that script only, but you can't set a parameter value 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

View solution in original post

3 REPLIES 3
Barry Kelly
Moderator
If you want the script to stop as soon as 'state =1' then is it just a matter of adding an 'END' statement directly after?

i.e.

state = 1
END

You can have more than one 'END' in a script.

Otherwise wrap your initial code in an 'if state = 0 then ... endif'

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
JGoode
Expert
Hi Barry,

well that's what I assumed but it was not working at all for some reason that I couldn't seem to work out.

I had to copy and paste my extremely large amount of code into my 3D script to get my object to do what I wanted.

Having an end in a subroutine in the parameter script just didn't work.
ArchiCAD 23

Windows 10
Solution
Barry Kelly
Moderator
I wasn't really thinking at the time.
An END in the parameter script will probably just stop the parameter script from running - maybe not a good idea.
The other scripts will still run - so this may not be the best solution.
Maybe checking the 'state' before going to the gosubs would be the way to go

I think an END in the master script will stop everything - so use with caution there.

Moving the code and gosubs to the 3D script is fine if you just want to set a variable value in that script only, but you can't set a parameter value 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