• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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.
  • A Offline
    alexandre sk
    last edited by 11 May 2014, 04:50

    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 11 May 2014, 10:26

      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
      • A Offline
        alexandre sk
        last edited by 11 May 2014, 20:02

        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
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement