• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Inche fraction in ruby script

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 869 Views 4 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.
  • N Offline
    nics
    last edited by 25 Jun 2010, 01:51

    hi guys, here's my code

    centerpoint = Geom::Point3d.new

    Create a circle perpendicular to the normal or Z axis

    vector = Geom::Vector3d.new 0,1,0
    vector2 = vector.normalize!
    model = Sketchup.active_model
    entities = model.active_entities
    edges = entities.add_circle centerpoint, vector2, 2.inch
    faceCircle = entities.add_face(edges)
    faceCircle.pushpull height

    however, I'd like to have 2 1/8 inches in the radius ... can I write it directly in the code and if so, how ? Otherwise, I guess I need to convert into a float number ? thanks

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 25 Jun 2010, 02:49

      2 1/8 can easily be re-written as 2.125, so why not just write it like that? I'm guessing this is a question that is actually larger than just the example provided?

      Also, SU ruby works in inches, so there is no need to add the .inches to the end of the 2. But if you'd really like it to accept a fraction, you could write 2 1/8 as (2.0)+(1.0/8.0). That should be a workable solution. Good luck,

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 25 Jun 2010, 08:17

        And also, of course, you may set your units in the Model Info dialog, Units page, to either Architectural or Fractional, (and choose precision,) if you wish the app UI to run in fractions.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 25 Jun 2010, 08:17

          @nics said:

          however, I'd like to have 2 1/8 inches in the radius ... can I write it directly in the code and if so, how ?

          Yes. In Ruby (and in Math,) fractions are really just division.

          @nics said:

          Otherwise, I guess I need to convert into a float number ?

          Again yes, you need to convert using the .to_f method, otherwise Ruby will truncate the fractional part and just return the Integer part (if both the numerator and denominator are Integer.)
          Here's an example:
          ` mod=Sketchup.active_model

          #Sketchup::Model:0x60aeb04
          ents=mod.entities
          #Sketchup::Entities:0x60a3434
          pt1=[12+1/8.to_f,14+5/8.to_f,0+7/8.to_f]
          [12.125, 14.625, 0.875]
          pt2=[33+1/2.to_f,67+3/4.to_f,47+3/8.to_f]
          [33.5, 67.75, 47.375]
          line=ents.add_line( pt1, pt2 )
          #Sketchup::Edge:0x602d1bc
          p line.start.position
          Point3d(12.125, 14.625, 0.875)
          p line.end.position
          Point3d(33.5, 67.75, 47.375)`

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 25 Jun 2010, 08:24

            You can also use strings, and apply the Sketchup extension to the String class, which adds the .to_l method.
            Example:
            ` length = '5 3/8"'.to_l

            5.375`

            See the API (Base Classes): String
            http://code.google.com/apis/sketchup/docs/ourdoc/string.html

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • T Offline
              todd burch
              last edited by 25 Jun 2010, 11:14

              Hi nics.

              You can use fractions pretty easily.

              
              entities = Sketchup.active_model.active_entities ; 
              face = entities.add_face(entities.add_circle(ORIGIN, Y_AXIS, 2.125.inch)).pushpull 4.inch ;
              
              or
              
              face = entities.add_face(entities.add_circle(ORIGIN, Y_AXIS, '2 1/8"'.to_l)).pushpull 4.inch ;
              
              

              Note that there are many predefined constants for common locations/vectors you can use, and when it's not too cryptic for you, you can string commands together as well. Paste the above 2 lines into the Ruby Console and you'll get the same result.

              Todd

              1 Reply Last reply Reply Quote 0
              • N Offline
                nics
                last edited by 25 Jun 2010, 20:12

                wow thank you guys its really appreciated 😄

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement