On Land

Environment Information
At Rill Architects we run ArchiCAD on Mac OS X. If you work at Rill, this is your stuff. If you don't, but you work in ArchiCAD, you may find something interesting. Anybody else, I don't know.

We have several objects offer the user a group of roof slope selection parameters. You can select an n/12 slope from the list, or you can enter a custom slope angle. When you select a slope, the angle changes. When you put in an angle, the slope parameter will show n/12 if there is a match, and 'Custom' if not.

I use GLOB_MODPAR_NAME statements to keep such parameters in sync. In the code there are a bunch of IF/THEN statements associating the angles and the named slopes.

Since this lookup is used by several objects, I keep it in a macro and use RETURNED_PARAMETERS to get the data back to the calling object.

A script can make use of separate object files by using the CALL statement. Such external objects are known as macros. In a CALL statement, the PARAMETERS keyword sends values to parameters in the macro. The RETURNED_PARAMETERS keyword receives parameter values from the macro.

Here's a pair of lookup calls. When you change the slope name (slpName), the call sends the name to the macro 'SlopeLookupJM10' and asks for the angle. Then the local parameter (slpDeg) is given the returned value:

	CALL 'SlopeLookupJM10' PARAMETERS lookup=2,
		slpName=slpName RETURNED_PARAMETERS slpDeg
	PARAMETERS slpDeg=slpDeg
	PARAMETERS slpHgt=slpHgt

This code asks for the slope (slpName) based on the angle:

	CALL 'SlopeLookupJM10' PARAMETERS lookup=1,
		slpDeg=slpDeg RETURNED_PARAMETERS slpName
	PARAMETERS slpName=slpName
	PARAMETERS slpHgt=slpHgt

The variable 'lookup' tells the macro what kind of lookup to do.

'slpHgt' is the height of the triangle with the given angle and whatever length value (usually the object's length or width). It is calculated locally in either case.

Within the lookup macro there are two data sets in the form of series of IF/THEN statements. To get the slope name from the angle in degrees, the macro compares the angle to the value of each n/12 slope (arctangent of n/12). If the angle matches a slope, the flag variable 'flg' is set to 1. If by the end of list no match is found, 'flg' remains 0 and the slope name is set to 'Other'.

IF lookup = 1 THEN ! name from deg
	IF ABS(slpDeg-ATN(1/12))

The ABS()<eps syntax is needed to prevent rounding errors. "slpDeg=ATN(1/12)" is functionally the same as "ABS(slpDeg-ATN(1/12)<eps" when 'eps' is very tiny. The value of 'eps' is set to 0.0001 at the beginning of the script.

To get the angle in degrees from the slope name, the macro simply calculates the arctangent:

IF lookup = 2 THEN ! deg from name

	IF slpName='1/12' THEN slpDeg=ATN(1/12)
	IF slpName='2/12' THEN slpDeg=ATN(2/12)
	IF slpName='15/12' THEN slpDeg=ATN(15/12)
	IF slpName='Flat' THEN slpDeg=0
	IF slpName='Vertical' THEN slpDeg=90

To send the value back to the calling object, you put the parameter name after the END keyword. What parameter gets sent also depends on the value of the 'lookup' variable:
IF lookup = 1 THEN END slpName
IF lookup = 2 THEN END slpDeg
To review, if the caller has
...then the macro needs to have
END slpDeg
Download (AC11)