Wrong distance and position of exploded dynamic component

Wrong distance and position of exploded dynamic component

Postby kimdv » Fri Sep 25, 2020 5:26 am

I am new to Sketchup extension development. Attached file is part of a dynamic component after getting it exploded. Then I applied the following code:
Code: Select all
def self.definition(instance)
    if instance.is_a?(Sketchup::ComponentInstance)
    # ComponentInstance
    return instance.definition
    elsif instance.is_a?(Sketchup::Group)   
      if instance.entities.parent.instances.include?(instance)
          return instance.entities.parent
          Sketchup.active_model.definitions.each { |definition|
          return definition if definition.instances.include?(instance)
    elsif instance.is_a?(Sketchup::Image)
    Sketchup.active_model.definitions.each { |definition|
        return definition if definition.image? && definition.instances.include?(instance)
    return nil # Error. We should never exit here.

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
puts ent[0]
faces =  definition(ent[0]).entities.grep(Sketchup::Face)
puts faces
faces[0].material = "Purple"
faces[0].vertices.each {|v| puts v.position}
puts '---'
f0_v = faces[0].vertices
for i in 0..f0_v.size - 2
  puts f0_v[i].position.distance(f0_v[i+1].position)
puts f0_v[3].position.distance(f0_v[0].position)

The result is not as I am expected:
Code: Select all
(0 mm, 0 mm, 300 mm)
(0 mm, 0 mm, 0 mm)
(300 mm, 0 mm, 0 mm)
(300 mm, 0 mm, 300 mm)
300 mm
300 mm
300 mm
300 mm

Any one can help me?
I am sorry for my bad English.


Re: Wrong distance and position of exploded dynamic componen

Postby Dan Rathbun » Sat Oct 17, 2020 2:12 pm

The result looks good.

What were you expecting to be different ?
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago

    Ad Machine 


    Return to Developers' Forum


    Who is online

    Users browsing this forum: No registered users and 11 guests

    Visit our sponsors: