Just noticed that my script is not working correctly with tag folders
Yes there are other issues as well.
Why do you think you cannot have nested tag folders ? There is nothing in the help that says you cannot. And the Ruby API supports nested tag folders.
Just be aware that tag folders are not themselves tag/layer collections. They are a display feature.
(Meaning that all tag/layers remain children of the toplevel model layers collection.)
Changing thisâŚ
if ( layers_toggle.any? {|l| l.visible? == false } )
layers_toggle.each {|l| l.visible = true }
else
layers_toggle.each {|l| l.visible = false }
end
to this worksâŚ
if ( layers_toggle.any? {|l| l.visible? == false } )
layers_toggle.each {|l| l.visible = true }
layers.folders.each {|l| l.visible = true }
else
layers_toggle.each {|l| l.visible = false }
layers.folders.each {|l| l.visible = false }
end
But the notes for the folders method says:
Note: This does not return all the folders in the model, only those that are direct children of the layer manager.
So it wonât work on folders that are children of folders⌠oh well
You may have missed what I said above. Tags(layers) remain children of the top level model layers collection. They are only displayed beneath the folder that their folder property points at.
Notes on your code:
(1) You must not define methods in the top level ObjectSpace. Doing so makes them global and part of class Object. Since everything in Ruby is an object and is a subclass of class Object, your object definitions will percolate into every other coderâs modules and classes as well as the APIâs modules and classes ⌠and Rubyâs modules and classes.
So your code must be within a unique namespace module, and then separated into categorical submodules (usually one for each extension.)
(2) The word âtoggleâ means to change state of a boolean or dual state object. Adding âOnOffâ is like a double descriptor. (Also the Ruby convention is for method names to be all lowercase with words separated with underscores. Mixed case method names often come from JavaScript, VisualBasic and C programmers.)
(3) Only use parenthesis around conditional expressions when it is necessary to control the order of evaluation. (if and unless statements in Ruby do not need parenthesis around the conditions like is required in JavaScript or other coding languages.)
(4) A toggle command is not a tool and does not belong on the âToolsâ menu.
Either in your own submenu of âExtensionsâ or perhaps the âViewâ menu.
An example for you âŚ
PaulMcAlenan_TagControl.rb (1.2 KB)
Each LayerFolder object has itself a #folders method that returns an array of itâs child folders, and a #folder property that points at itâs parent folder (or nil if it has no parent folder and is a toplevel folder.)
So itâs a tree structure and needs to be walked (which is usually done with a recursive method.)
Dan, how right you are. You can have multi-level nesting. So I take back what I wrote in post 9. Having a single top level folder for all tags apart from Untagged would do the trick very simply. I guess this would be better than struggling with code that doesnât quite cover it all.
Oh, but then youâll need a code command to set all your layers to be a child of a folder you pick ?