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

    Get group location over Ruby Script

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 5 Posters 3.0k Views 5 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.
    • O Offline
      Ossi01
      last edited by

      Hello everybody,

      can somebody explain me, how i get the location of a group(In Sketchup.active_model) over a ruby script ? Currently, i get only the local position of the entities in the group(groups have a own axis of abscissas), but i need the global position. I hope, you-all understand my problem

      Cu
      Ossi01

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Is the group in the active context? ( model.active_entities ? )
        How are you obtaining the group?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • O Offline
          Ossi01
          last edited by

          @ thomthom : Yes, the group is in model.active_entites and i obtaining the group. This isn't my Problem. But i get over Sketchup.active_model.active_entities[0].entities[1].end.position or Sketchup.active_model.active_entities[0].entities[1].start.position the local position of a edge(Start- and End-Vertex) in the group , not the global position in the whole model ! But i need the global position

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

            Try tr=group.transformation to get the group's current position and then when you get the contents points transform! them by 'tr' - e.g. pt.transform!(tr)
            If the group is not within the model.entities (as in group.parent != model) you need to recursively apply the parent's parent's transformations until it is etc... using a while parent != model ... end loop ?

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @ossi01 said:

              @ thomthom : Yes, the group is in model.active_entites and i obtaining the group. This isn't my Problem. But i get over Sketchup.active_model.active_entities[0].entities[1].end.position or Sketchup.active_model.active_entities[0].entities[1].start.position the local position of a edge(Start- and End-Vertex) in the group , not the global position in the whole model ! But i need the global position

              Ok - assume you have an edge in group in the current context - the group is selected

              
              model = Sketchup.active_model
              sel = model.selection
              
              group = sel[0]
              edge = group.entities[0] # Assuming there is only one edge in the group
              
              global_start = edge.start.position.transform( group.transformation )
              
              

              Not that when you open a group or component for editing, the co-ordinates you get in active_entities are the global ones.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @tig said:

                If the group is not within the model.entities (as in group.parent != model) you need to recursively apply the parent's parent's transformations until it is etc... using a while parent != model ... end loop ?

                As long as the group is within model.active_entities one only need to apply the group's transformation.
                And you can't go backwards by parent as you traverse definitions instead if instances.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • O Offline
                  Ossi01
                  last edited by

                  big thanks @ TIG and thomthom. It works 😉!!

                  1 Reply Last reply Reply Quote 0
                  • honoluludesktopH Offline
                    honoluludesktop
                    last edited by

                    Isn't this ("the location of a group") what Ossi01's asking? The example uses selection to Id a group, then gets its transformation, then its origin based on its location from the model's origin.

                    model = Sketchup.active_model
                    my_selection = model.selection
                    	
                    my_selection.each do |ent|
                      if ent.is_a? Sketchup;;Group
                         t=ent.transformation
                         puts t.origin.to_a
                      end
                    end
                    

                    Temp00.jpg

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

                      When you get the position of a point [ pt] in a group.entities [or definition's] it is relative to where it was 'made' i.e. for a model it's bounds.min is typically taken as the model.origin. So the point is returned relative to the group's coordinate system not the model's. You can apply the tr=group.transformation to that point pt.transform!(tr) and it is now given in the model's coordinate system... If groups are nested then the transformation of each parent back to the model level has to be taken into consideration...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        HerveRenault
                        last edited by

                        @tig said:

                        tr=group.transformation to that point pt.transform!(tr)

                        Thank you very much for the tip !

                        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