fork download
  1. # Starting with entity check if entity or any of it's children is is_a type
  2. # Add them to entity_instances
  3. # Cache component_definitions in a set to not check them twice
  4. def get_all_instances_of(entity, type, entity_instances, component_definitions)
  5. if entity.is_a?(Sketchup::ComponentInstance)
  6. # check component_definitions cache
  7. if component_definitions.include?(entity)
  8. return
  9. end
  10. component_definitions.insert entity
  11.  
  12. # check children
  13. entity.definition.entities.each do |child|
  14. get_all_instances_of(child, type, entity_instances, component_definitions)
  15. end
  16.  
  17. elsif entity.is_a?(Sketchup::Group)
  18. # check children
  19. entity.entities.each do |child|
  20. get_all_instances_of(child, type, entity_instances, component_definitions)
  21. end
  22. end
  23.  
  24. if entity.is_a? type
  25. entity_instances << entity
  26. end
  27. end
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty