Below are some of the tips I think would be very helpful to any newbie (based on my own recent experience ). I’ll post more as I get to them, please feel free to post your own. If we get enough, then at some point I’ll put them into a more organized document.
Ken
INTERPRETING THE VALUE RETURNED BY [IGetFlags, layername]:
From my testing:
LAYER BITS: (counting from bit 0 as the least significant bit.)
Bit 0: 1 if enabled, 0 if not
Bit 1: 1 if active layer, 0 if not
Bit 2: ???
Bit 3: 1 if created, 0 if not
Use bitwise and to test for condition, eg. [if, 8 & [IGetFlags, layer], …layer has been created…]
The numeric value to use in the & is 2^(bit number)
LOGICAL OPERATORS
||, &&: Boolean or, and
|, &: Bitwise or, and
QUOTING CONTROL NAMES
Using an unquoted control name with spaces (eg Layer:Layer Clear) will sometimes work, but not always.
In general, quote all of your control names. Not doing so can lead to bugs that are very difficult to
detect.
RETURNING VALUES
A custom function (defined with RoutineDef) cannot return a result directly, as can
the builtin functions. However, it can pass a value back through an argument, eg.
[RoutineDef, fun,
…
[VarSet, outX, …something…]
… ,
outX]
[VarDef, myX, 0]
[RoutineCall, fun, myX]
// now myX will have the value assigned to outX in fun
Such variables can be of any name, but for ease of reading, name output variables outSomething,
and name variables used for both input and output inoutSomething.
TYPES
Variables can have either a string or numeric type. Assigning a number to a variable
of string type or vice versa will not cause the desired effect, but will not report
an error. To get around this, always included an initialization value of appropriate
type when defining a variable, eg [VarDef, x, “”], or [VarDef, y, 0]. This also
works with list variables: [VarDef, x(3), 3] results in a 3 element list with each
element being a numeric variable set to 3.
Not doing this is another cause of subtle, difficult to find bugs.
CLEARING A LAYER INCLUDING A 3D MODEL
“Layer:Layer Clear” will not clear a model in 3D edit mode. To clear that along with the rest of the layer, do
this:
[If, [IsEnabled, “Transform:Edit”], [IUnpress, “Transform:Edit”]]
[IPress, “Layer:Clear Layer”]
Restoring an object to a marker can sometimes require two clicks. This function restores
an object by clicking on a marker at the specified position. (Note; this function isn’t
thoroughly tested, plus it may alter the currently selected tool. I’ll be writing a better
version in the future.)
[RoutineDef, MarkerRestore,
[Note, [StrMerge, "Restoring Marker at ", x, " ", y]]
[CanvasClick, x, y]
// Under some circumstances, a single click on a marker will set
// the tool in the tool palette back to the tool stored with the
// marker, but will not draw the tool. In this case, a second
// click is needed.
[If, [IsDisabled, “Transform:Edit”], [CanvasClick, x, y]]
[IPress, “Transform:Unmark Object Position”]
, x, y]