Offset a line Ruby command
-
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
-
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...
-
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 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 exampleSet 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 = 2ents = 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
-
First, your code...
which I assume is just a sample...door_width = 3
makes it 3" widedoor_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 thatgroup.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 said:
First, your code...
which I assume is just a sample...door_width = 3
makes it 3" widedoor_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 thatgroup.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
-
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...
Advertisement