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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement