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

Offset a line Ruby command

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 4.6k Views
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 8 Feb 2013, 01:13

    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
    • T Offline
      TIG Moderator
      last edited by 8 Feb 2013, 09:41

      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
      • D Offline
        Dan Rathbun
        last edited by 9 Feb 2013, 04:56

        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 28 Apr 2018, 08:41

          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
          • T Offline
            TIG Moderator
            last edited by 28 Apr 2018, 17:38

            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 29 Apr 2018, 05:20

              @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
              • T Offline
                TIG Moderator
                last edited by 29 Apr 2018, 12:59

                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