Offset Problem

Hi, Greetings! I wanted to offset a curve (which is a 2d curve represented in 3d).

The length of offset is -30 mm

[Expected curves] The offset curve i expect is,

[Reality]The offset i am getting is,

Can you suggest me some Rhinoscriptsyntax’s function that does my job, The code and the cad file i am using is attached below.

Thanks in advance

Please Note: I am using Rhino for Windows and I am using Rhino python (rhinoscriptsyntex) for my code.

import rhinoscriptsyntax as rs

id = rs.ObjectsByName("Sketch.1")
direction = (0,0,0)
distance = -30
rs.OffsetCurve(id, direction, distance)

offset_problem.stp (3.8 KB)

Hi @pascal, please can you help me?

I’m sure @pascal knows better solutions but meanwhile you can use my script:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc

polyline = rs.GetObject("Select a polyline", rs.filter.curve)
distance = rs.GetReal("Offset Distance", -30)
segments = rs.ExplodeCurves(polyline)
rhinoPolyline = rs.coercecurve(polyline)
success,plane = rhinoPolyline.TryGetPlane()
ids = []
rs.EnableRedraw(False)
for segment in segments:
    rhinoSegment = rs.coercecurve(segment)
    rs.DeleteObject(segment)
    rhinoSegment = rhinoSegment.Offset(plane, distance, 0.1, rg.CurveOffsetCornerStyle.None)[0]
    ids.append(sc.doc.Objects.AddCurve(rhinoSegment))
rs.SelectObjects(ids)
rs.Command("_CurveBoolean _DeleteInput=All _CombineRegions=Yes _Output=Curves _AllRegions _Enter")

Sumuk.py (734 Bytes)

P.S. You can also use OffsetPolyline command from CLIPPER plugin.

1 Like

Thank you @Mahdiyar, But when i offset for -10 mm , the result i am expecting is


can you help me here,
Thanks in advance :slight_smile:

This one is even messier than previous one:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc

polyline = rs.GetObject("Select a polyline", rs.filter.curve)
distance = rs.GetReal("Offset Distance", -30)
segments = rs.ExplodeCurves(polyline)
rhinoPolyline = rs.coercecurve(polyline)
success,plane = rhinoPolyline.TryGetPlane()
ids = []
rs.EnableRedraw(False)
for segment in segments:
    rhinoSegment = rs.coercecurve(segment)
    rs.DeleteObject(segment)
    rhinoSegment = rhinoSegment.Offset(plane, distance, 0.1, rg.CurveOffsetCornerStyle.None)[0]
    ids.append(sc.doc.Objects.AddCurve(rhinoSegment))
rs.SelectObjects(ids)
rs.Command("_CurveBoolean _DeleteInput=All _CombineRegions=Yes _Output=Curves _AllRegions _Enter")
results = rs.SelectedObjects()
if results:
    for result in results:
        if not rs.IsCurveClosed(result):
            rs.DeleteObject(result) 
results = rs.SelectedObjects()
if len(results) == 0:
    rhinoPolyline = rhinoPolyline.Offset(plane, distance, 0.1, rg.CurveOffsetCornerStyle.Sharp)[0]
    sc.doc.Objects.AddCurve(rhinoPolyline)

Sumuk.py (1.1 KB)

2 Likes

Hi, Thank you @Mahdiyar, Sorry for delay response.
But i have a problem, The problem is when the curve is complex. Can you help me or give me solution when curve is complex

[ Complex Curve ]

[ Expected offset ]

Please find the cad file attached below

Note: The above offset is done manually and the offset length is "-5 mm "

Thank you :slight_smile:

find_corner_points.stp (9.9 KB)

Hi, Any updates from anyone?

Use Clipper, which is for Rhino and Grasshopper (it will give you new rhino commands) you won’t get better than Clipper. it uses the clipper library there is no point to script it in rhino as it just won’t be as robust or as fast. If you really need to script something the source code is available on Github.

Hi, Thanks a lot.

Can you share me github link, as i cannot use grasshopper at this time, I can only use python. Also please share the command you used in clipper to get this

Thanks in Advance

You do not need Grasshopper, it gives you some Rhino commands as well, in this case the command is OffsetPolyline (Once you have clipper installed). Here is the github: https://github.com/arendvw/clipper

Hi @Michael_Pryor Do you know how to Clip open polylines using Clipper?

I’m not sure what you mean, for me it works on all polyline types. Do you have an image of what you mean?

For instance I have one closed polyline and one open polyline.
And I would like to cut open polyline with closed one.

But it all boolean operations works for closed polylines. Is there any method in clipper that allows to cut open curves, like shatter component in GH?

You mean like this with polyline boolean?

1 Like

Oh, I thought it wont work with open curves, thanks