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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    How to subtract Point3D.Z value with a variable

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 840 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.
    • B Offline
      bakbek
      last edited by

      seems simple but i can't make this thing work 😳

      this is form Robin Hills HeightTool.rb

      def onLButtonUp(flags, x, y, view) #called when left mouse button released
      txt='Height: '+@pt[2].to_s
      model=Sketchup.active_model
      e=model.entities
      t=e.add_text txt,@pt,@vec
      end

      what i want to do is make this tool work relative to a set zero level... not the files axis zero. i get the user set level with the same method as in the drop ruby script so now i have a @@level=The user set value

      but performing
      txt='Height: '+(@pt[2]-@@level).to_s

      doesn't show the right value
      @@level.to_s alone works well but the subtraction doesn't

      what am i doing wrong here 😳

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        @bakbek said:

        txt='Height: '+(@pt[2]-@@level).to_s

        doesn't show the right value

        @@level.to_s alone works well but the subtraction doesn't

        what am i doing wrong here 😳

        What value is displayed?

        What is @@level prior to the subtract? What is its class?
        What is @pt[2] prior to the subtract? What is its class?
        What is the class after you do the subtract?

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          As we can see from this prior reference:

          
          t=e.add_text txt,@pt,@vec
          
          

          @pt is a Point3D. Therefore, @pt[2] would be the z value.

          Personally, I would have coded

          
          @pt.z
          
          

          but to each his own.

          1 Reply Last reply Reply Quote 0
          • A Offline
            AlexMozg
            last edited by

            I think that all is far simpler...

            
            txt='Height; '+(@pt[2].z - @@level.to_l).to_s
            ...
            or
            For example;
            @@level = 100.mm
            txt='Height; '+(@pt[2].z - @@level).to_s
            
            
            1 Reply Last reply Reply Quote 0
            • B Offline
              bakbek
              last edited by

              Hi Todd & Alex, thanks for your assistance.

              I've attached a screen capture for you to see what I'm trying to achieve here... it's not working yet.

              using the context menu when clicking on a surface i can assign the surface height to the @@level variable, it is suppose to be a number or length class as far as i can say. when i assign it directly to txt i get proper values... it is the math with the @pt (point3d class) that gets odd values as you can see in the image

              the proper height should have been 120cm at the note but it is 47.244094488189

              i guess i either mix up classes or units or something else i don't know about


              Sketchup Screen Capture

              1 Reply Last reply Reply Quote 0
              • A Offline
                a4chitect
                last edited by

                try converting your results to the metric system, you are probably getting sketchup internal imperial units.

                1 Reply Last reply Reply Quote 0
                • B Offline
                  bakbek
                  last edited by

                  how to? this is what i can't seem to get right

                  1 Reply Last reply Reply Quote 0
                  • G Offline
                    GreyHead
                    last edited by

                    Google says 120 centimeters = 47.2440945 inches

                    Bob

                    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