sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    FredoBend | Powerful new bending tool for SketchUp Download

    Wrong distance and position of exploded dynamic component

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 4.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kimdv
      last edited by

      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:

      
      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
            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|
              return definition if definition.image? && definition.instances.include?(instance)
          }
          end
          return nil # Error. We should never exit here.
      end
      
      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)
      end
      puts f0_v[3].position.distance(f0_v[0].position)
      
      
      

      The result is not as I am expected:

      
      #<Sketchup;;Group;0x0000024da5ea60b0>
      #<Sketchup;;Face;0x0000024da5ea5f20>
      #<Sketchup;;Face;0x0000024da5ea5e30>
      #<Sketchup;;Face;0x0000024da5ea5d18>
      #<Sketchup;;Face;0x0000024da5ea5cc8>
      #<Sketchup;;Face;0x0000024da5ea5c78>
      #<Sketchup;;Face;0x0000024da5ea5c50>
      (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.


      test.skp

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        The result looks good.

        What were you expecting to be different ?

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better đź’—

        Register Login
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement