Select all geometry
-
Which error do you get?
-
This is my ruby script »Aar_Select_comp_by_name.rb« in the Plugins folder:
@unknownuser said:
def select_comp_by_name(comp_name)
model = Sketchup.active_model
sel = model.selection
sel.clear
compdef = model.definitions[comp_name]
if compdef #There is a component
sel.clear
sel.add compdef.instances
else
UI.beep
end
end
#def select_comp_by_name(comp_name)
#@sel = Sketchup.active_model.selection
#@sel.clear
#@sel.add Sketchup.active_model.definitions[comp_name].instances
#@sel
#endIf I repeat loading by ruby console:
load "Aar_Select_comp_by_name.rb"
then come the following notes
@unknownuser said:/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:6: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:7: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:7: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:8: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:8: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:8: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:10: warning: parenthesize argument(s) for future version
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:10: warning: parenthesize argument(s) for future version
true
… but also »true«.Now with ruby script line
Sketchup.active_model.definitions["Stein"]
I get
@unknownuser said:nil
and with
> select_comp_by_name("Stein")
@unknownuser said:
Error: #<NoMethodError: undefined method ` ' for main:Object>
/Library/Application Support/Google SketchUp 6/SketchUp/Plugins/Aar_Select_comp_by_name.rb:2
(eval):197… nothing is selected.
-
Hi !
Your script works fine here... Be careful with case of the definition name... I found no error in your script...
Perhaps some parenthesissel.add(compdef.instances)
and unnecessary duplication
sel.clear
Erase the second duplication.
-
@Matt666
Thanks for your corrections.
When your script runs fine, in the end you have the component "Stein" selected? -
@unknownuser said:
When your script runs fine, in the end you have the component "Stein" selected?
I tried with a component called "essai" created before. I had five components, and they had been all selected in the end.
Can you upload an example I can test, please ?
-
Matt, here is my model to select a component by name "Stein"
-
Ok I understand your problem...
I have made a component called "test". Entity info window looks like this :
With your component, entity info window looks like this :
The script search for component with definition as ["Stein"]. But your component definition is called "<gruppe#4> in the Skecthup database. His NAME is "Stein".3 methods :
- Create a component directly, without create a group first. Your first ruby script will work.
- Change your ruby script, and don't change your method.
Try this in the ruby API :
Sketchup.active_model.definitions.each{|d|return d if d.name == "Stein"}
This code returns the name of the component definition which called "stein"
And the ruby script :def select_comp_by_name(comp_name) model = Sketchup.active_model sel = model.selection sel.clear compdef = Sketchup.active_model.definitions.each{|d|return d if d.name == "Stein"} if compdef #There is a component sel.clear sel.add(compdef.instances) else UI.beep end end
- Add a line in ruby which control name of all component definitions if C definitions not found...
Like this :
def select_comp_by_name(comp_name) model = Sketchup.active_model sel = model.selection sel.clear compdef = Sketchup.active_model.definitions[comp_name] Sketchup.active_model.definitions.each{|d|return d if d.name == "Stein"} if not compdef if compdef sel.clear sel.add(compdef.instances) else UI.beep end end
Not tested, but it sould work !
Tell me if you want more explanations
-
@Matt666
I did understand you. First changes did not delete my error. Hm? What could it be? -
Oops !! A little bug !!
In fact, name is linked to the component, not to the component definition.
So you have to search around all the component in the drawing to select component with specific name, if no component definition have this specific name....Like this :
def select_comp_by_name(comp_name) model = Sketchup.active_model sel = model.selection sel.clear if compdef = Sketchup.active_model.definitions[comp_name] sel.add(compdef.instances) else Sketchup.active_model.active_entities.each do |d| if d.typename == "ComponentInstance" sel.add d if d.name==comp_name end end if sel.count == 0 UI.beep else UI.messagebox(sel.count.to_s + " entities found.") end end end
-
Qui!
Now your script runs, Matt666. My component is selected by name/definition. As it is selected, I can »Get Position - X« (Proper_animation.rb from RichW).Matt666, you have my elevator model with arrow buttons. With Links.rb the arrow up buttons will select the elevator and »Get Position - 2«. The arrow down buttons will select the component elevator and then »Get Position - 1«.
But my question is, whether I can start a ruby.rb script by clicking a button.
Advertisement