Search code examples
rubysketchup

Sketchup Get Entity By component name


To work on an element, I use the following for the definition.

ref = Sketchup.active_model.entities[0]
refdef = ref.definition

is there a way in which I can get the entitiy by its name (component name) instead of entities[0] etc


Solution

  • Sketchup.active_model.definitions returns a DefinitionList. Its [] method can be used to access definitions by index, GUID or name.

    componame="MyLovelyComponent"
    compo = Sketchup.active_model.definitions[componame]
    if compo
        puts "#{componame} found: doing something else..."
        ### do something with 'compo' definition
    else
       puts "#{componame} does NOT exist!"
       return
    end