ZBrushCentral

Newbie tips

Below are some of the tips I think would be very helpful to any newbie (based on my own recent experience :slight_smile: ). 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]

I have to say that I’ve never used quotes around interface item paths; I’ve never had any problems.

Lack of quotes definitely caused me problems in at least one instance. If I ever have time I will try to track it down, but don’t hold your breath :slight_smile:

Cool stuff, hope you continue to add to this thread :+1:

I just wanted to add that while your layer testing code is sound it is done the hard way. You do not need to bit interpret the [IgetFlag,…] value. The flag values were assigned with a purpose in mind.

The flag values for layers can be the following:

:white_small_square: 0: Not Created
:white_small_square: 8: Disabled
:white_small_square: 9: Enabled
:white_small_square: 10: Disabled and the active layer
:white_small_square: 11: Enabled and the active layer

,so according to the above you only need to check against an [IGetFlags,…] > 0 to see if a layer is created.

To check for the currently active layer simply check against an [IGetFlags,…] value of 10 or 11.

The light buttons in the Light palette return similar values. See the [IGetFlags,…] description in the Zbrush Zscripting Reference at the www.ZBrush.com website.