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

    Offset a line Ruby command

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 4.6k 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.
    • S Offline
      sachi
      last edited by

      Dear all,
      Does anybody know about a Ruby API command to offset a line? I already checked the API.
      It has a command to offset a point.

      point1 = point2.offset vector

      But i need to offset a line, like a parallel line. Is there any command in Ruby API which i can work with or any suggestions to offset a line(draw a parallel line)?

      please help me, im stuck here

      thank you in advance

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

        There are several ongoing 'offset' discussions in the Developers' forum...
        There is no API 'offset' method, for edges or faces.
        But there are various scripted solutions.
        If you have one edge, then you are able to get its vertices, from these you can get two points, and then you can offset these points by a vector of the desired length... and then use something like edge.parent.entities.add_line(pt0,pt1) to make the parallel 'copy'...

        PS: I have moved this into the right forum...

        TIG

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

          module Sachi
            module SomePlugin
              class << self
              def clone_edge_by_offset( e, vec )
                return nil unless e.is_a?(Sketchup;;Edge)
                return nil unless vec.is_a?(Geom;;Vector3d) || vec.is_a?(Array)
                e.parent.entities.add_line( e.start.position.offset(vec), e.end.position.offset(vec) )
              end # method
              end # proxy class
            end # plugin module
          end # Author's namespace
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • R Offline
            Remmel
            last edited by

            i have the same problem... not to offset a edge... but offset a face in ruby code
            i hope TIG have a solution for this issue
            see example

            Set the house dimensions (in feet)

            @num_windows = 4
            door_width = 3
            door_height = 7
            house_height = 9
            house_length = (@num_windows + 1) * (door_width + 2) + 2
            house_width = 10
            roof_height = 2

            ents = model.entities

              pl = ents.add_face([0, 0, 0], [0, house_length, 0],
                 [house_width, house_length, 0], 
                 [house_width, 0, 0], [0, 0, 0])
            	 pl.pushpull -1
            
            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              First, your code...
              which I assume is just a sample...

              door_width = 3
              makes it 3" wide

              door_width = 3.feet
              makes it 3' wide !
              etc...

              I.E. force the use of a 'length', rather than passing a default 'number' - which SketchUp always interprets as inches !

              Also... you'd probably be better off adding a new group into model.active_entities and then adding your new geometry into that group.entities

              Currently your code draws a rectangle on the ground [Z=0 - and 0 is 0 in ALL length-units!] and then you extrudes it downwards by -1["]...
              If you wanted -1' then use -1.feet etc


              AND... you haven't actually explained 'how' you want to 'offset a face' !?
              Your code uses 0 for all of the Z values used in the rectangle's corner-points, but of course you could use any value for those Z's - but remember that they should be set to the same length if a valid 'flat' rectangle is to result...

              TIG

              1 Reply Last reply Reply Quote 0
              • R Offline
                Remmel
                last edited by

                @tig said:

                First, your code...
                which I assume is just a sample...

                door_width = 3
                makes it 3" wide

                door_width = 3.feet
                makes it 3' wide !
                etc...

                I.E. force the use of a 'length', rather than passing a default 'number' - which SketchUp always interprets as inches !

                Also... you'd probably be better off adding a new group into model.active_entities and then adding your new geometry into that group.entities

                Currently your code draws a rectangle on the ground [Z=0 - and 0 is 0 in ALL length-units!] and then you extrudes it downwards by -1["]...
                If you wanted -1' then use -1.feet etc


                AND... you haven't actually explained 'how' you want to 'offset a face' !?
                Your code uses 0 for all of the Z values used in the rectangle's corner-points, but of course you could use any value for those Z's - but remember that they should be set to the same length if a valid 'flat' rectangle is to result...

                now i know in Sketchup API , there is no method to offset a face.... but i thought to offset a face like this..... pl.offset 1, to get a border of 1" width

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

                  You can replicate an offset for a face.
                  The code is not so simple.
                  Install my old tool https://sketchucation.com/pluginstore?pln=TIG_Smart_offset
                  Read the code and try to understand how it works...
                  It's somewhat more complicated than you need, but you should be able to extract what you need...

                  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