sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Component definition name

    scheduled pinned locked moved Developers' Forum
    3 Posts 2 Posters 282 Views 2 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • 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)
      
      
      one-reply-to-this-post last-reply-time reply quote 0
      • TIGT Offline
        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

        one-reply-to-this-post last-reply-time reply quote 0
        • C Offline
          Casey
          last edited by

          Works great, thanks.

          one-reply-to-this-post last-reply-time 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