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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Find the position of a group in the active context

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 2 Posters 237 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.
    • D Offline
      dacastror
      last edited by

      Hi, I'm trying to find the position of a group in the active context, relative to the coordinate system of the group that it contains (which itself can be contained within other groups), this picture illustrates the situation

      https://sites.google.com/site/dacastror/archivos/coordenadas.jpg

      You may also need to do this but with components. Really, I do not find the way to accomplish what I need, I appreciate your help
      (google translator)

      .

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        A recent discussion might help

        http://sketchucation.com/forums/viewtopic.php?f=180&t=49592

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          dacastror
          last edited by

          thanks for replying, I saw this link, unfortunately I still do not understand how to solve my problem

          😐

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            The transformation of a sub-group will be relative to its parent so the sub-groups.transformation.origin will be the dx,dy,dz relative to the container group.

            For example your model contains a group which contains another group then the following code would find the most embedded group and output its transformation.origin to the Ruby Console.

            mod = Sketchup.active_model
            ent = mod.active_entities
            sel = mod.selection
            grps=[];tran=[]
            grps<<ent.grep(Sketchup;;Group)[0]
            tran<<grps[0].transformation
            begin
             fnd=false
             grps[-1].entities.each{|e|
              if e.class==Sketchup;;Group
               grps<<e;tran<<e.transformation
               fnd=true;break
              end
             }
            end while fnd
            puts grps[-1].transformation.origin
            
            

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • D Offline
              dacastror
              last edited by

              Sdmitch thank you very much, unfortunately the problem persists when I'm in the active context, I'm trying something with this

              mod = Sketchup.active_model 
              path = mod.active_path
              tr1 = Geom;;Transformation.new([0,0,0],[1,0,0],[0,1,0])
              if path
                path.each{|entity|
                   tr2 = entity.local_transformation
                   tr1 = tr1*tr2
                }
              end
              tr1.origin
              

              It works, but to play around with this in the least expected moment this fails. If it always worked, I would do something like this then

              mod = Sketchup.active_model 
              sel = mod.selection
              path = mod.active_path
              tr1 = Geom;;Transformation.new([0,0,0],[1,0,0],[0,1,0])
              if path
                path.each{|entity|
                   tr2 = entity.local_transformation
                   tr1 = tr1*tr2
                }
              end
              origin_parent = Geom;;Vector3d.new(tr1.origin.to_a)
              
              ejex_o = sel[0].transformation.xaxis
              ejey_o = sel[0].transformation.yaxis
              center = sel[0].local_bounds.center
              tr3 = Geom;;Transformation.new([0,0,0], ejex_o, ejey_o)
              center_tr = Geom;;Vector3d.new((center.transform tr3).to_a)
              origin_group = Geom;;Vector3d.new(sel[0].transformation.origin.to_a)
              point = origin_group - origin_parent + center_tr 
              point_tr = point.transform tr1.inverse
              

              here I have gained the center of the group with respect to the coordinate system of the parent in the active context. The problem is that it only works well sometimes,
              I do not understand how to fix this
              (google translator)

              1 Reply Last reply Reply Quote 0
              • D Offline
                dacastror
                last edited by

                I solved the problem, the key was to use "mod.edit_transform.origin"
                I leave the code in case anyone needs it one day

                mod = Sketchup.active_model sel = mod.selection parert_origin = mod.edit_transform.origin entity_origin = sel[0].transformation.origin distance = entity_origin-parert_origin tr = mod.edit_transform.inverse distance.transform tr

                😄

                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