[REQ] Name Layer from a group existing
-
Many thanks!
-
asuming that the file is renamed toto.rb, and working with for groups
I add this at the end for have the right click Context
if( not file_loaded?("toto.rb") ) UI.add_context_menu_handler do |menu| menu.add_separator if ss[0].class != Sketchup;;Group menu.add_item("add Layer name") if ss[0].class != Sketchup;;Group end end file_loaded "toto.rb"
All is always working fine in the Ruby console
but I have nothing as Menu Contextual on the Right Click when a group is selectedPs This Text editor is a little smaller for see a correct Code size's line
-
@unknownuser said:
asuming that the file is renamed toto.rb, and working with for groups
I add this at the end for have the right click Context
> if( not file_loaded?("toto.rb") ) > UI.add_context_menu_handler do |menu| > menu.add_separator if ss[0].class != Sketchup;;Group > menu.add_item("add Layer name") if ss[0].class != Sketchup;;Group > end > end > file_loaded "toto.rb"
All is always working fine in the Ruby console
but I have nothing as Menu Contextual on the Right Click when a group is selectedYou also need to give the menu item an action {}
Ps This Text editor is a little smaller for see a correct Code size's line
should be
...class == Sketchup::Group
Should NOT be
...class != Sketchup::Group
The ! negates it - i.e. "if class is NOT == Group", when you actually want "if class == Group" !
-
After hundred of try
(ruby console works always fine I have no syntax error message)
but always nothing in the right click panel menu
I don't see very well what "action" I must put inside the {} (I had tested some many
Surely trivial butif(not file_loaded?("toto.rb")) UI.add_context_menu_handler do |menu| menu.add_separator if ss[0].class == Sketchup;;Group menu.add_item("Add Name Layer"){layers.add(name)}if ss[0].class == Sketchup;;Group end end file_loaded "toto.rb"
-
Another thing that will be cool :
put in the same time the object (goup/component) in the the layer created -
If you go back to my earlier example
def
layer_name_from_group_name()
...
is the action to put in the {}
So at the end of the file that loadslayer_name_from_group_name
add your context-menu test and run the action... -
hum hum
Seems there is something again missing
(Console is Ok)right Click context menu always unseen
def layer_name_from_group_name() model=Sketchup.active_model ss=model.selection if ss[0].class != Sketchup;;Group UI.messagebox("Select a Group to Name a Layer after...") return nil end#if name=nil name=ss[0].name if not name or name=="" UI.messagebox("Select a NAMED Group to Name a Layer after...") return nil end#if layer_names=[];layers=model.layers layers.each{|layer|layer_names<<layer.name} if layer_names.include?(name) UI.messagebox("A Layer with that Group's Name ["+name+"] already exists...") return nil end#if new_layer=layers.add(name) UI.messagebox("Layer '"+name+"' created.") end#def if(not file_loaded?("layer_name_from_group_name.rb")) UI.add_context_menu_handler do |menu| menu.add_separator if ss[0].class ==Sketchup;;Group menu.add_item("Add Name Layer"){layer_name_from_group_name()}if ss[0].class==Sketchup;;Group end end file_loaded ("layer_name_from_group_name.rb")
-
if(not file_loaded?("layer_name_from_group_name.rb"))
ss=Sketchup.active_model.selection
UI.add_context_menu_handler do |menu|
menu.add_separator if ss[0].class ==Sketchup::Group
menu.add_item("Add Name Layer"){layer_name_from_group_name()}if ss[0].class==Sketchup::Group
end
endThe red text is needed to define
ss
as it was only defined inside thedef
... -
Yep now that works fine! Many thx!
To do
Now second part : move in the same time the object clicked on the layer namedFor the moment that works for a group or a component
Just select a group named or a component with Definition name
Right Click and a context menu appears : Add Name Layer from Group
or Add Name Layer from Component
(object is not moved on this version)If your Right Click is broken you must enter on the ruby Console
layer_name_from_group_name or layer_name_from_component_name
-
Is possible to do the inverse of this situation, like this:
Base Group (or components) Name from layer name? If yes, would be fantatisc to my workflow.
-
Pilou - nascent scripter - yours I think...
Iterate through model.definitions,
if defn.group?
then add if to a groups array and then iterate through groups and rename each group to match its group.layer.name, keep a list of all group names as you go [start by making a list of the groups' names and then remove old name and add new name as you go groups]. It a group name exists then increment it [tip:name="name#1";name=name.next if groupnames.include?(name)
] - several groups could be on one layer and should them get named name#1,name#2,name#3 etc...
Advertisement