I will show how to hide an object based on the selected style.
I created a style tree that looked like:
Base
|
- Triangle
|
- Rectangle
In base I created two object with unique names to avoid confusion:
- Rectangle Object'
- Triangle Object
Then I added the following code point to base
if ( Flow[ @Piece[Base] ] == @Style[Rectangle] )
@Object[Triangle Object].Hide = 1;
else
@Object[Rectangle Object].Hide = 1;
There is a lot going on. Let me break it down.
@Object[Triangle Object].Hide = 1;
and
@Object[Rectangle Object].Hide = 1;
A lot is added in
if ( Flow[ @Piece[Base] ] == @Style[Rectangle] )
To break it down.
@Style[Rectangle]
Every style is converted into a unique number. This code is getting the number for the style Rectangle.
The same is true for pieces. To get the piece's number we use
@Piece[Base]
Understanding that we can look at the .mac file and find the following code.
if ( Flow[ 0 ] == 2 )
This is straight C code testing if an array value is equal to a
constant. The key here is the options chosen when running the macro
populates the Flow array. There is one element for each piece. Flow[0]
corresponds to the first Piece (Base). If we added another piece it would have the value 1.
The value of Flow[0] contains the unique value of a style. There are 3 styles in Base. They are:
While it is possible to hard code the values it quickly becomes confusing. Accessors make the code more readable.
Here is the final project HideObject.mg4 (23.8 KB)