Name of component
-
Hi i am struggling with what i am sure is something really easy but after hours of search i can't work out how to get the name of the active component as a string. I can set the name in Component attributes.
This is what I've tried
model = Sketchup.active_model
selection = model.selection.name
but its no where nearCheers in advance
Fred
-
model = Sketchup.active_model name = model.selection[0].nameBUT of course that assumes that the first object in the model's selection has a 'name'. A ComponentInstance or a Group might have a name [BUT it might also be ""], AND many other things like a Face or Edge never will have a name, so you'll then get an error...
If [as I suspect] you want the name of the component-definition of the first item [component-instance] in the current selection... AND you know it is definitely a ComponentInstance then you can usename = model.selection[0].definition.namewhich will return the unique string that is that component-definition's name.
To stop errors you really ought to test for the selection's suitability, 'type' thus...model = Sketchup.active_model sel=model.selection name=nil if sel and sel[0] and sel[0].is_a?(Sketchup.ComponentInstance) name=sel[0].definition.name endThis way name is either 'nil' or a string, so the next step in your code could be
if name ### do something with 'name' else UI.messagebox("Please select a Component Instance to find its Name !") return nil end -
Nice one that has worked well cheers for the help

fred
-
Note that there is component instance name and component name. Component instance name is the same as a group's name.
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