Is there a way of calling Clipper’s OffsetPolyline from a Python script, without using rs.Command()?
Thank you
I have this little script working:
from __future__ import print_function
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghcomp
def main():
msg = 'Pick polyline'
pline = rs.GetObject(msg, filter=rs.filter.curve, preselect=True, select=True)
if not pline:
print("Error: Need polyline.")
return
ret = ghcomp.ClipperComponents.PolylineOffset(pline, distance=1, tolerance=0.001,
plane=rs.WorldXYPlane(), closedfillet=1, openfillet=0, miter=2)
if not ret:
return
print(ret)
return
if __name__ == '__main__':
main()
which runs without errors. It outputs this:
{‘contour’: <Rhino.Geometry.PolylineCurve object at 0x00000000000000BE [Rhino.Geometry.PolylineCurve]>, ‘holes’: <Rhino.Geometry.PolylineCurve object at 0x00000000000000BF [Rhino.Geometry.PolylineCurve]>}
I assume ‘contour’ is the outset, and ‘holes’ the insets???
To add the actual outset polyline to the document, would I have to run sc.doc.Objects.AddPolyline(???)
somehow? How would I do this?
I also don’t see the Project=FitToCurve
option that I get when running OffsetPolyline as a Rhino command.
Thank you for your patience
I assume ‘contour’ is the outset, and ‘holes’ the insets???
Correct!
To add the actual outset polyline to the document, would I have to run
sc.doc.Objects.AddPolyline(???)
somehow? How would I do this?
This is the first time I’m using RhinoPython and node in code, but what you get back from the node in code is quite ackward. It can be a list, or it can be a single item, but it changes its type on the quantity of items.
I also don’t see the
Project=FitToCurve
option that I get when running OffsetPolyline as a Rhino command.
This is a bit different in the grasshopper component. Fitting a plane to the points of the first polyline is what it actually does.
from __future__ import print_function
from collections import Iterable
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghcomp
import scriptcontext
def main():
msg = 'Pick polyline'
#pline = rs.GetObject(msg, filter=rs.filter.curve, preselect=True, select=True)
plines = rs.GetObjects(msg, filter=rs.filter.curve, preselect=True, select=True)
if not plines:
print("Error: Need polyline.")
return
# Equivalent to fit plane:
points = rs.PolylineVertices(plines[0])
plane = rs.PlaneFitFromPoints(points)
ret = ghcomp.ClipperComponents.PolylineOffset(plines, distance=100, tolerance=0.001,
plane=plane, closedfillet=1, openfillet=0, miter=2)
if (ret.contour):
if isinstance(ret.contour, Iterable):
for item in ret.contour:
scriptcontext.doc.Objects.AddCurve(item)
else:
scriptcontext.doc.Objects.AddCurve(ret.contour)
if (ret.holes):
if isinstance(ret.holes, Iterable):
for item in ret.holes:
scriptcontext.doc.Objects.AddCurve(item)
else:
scriptcontext.doc.Objects.AddCurve(ret.holes)
return
if __name__ == '__main__':
main()
Ah, I see. Thank you so much for explaining how this works