ZBrushCentral

3D Layers Scripting Commands Help

Hi everyone,
I am fairly new to zscripts and have a few questions about 3d layers…
I am trying to select layers via script by having a “next” and a “previous” button.
What i am trying to understand is:

1 - How do i tell the script what is the currently selected layer number? e.g. if the currently seleccted layer is “3D Layer 4”, i need the result to be 4 so that i can assign it to a variable and add/subtract it later on

2 - How do I jump to the next/previous layer?
For example, if I know that I am on layer 1, can i do something like:
IPress,Tool:Layers:3D Layer (n + 1)

Thanks in advance… hope i made some sense

Dario

One helpful learning method for scripting is to turn on ZScript record, then manually click through the sequence of steps (button presses) that do what you want, then end recording and examine the generated script.

try:

[IPress, TOOL:SubTool:SelectUp ]
and
[IPress, TOOL:SubTool:SelectDown ]

Each button becomes disabled when you reach the top or bottom, so it is a good idea to test before pressing:

[If, [IsEnabled, TOOL:SubTool:SelectUp ],
[IPress, TOOL:SubTool:Selectup ]
]

You can derive the number of the original subtool by putting this in a loop and increment a counter until the test fails…

Tip: the actual FULL name for a button used in the script can be different from the button’s visible name, so you should hold the cursor over the button and press Ctrl - the FULL name to be used in your script will be displayed at the bottom of the info popup.

Sven

p.s. sorry if this is all stuff you already know, but I’m never sure where on the learning curve a new scripter might be.

Thanks for the response Svengali.
Unfortunately I had no luck with this command:
[IPress, TOOL:Layers:Selectup ]

I have even tried the subtool version and nothing happens either… there must be something i am missing.(i do have more than one layer and subtool)

Also, should this:
[VarSet, myLayer,[IGetSecondary, Tool:Layers:Layers Scrollbar]]

set the variable myLayer to be the currently selected layer number? (it always gives me 0 as a result)

Thanks

EDIT: Sorry, my mistake, the subtool up and down do work… just the layer doesn’t :frowning:

Dario

DZ,

sorry my friend, I didn’t read your first post very carefully and gave you some irrelevant info on subtool selection rather than layer selection. Frankly, I’ve not worked with 3d Layers yet so I don’t really have any useful advice for you. If Marcus_civis happens by he could probably give you a useful pointer or two.

Sven

Dario,

The wonderful thing about zscripting is that nothing is ever easy. :wink:

As you’ve found, 3D Layers offer a few challenges. First the layer ID number is always only 0 - 7 (the layers that are visible in the menu). That’s straightforward if there are 8 layers or less but the numbering never changes, however many layers there are. For more than 8 layers, the scroll bar position has to be used to determine which layer is which. So it is also necessary to find out the number of layers so that we can keep track of all this.

The number of layers can be inferred by putting the scroll bar at the top position by setting its secondary value to a maximum (I don’t know what this is but I’ve used 256) and then getting its secondary value. If the returned value is 0 then there are 8 layers or less and we can loop through them to see how many there are using [IsEnabled]. If the scroll bar value is more than 0 then the number of layers is simply that value + 8.

Having found out the number of layers we can test for the selected layer by using the [IGetFlags] command. This will return a value >8 if the layer is selected. (The flag values can be determined for any interface item by testing.) For 8 layers or less we can loop through easily enough using [StrMerge] to set the layer path:


[If,[IGetFlags,[StrMerge,"Tool:Layers:3D Layer ",[Val,n]]] > 8,
//this is the selected layer

For more than 8 layers we need to set the scroll bar also. You’ll see the method I use in the attached sample code.

HTH,

Thanks Marcus! That’s much more compicated than i thought it would be :slight_smile:

I’ll be studying the scripts you posted… looks like there is quite a bit i have to learn there to be able to work with 3d layers.

Cheers

Dario

Hey Marcus,
I have started playing with the script samples you posted (thanks again for that :slight_smile: )and there is something that is not making much sense to me. I started with something simple:

[IConfig,3.1]
[VarDef,tmpScrPos,0]

[RoutineDef,GetLayers,
[ISet,Tool:Layers:Layers Scrollbar,0,256]
]//end of routine

[Ibutton, “Zplugin:Misc Utilities :TEST”, “Test Script”,
[VarSet,tmpScrPos,[IGetSecondary,Tool:Layers:Layers Scrollbar]]
[RoutineCall,GetLayers]

] // End of Ibutton

That works fine, but can you explain why doesn’t this work? :

[IConfig,3.1]
[VarDef,tmpScrPos,0]

[RoutineDef,GetLayers,
[VarSet,tmpScrPos,[IGetSecondary,Tool:Layers:Layers Scrollbar]]
[ISet,Tool:Layers:Layers Scrollbar,0,256]
]//end of routine

[Ibutton, “Zplugin:Misc Utilities :TEST”, “Test Script”,
[RoutineCall,GetLayers]
] // End of Ibutton

All i am trying to do is to move the 3d layers scrollbar. I don’t get why it doesn’t do anything if I set the variable in the same routine as the scrollbar positioning… I mean, you have done the same in your script, which i assume it works just fine, right? Am I missing something?

Cheers

Dario

Ok, it works now.

If I close, restart ZB, load the script, it works fine
If I keep modifying the script and just press reload, then the script does not work.
I find this really wierd, I have been modifying and updating scripts in the past and it always worked:confused:

It’s because it’s a plugin zscript. If you specify a plugin button in the script it won’t reload after changes (at least, it will load as far as the changes).
It’s simplest to test plugins as ordinary zscripts until you’ve got the functionality working but for final testing TVeyes just posted a useful working method here:http://www.zbrushcentral.com/zbc/showthread.php?p=411829#post411829

I see… Thanks for the tip :slight_smile:

Dario