View Full Version : print layer name as its hidden / unhidden
05-14-2008, 09:03 PM
is this possible... ?
05-14-2008, 09:54 PM
I don't think there is an existing callback to do this. But you could theoretically set up a viewport callback or timer and check the .isHidden property of each layer to see if it's changed and then print the name of it if it has.
05-14-2008, 10:02 PM
if you have AVG extension (nothing to do with the anti-virus product) installed, or are running 2008+, then you can set up a change Handler on each layer as well.
With the 2008+ code:
myLayer = (layermanager.getLayer 1).layerAsRefTarg
when parameters myLayer change id:#test do (
print "layer parameter changes"
You'll still have to track, one way or another, what the original Hidden value was so you can check if that's the parameter that got changed (would be nice if changeHandlers told you, but alas). As the .layerAsRefTarg returns it as a MaxWrapper, a custom attribute block or set/getAppData should work.
You can use the #layerCreated callback to keep track of any new layers being added. Layers being deleted should automatically remove the changeHandler once the layer is actually out of memory, so probably needn't worry about #layerDeleted.
05-14-2008, 10:26 PM
fn create_layer_ch myLayer = (
when parameters myLayer change id:#layer_stuff theLayer do (
if ((theLayer.isHidden as string) != (getAppData theLayer 3217)) then (
setAppData theLayer 3217 (theLayer.isHidden as string)
format "Layer '%' has been %\n" theLayer.name ( if (theLayer.isHidden) then ("hidden") else ("unhidden") )
for i = 1 to layerManager.count do (
myLayer = (layermanager.getLayer (i - 1)).layerAsRefTarg
callbacks.addScript #layerCreated "create_layer_ch (callbacks.notificationParam())" id:#layer_stuff
05-14-2008, 11:22 PM
thanks richard... works just perfect... i never imagined it was possible...
how can i find such info in the help... like examples of getAppData and the id: 3217 you used in the script... ??
05-15-2008, 12:40 AM
open the help file, go to the search tab, enter "setAppData" ;)
Seriously, though - finding that type of information if you don't already know about it can be difficult at best and take several searches in the help file.. and even then you might not find it, and Autodesk Sup...community webboards such as these can be a great help :)
I do recommend, however, that if you have a spare hour or two sometime, to just go through every topic in the MaxScript help file (Except maybe those that you know you can safely skip... such as, say, the NURBS topics). Even if you don't retain all of the information in one go, you might encounter things where you'll go "that might be handy" and bookmark it or write it down somewhere - or, later on when you're coding something and go "I need to store some information with this object.. how might I do that" and then remember some of the things you had read before.
Oh, as for that number '3217' - that's just a random number I used. AppData, at least with maxscript, allows you to read/write a string from a given AppData channel. That channel is any number between 0 and 65536 if I recall correctly. I wouldn't typically recommend it, as you never know if somebody else is using '3217' for -their- AppData. But the alternatives are pretty heavy for such a relatively simple use, that I think AppData is fine in this instance.
05-15-2008, 12:40 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.