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

    Component definition name

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 275 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.
    • C Offline
      Casey
      last edited by

      Hi,

      How to get the definition name from a selected component?
      I tried the code below, assuming only one component selected which is correct. But this returns just the name not the definition name which is set when the component is created.

      
      model = Sketchup.active_model; 
      selection = model.selection
      
      componentdef = selection[0]
      UI.messagebox(componentdef.name)
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        You are making a reference to an Instance not a Definition.
        An Instance can have a name separate from its Component's name...
        Do it this way

        model = Sketchup.active_model;
        selection = model.selection
        component_instance = selection[0]
        component_definition = component_instance.definition
        ci_name = component_instance.name
        cd_name = component_definition.name
        ### to be clever count the instances too ;)
        num = component_definition.instances.length.to_s
        UI.messagebox("Component Definition Name = "+cdname+"\nComponent Instance Name = "+ciname+"\nThere are "+num+" Instances.")
        

        TIG

        1 Reply Last reply Reply Quote 0
        • C Offline
          Casey
          last edited by

          Works great, thanks.

          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