sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Get component definition name

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 347 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • alexandre skA Offline
      alexandre sk
      last edited by

      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

      http://www.arquitetosonline.com/outros/component_name.png

      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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • alexandre skA Offline
          alexandre sk
          last edited by

          ohhhhhh this one is for me:

          http://www.loud-mouse.com/wp-content/uploads/2012/09/dumbass.jpg

          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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement