sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Retrievin object's absolute height ??

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 5 Posters 773 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.
    • 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