sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby : Get dimensions of a transformed element

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 438 Views 3 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.
    • N Offline
      nicoiweins
      last edited by

      Hi there,

      I have a problem with dimensions of a group which has been transformed with the scale tool
      (or the edges of a group)

      before and after the transformation, I get the same dimensions.

      here is my script :

      myEdges= []
      entGroup = myGroup.entities
      entGroup .each do |e|
        if e.is_a? Sketchup;;Edge
          myEdges<< e.length
        end
      end
      puts myEdges
      

      Is there a better way to get my dimensions using Ruby?

      using boundingbox I have the same problem

      bbox = myGroup.local_bounds
      widthBox = bbox.width
      depthBox = bbox.depth
      heightBox = bbox.height
      

      Thanks for your help

      Nicolas

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        You need to take into account the transformation of the group when looking at distances, thus:

        g=Sketchup.active_model.selection[0]; g.entities.grep(Sketchup;;Edge).each{|e| p (e.start.position.transform(puts; g.transformation).vector_to(e.end.position.transform(g.transformation))).length ; p e.length}; puts;
        

        Make a group [say a square that's 10 inches], make a copy, scale one of those groups, select the original sized one, paste this code in the Ruby Console + <enter>.

        Then repeat the selection and code for the scaled one.

        Your output for each is in pairs - the transformed distance between each vertex and the edge length.
        The unscaled one returns matching pairs, but the scaled one gives the transformed distance and the original length...

        🤓

        TIG

        1 Reply Last reply Reply Quote 0
        • N Offline
          nicoiweins
          last edited by

          OK it seems great and for a bounding box?

          1 Reply Last reply Reply Quote 0
          • N Offline
            nicoiweins
            last edited by

            Thank you TIG for your help

            I wrote this function

            def getLength pt1,pt2,myGroup
              myLength =  (pt1.transform(myGroup.transformation).vector_to(pt2.transform(myGroup.transformation))).length
              return myLength 
            end
            
            #    # for the boundingbox of the group myGroup
            #    width = getLongueur bbox.corner(0),bbox.corner(1),myGroup
            #    depth = getLongueur bbox.corner(0),bbox.corner(2),monGroup
            #    height = getLongueur bbox.corner(0),bbox.corner(4),monGroup
            
            #    # for a edge myEdge of the group myGroup
            #    length = getLongueur myEdge.start.position,myEdge.end.position,myGroup
            
            
            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @nicoiweins said:

              OK it seems great and for a bounding box?

              use
              group_instance.bounds()
              which is inherited from Sketchup::Drawingelement, the superclass of Sketchup::Group (and most all model objects that are seen.) Even more model objects are descended from Sketchup::Entity, including Sketchup::Drawingelement. Each Ruby class inherits from it's ancestor classes.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement