2

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

Calipso
  • 957
  • 3
  • 15
  • 33

1 Answers1

2

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
alexandre-rousseau
  • 2,321
  • 26
  • 33
Sven
  • 2,839
  • 7
  • 33
  • 53