sketchucation logo sketchucation
    • Login
    πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

    Help on scale

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 291 Views 3 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
      shirazbj
      last edited by

      Hi,

      I use the following code to draw a r=100 cyclinder. With the SketchUp runing in Archi mm template, what I got is a r=5080 cyclinder which is 25.4 times bigger. Thought it is in inch.

      I was wondering should I specify what template to use in my code? If so, how to do that?

      Thanks in advance

      Cean

      def my_cylinder
      
          x=0
          y=0
          z=0
          idir=1
          r=100
          h=500
          
          model = Sketchup.active_model
          
          $entities=model.entities
          
          p1 = Geom;;Point3d.new(x,y,z)
          vector= Geom;;Vector3d.new(1,0,10)
      
          circleI = $entities.add_circle p1, vector, r
          base = $entities.add_face circleI
          base.pushpull h
      
      
      end #def hw_cylinder
      
      UI.menu("Plugins").add_item("my") { my_cylinder }
      
      1 Reply Last reply Reply Quote 0
      • S Offline
        shirazbj
        last edited by

        Thanks Dan. So, I was right. It was in inch.

        It's a bit hard to understand the API:
        "
        The mm method is used to convert a number to millimeters.

        It returns a Length value which is the same length as the given value. For example len = 25.4.mm returns 1 inch.
        
        Returns:
        
        mm
            a value in millimeters if successful
        
         value = 10
         mm = value.mm
        

        "

        The result is the same length but with a different unit.

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

          In the API a 'raw' number is always taken to be in inches when in the context of a 'length' so 500 is taken as 500".
          To get it to be taken as 'mm' you write it as 500.mm [or 50.cm if you prefer 'cm' etc...]

          For 'angles' a 'raw' number is assumed to be 'radians' - but you can use 90.degrees to set an angle you can readily understand... otherwise it'd have to be expressed as the more awkward Math::PI/2 to be the equivalent in radians!

          TIG

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            See the API on classes:

            • Numeric
            • Length

            If you want the radius of the cylinder to be 100mm, then in Ruby:
            r = 100.mm puts(r)

            3.93700787401575

            .

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              Yes.. Sketchup and the Ruby API use Inches internally.

              The "User Units" are only for display in dialogs.

              I'm not here much anymore.

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

                Instead of writing every 'mm' in code, I thought it's more easy to draw as it is and scale back at the end.

                That also cleared me from inserting a DWG file, need scale back to get the dimensions show in right number.

                Thanks.

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

                  @shirazbj said:

                  Instead of writing every 'mm' in code, I thought it's more easy to draw as it is and scale back at the end. That also cleared me from inserting a DWG file, need scale back to get the dimensions show in right number.
                  Thanks.

                  An imported DWG will use whatever units it has set in the import 'options' dialog opened from the main DWG import browser, So you can rely on that to always be correct.

                  TIG

                  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