Module: TT::Instance
- Defined in:
- TT_Lib2/instance.rb
Overview
Collection of Group, ComponentInstnace and Image methods.
Class Method Summary collapse
-
.definition(instance) ⇒ Sketchup::ComponentDefinition, Mixed
Returns the definition for a
Group
,ComponentInstance
orImage
. -
.is?(entity) ⇒ Boolean
Query to whether it's a Group or ComponentInstance.
Class Method Details
.definition(instance) ⇒ Sketchup::ComponentDefinition, Mixed
Returns the definition for a Group
,
ComponentInstance
or Image
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'TT_Lib2/instance.rb', line 21 def self.definition(instance) if instance.respond_to?(:definition) begin return instance.definition rescue # Previously this was the first check, but too many extensions modify # Sketchup::Group.definition with a method which is bugged so to avoid # all the complaints about extensions not working due to this the call # is trapped is a rescue block and any errors will make it fall back to # using the old way of finding the group definition. end end if instance.is_a?(Sketchup::Group) # (i) group.entities.parent should return the definition of a group. # But because of a SketchUp bug we must verify that group.entities.parent # returns the correct definition. If the returned definition doesn't # include our group instance then we must search through all the # definitions to locate it. if instance.entities.parent.instances.include?(instance) return instance.entities.parent else Sketchup.active_model.definitions.each { |definition| return definition if definition.instances.include?(instance) } end elsif instance.is_a?(Sketchup::Image) Sketchup.active_model.definitions.each { |definition| if definition.image? && definition.instances.include?(instance) return definition end } end return nil # Given entity was not an instance of an definition. end |
.is?(entity) ⇒ Boolean
Query to whether it's a Group or ComponentInstance
63 64 65 |
# File 'TT_Lib2/instance.rb', line 63 def self.is?(entity) entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance) end |