Get component definition name
-
Hi, I try, a lot, but failed.
I am able to get the INSTANCE name and do stuff with it but I have trouble to get the DEFINITION name
Here what i make to get the instance name and printed:
selection = Sketchup.active_model.selection selection.each { |entity| value = entity.name } UI.messagebox("Name; " + value.to_s)
I also got the definition code but don't know what to do with it.
Thx
-
HI ALexandre,
Simply, like this:
selection.each { |entity| value = entity.definition.name }
or more precisely, you likely want to do something like this:
selection.each { |entity| if entity.class == Sketchup;;Group value = entity.name end if entity.class == Sketchup;;ComponentInstance value = entity.definition.name end }
ComponentInstance#definition returns the ComponentDefinition of the instance.
ComponentDefinition#name returns the name.
Then to assign a new name, you would use #name=
if entity.class == Sketchup;;Group entity.name = value end if entity.class == Sketchup;;ComponentInstance entity.definition.name = value end
-
ohhhhhh this one is for me:
Thank you very much. I was expecting something very simple but not that simple.
Starting to like ruby. I only know php and javascript, but this ruby is good.
Thank you Jim
Advertisement