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

    Retrievin object's absolute height ??

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 5 Posters 694 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi and thanx,
      so if understand right,
      this would sort the array of given points and find out the one with the highest z, right? (nice code, btw).

      so if if i had

      pt1=[0,0,5]
      pt2=[0,0,6]

      it would return zmax = 6 , right?

      my problem is, that when i retrieve points WITHIN a group, i get relative coordinates, not absolute. and since the group has no transformation, i again don't get ABSOLUTE coordinates ( with ABSOLUTE i hope to get the Z-zero of sketchup space, independent of, if the user changes the coordinate-origin (axes).

      maybe there is a way to get ABSOLUTE COORDINATES of any point outside or inside of grous/components?

      regards
      stan

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

        Points within a group are returned relative the the group's origin.
        So let's say you have a point 'pt' at [0,0,1] in the group you don't know where it is in the group's context unless you know where the group is within that let's say it is actually at [11,11,11].
        The group has a transformation: you can apply that to 'pt' and the values will change so:
        pt.transform!(group.transformation) becomes [11,11,12]
        and pt.z is now 12 rather than 1

        Of course your example should also work...
        zz=group.transformation.origin.z
        gives the height of the group so pt.z+zz also gives that height ?

        Of course if objects are nested you need to apply multiple transformations.

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi tig,
          i understood and made some tests.
          but if i have a group named

          @main_element (i persume it has a transformation, even it is not moved or anything else)
          and say

          tra = @main_element.transformation

          i get errors , since my syntax is wrong.

          could you give me the syntax for retrieving the transformation from a group?

          i tried a lot of ways, but always get errors.

          thank you!
          stan

          edit:
          when i define tra as

          tra = @main_element.transformation.to_a
          

          i get

          tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]

          how can i interpret the numbers?

          edit 2:
          when i move a group in Z+, tra becomes

          tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1968.503937007874, 1.0]

          so 14th position seems to give the height.

          the problem is, that if i create a plane in a certain height (Z+), the transformation counts this as 0,0,0 .
          pos. 14 changes first, when i move the group from its origin place, where it was created.......this transformation is not related to absolute zero.... 😞

          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            Does this work ?

            If I resue my code with TIG's recommendations..

            gpz = group.transformation.origin.z
            zmax = pts.map{|p| p.z + gpz }.max

            You could also have a look at Bounds.corner.points and get the highest Z value from those,
            unless you are interested in a particular vertice or so..

            1 Reply Last reply Reply Quote 0
            • artmusicstudioA Offline
              artmusicstudio
              last edited by

              hi jolran,

              1. i'll test your new idea later tonight, but i had the formula with origin
              tra = @main_element.transformation.origin
              

              already and it gave me the origin of the group at the point, where it was made, not to absolute [0,0,0]. but we shall see !!

              1. bounding box : i tried this, but i don't need the lowest point of a group, but one special corner within it, so lowest z of the bbox does not help here.
                and when i retrieve the bbox of the nested element, itz again is relative, not absolute.

              seems to be tricky somehow....

              thanx
              stan

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

                @artmusicstudio said:

                hi tig,
                i understood and made some tests.
                but if i have a group named

                @main_element (i persume it has a transformation, even it is not moved or anything else)
                and say

                Yes at the moment the group is created it is given an Identity Transformation.

                tra = @main_element.transformation
                i get errors , since my syntax is wrong.

                The only reason this would give you syntax errors is if the variable @main_element has not been physically associated with the group.

                could you give me the syntax for retrieving the transformation from a group?
                i tried a lot of ways, but always get errors.

                mod = Sketchup.active_model # Open model
                > ent = mod.entities # All entities in model
                > sel = mod.selection # Current selection
                > @main_element = ent.grep(Sketchup;;Group).select{|g| g.name=="@main_element"}[0]
                > tra = @main_element.transformation; #save the current transformation
                > @main_element.transform! tra.inverse; # return the group to its created position
                > zmax = @main_element.bounds.max.z; puts zmax; # get the max z
                > @main_element.transform! tra; # return the group to its current position
                

                thank you!
                stan

                edit:
                when i define tra as

                tra = @main_element.transformation.to_a
                

                i get

                tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]

                how can i interpret the numbers?

                edit 2:
                when i move a group in Z+, tra becomes

                tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1968.503937007874, 1.0]

                so 14th position seems to give the height.

                the problem is, that if i create a plane in a certain height (Z+), the transformation counts this as 0,0,0 .
                pos. 14 changes first, when i move the group from its origin place, where it was created.......this transformation is not related to absolute zero.... 😞

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

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • S Offline
                  slbaumgartner
                  last edited by

                  @sdmitch said:

                  @artmusicstudio said:

                  hi tig,
                  i understood and made some tests.
                  but if i have a group named

                  mod = Sketchup.active_model # Open model
                  > > ent = mod.entities # All entities in model
                  > > sel = mod.selection # Current selection
                  > > @main_element = ent.grep(Sketchup;;Group).select{|g| g.name=="@main_element"}[0]
                  > > tra = @main_element.transformation; #save the current transformation
                  > > @main_element.transform! tra.inverse; # return the group to its created position
                  > > zmax = @main_element.bounds.max.z; puts zmax; # get the max z
                  > > @main_element.transform! tra; # return the group to its current position
                  

                  thank you!
                  stan

                  The code block above seems to have been edited out of your earlier post, but sdmitch grabbed it first. It seems to reveal confusion between the name attribute of a group and the symbolic name of a variable that refers to that group. These are separate, unrelated concepts. That is, if you write

                  @foo = ents.add_group #@foo is a variable that refers to a group with no name attribute
                  @foo.name = "@main_element" #@foo now refers to a group with name attribute "@main_element"

                  Following this code, there is no such variable as @main_element. Conversely, there is no group whose name attribute is @foo.

                  Your search above looks for a group whose name attribute is "@main_element". Did you assign that previously using Group#name=, or are you assuming that because you earlier created a group referenced by a variable named @main_element that the group has that as its name attribute (wrong). In any case, you need to test what value was assigned to @main_element by your search. I bet it is nil (because the search found nothing), and that is the cause of your syntax error.

                  Steve

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    I haven't follow along the other discussion so pardon me if butting in..

                    But If your only concern is the get the heighest elements point(?) won't this code work regardless of any transformation made ?

                    %(#FF0000)[bb = group.bounds # could be any element responding to Bounds.
                    cornersZmax = (0..7).collect{|i| bb.corner(i).z }.max]

                    I tested and it seams to be working. ?

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

                      Since I haven't seen your code...
                      Here's a guess...

                      If your 'reference' is to a 'group' OR a 'component-instance', then it WILL have a 'transformation'.
                      BUT if that 'reference' is to a 'definition' it will NOT ! πŸ˜’

                      puts @main_element.class in your code will tell you what the reference is...

                      TIG

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

                        What are we trying to determine? If it is the highest point regardless of location and/or orientation or the true height of the group?

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

                        http://sdmitch.blogspot.com/

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          πŸ˜„

                          I interpreted this as highest point.

                          @unknownuser said:

                          i would like to calculate the height of a defined point (say toppoint of a bbox)
                          above absolute sketchup 0,0,0.

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

                            In that case, ?group?.bounds.max.z should give you that in SU8.

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

                            http://sdmitch.blogspot.com/

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

                              It's possible to devise a group with a transformation where the group.bound.max.z will NOT be a vertex.
                              If the proposition is to find the highest vertex in a group that is not the same thing ?
                              However, if you are simply trying to find the max.z it will do...
                              See this simple illustration...


                              Capture.PNG

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • jolranJ Offline
                                jolran
                                last edited by

                                @unknownuser said:

                                element.bounds.max.z

                                Yeah, that's way simpler...
                                But as TIG pointed out bbox cp is not always safest way to find highest vertex, so normally one end up traversing the collection anyway.

                                I'm starting to wonder if TO wants to measure the face height..

                                to reuse the transformation origin maybe try this.. I guess theres more than 1 way to do this.

                                targetZ = 0
                                org = group.transformation.origin
                                
                                group.entities.to_a.grep(Sketchup;;Edge).each{|edg|
                                    sz = edg.start.position.z
                                    ez = edg.end.position.z
                                    tmax = (sz > ez ? sz ; ez) + org.z
                                    next unless tmax > targetZ 
                                     targetZ = tmax
                                }
                                puts targetZ.to_l
                                
                                1 Reply Last reply Reply Quote 0
                                • sdmitchS Offline
                                  sdmitch
                                  last edited by

                                  @jolran said:

                                  @unknownuser said:

                                  element.bounds.max.z

                                  Yeah, that's way simpler...
                                  But as TIG pointed out bbox cp is not always safest way to find highest vertex, so normally one end up traversing the collection anyway.

                                  I'm starting to wonder if TO wants to measure the face height..

                                  to reuse the transformation origin maybe try this.. I guess theres more than 1 way to do this.

                                  targetZ = 0
                                  > org = group.transformation.origin
                                  > 
                                  > group.entities.to_a.grep(Sketchup;;Edge).each{|edg|
                                  >     sz = edg.start.position.z
                                  >     ez = edg.end.position.z
                                  >     tmax = (sz > ez ? sz ; ez) + org.z
                                  >     next unless tmax > targetZ 
                                  >      targetZ = tmax
                                  > }
                                  > puts targetZ.to_l
                                  

                                  Sorry but that only works if there is no rotation. Here is another way

                                  targetZ = 0
                                  tra = group.transformation
                                  group.entities.to_a.grep(Sketchup;;Edge).each{|edg|
                                      sz = edg.start.position.transform(tra).z
                                      ez = edg.end.position.transform(tra).z
                                  	targetZ = [targetZ,sz,ez].max
                                  }
                                  puts targetZ.to_l
                                  

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

                                  http://sdmitch.blogspot.com/

                                  1 Reply Last reply Reply Quote 0
                                  • jolranJ Offline
                                    jolran
                                    last edited by

                                    Dats true. But I don't understand why you opt to create a new Array for each edge instead of a ternary πŸ˜•

                                    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