offset a line Ruby command

offset a line Ruby command

Postby sachi » Fri Feb 08, 2013 2:13 am

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
0

sachi 
 

Re: offset a line Ruby command

Postby TIG » Fri Feb 08, 2013 10:41 am

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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: offset a line Ruby command

Postby Dan Rathbun » Sat Feb 09, 2013 5:56 am

Code: Select all
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
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: offset a line Ruby command

    Postby Remmel » Sat Apr 28, 2018 9:41 am

    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
    0

    Remmel 
     

    Re: offset a line Ruby command

    Postby TIG » Sat Apr 28, 2018 6:38 pm

    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...
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    Re: offset a line Ruby command

    Postby Remmel » Sun Apr 29, 2018 6:20 am

    TIG wrote: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
    0

    Remmel 
     

    Re: offset a line Ruby command

    Postby TIG » Sun Apr 29, 2018 1:59 pm

    You can replicate an offset for a face.
    The code is not so simple.
    Install my old tool https://sketchucation.com/pluginstore?p ... art_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...
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: Ehllan_06 and 7 guests

    Visit our sponsors: