# Offset Problem

**URL:** <https://discourse.mcneel.com/t/offset-problem/78364>\
**Category:** Scripting\
**Tags:** python\
**Created:** [February 6, 2019, 5:33am UTC](https://discourse.mcneel.com/t/offset-problem/78364 "2019-02-06T05:33:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 6, 2019, 5:33am UTC](https://discourse.mcneel.com/t/offset-problem/78364/1 "2019-02-06T05:33:38Z")

</div>

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

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/6/1/617f085dd538e075cdafa4181ed7037045424b7d.png)

The length of offset is **-30 mm**

[**Expected curves**] The offset curve i expect is,

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/3/b/3b56d810edf28243709f0dd954b727c66ef48370.png)

[**Reality**]The offset i am getting is,

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/7/b/7bbd039848a66a4bad4909228f77fb750ec387ab.png)

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/f/3fe50cff2842c264703994650e012ec97a9fce8c.stp) (3.8 KB)

---

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 8, 2019, 6:29am UTC](https://discourse.mcneel.com/t/offset-problem/78364/2 "2019-02-08T06:29:38Z")

</div>

Hi @pascal, please can you help me?

---

<div class="post-metadata">

**Author:** ![Mahdiyar](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahdiyar/32/472862_2.png) [@Mahdiyar](https://discourse.mcneel.com/u/Mahdiyar)\
**Post date:** [February 8, 2019, 8:01am UTC](https://discourse.mcneel.com/t/offset-problem/78364/3 "2019-02-08T08:01:04Z")

</div>

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/f/bf10f07b08ba63a2b34d74ea428a69102a8f50cd.py) (734 Bytes)

P.S. You can also use `OffsetPolyline` command from [CLIPPER](https://www.food4rhino.com/app/clipper-grasshopper-and-rhino) plugin.

---

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 8, 2019, 9:17am UTC](https://discourse.mcneel.com/t/offset-problem/78364/4 "2019-02-08T09:17:40Z")

</div>

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

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/1/5/153dc4b1e64a482b56e77bfb1154f85ba3bac921.png)  
can you help me here,  
Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![Mahdiyar](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahdiyar/32/472862_2.png) [@Mahdiyar](https://discourse.mcneel.com/u/Mahdiyar)\
**Post date:** [February 8, 2019, 9:35am UTC](https://discourse.mcneel.com/t/offset-problem/78364/5 "2019-02-08T09:35:47Z")

</div>

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/5/e5d11904228098db8e4d09085d6b2aeb4d4ca8b0.py) (1.1 KB)

---

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 11, 2019, 6:33am UTC](https://discourse.mcneel.com/t/offset-problem/78364/6 "2019-02-11T06:33:29Z")

</div>

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**]

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/7/a/7a2a9d3c8e58254d27eadd15bbd1210c7f3384f5.png)

[**Expected offset**]

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/e/a/ead2491492003565fd0276efd0afe37ae101e643.png)

Please find the cad file attached below

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

Thank you 🙂

[find\_corner\_points.stp](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/1/f1faef07f9ef69632524f9d2752c69af1b3e127e.stp) (9.9 KB)

---

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 13, 2019, 6:09am UTC](https://discourse.mcneel.com/t/offset-problem/78364/7 "2019-02-13T06:09:06Z")

</div>

Hi, Any updates from anyone?

---

<div class="post-metadata">

**Author:** ![Michael\_Pryor](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/michael_pryor/32/489117_2.png) [@Michael\_Pryor](https://discourse.mcneel.com/u/Michael_Pryor)\
**Post date:** [February 13, 2019, 6:28am UTC](https://discourse.mcneel.com/t/offset-problem/78364/8 "2019-02-13T06:28:35Z")

</div>

Use [Clipper](https://www.food4rhino.com/app/clipper-grasshopper-and-rhino), 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](http://www.angusj.com/delphi/clipper.php) 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.

 ![Capture](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/4/a/4acdd86c5a03d45c9ccf447846f41fcf7d91864c.jpeg)

---

<div class="post-metadata">

**Author:** ![sumuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sumuk/32/129863_2.png) [@sumuk](https://discourse.mcneel.com/u/sumuk)\
**Post date:** [February 13, 2019, 6:59am UTC](https://discourse.mcneel.com/t/offset-problem/78364/9 "2019-02-13T06:59:44Z")

</div>

Hi, Thanks a lot.

> [@Michael\_Pryor](#):
>
> source code is available on Github.

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

---

<div class="post-metadata">

**Author:** ![Michael\_Pryor](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/michael_pryor/32/489117_2.png) [@Michael\_Pryor](https://discourse.mcneel.com/u/Michael_Pryor)\
**Post date:** [February 13, 2019, 7:28am UTC](https://discourse.mcneel.com/t/offset-problem/78364/10 "2019-02-13T07:28:32Z")

</div>

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](https://github.com/arendvw/clipper)

---

<div class="post-metadata">

**Author:** ![Petras\_Vestartas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/petras_vestartas/32/480531_2.png) [@Petras\_Vestartas](https://discourse.mcneel.com/u/Petras_Vestartas)\
**Post date:** [February 13, 2019, 7:54am UTC](https://discourse.mcneel.com/t/offset-problem/78364/11 "2019-02-13T07:54:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Pryor](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/michael_pryor/32/489117_2.png) [@Michael\_Pryor](https://discourse.mcneel.com/u/Michael_Pryor)\
**Post date:** [February 13, 2019, 7:59am UTC](https://discourse.mcneel.com/t/offset-problem/78364/12 "2019-02-13T07:59:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Petras\_Vestartas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/petras_vestartas/32/480531_2.png) [@Petras\_Vestartas](https://discourse.mcneel.com/u/Petras_Vestartas)\
**Post date:** [February 13, 2019, 8:14am UTC](https://discourse.mcneel.com/t/offset-problem/78364/13 "2019-02-13T08:14:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Michael\_Pryor](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/michael_pryor/32/489117_2.png) [@Michael\_Pryor](https://discourse.mcneel.com/u/Michael_Pryor)\
**Post date:** [February 13, 2019, 8:21am UTC](https://discourse.mcneel.com/t/offset-problem/78364/14 "2019-02-13T08:21:43Z")

</div>

You mean like this with polyline boolean?

 ![Capture](https://global.discourse-cdn.com/mcneel/original/3X/1/7/179f55d20ec46d056a9caef007a9522328c693e7.jpeg)

---

<div class="post-metadata">

**Author:** ![Petras\_Vestartas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/petras_vestartas/32/480531_2.png) [@Petras\_Vestartas](https://discourse.mcneel.com/u/Petras_Vestartas)\
**Post date:** [February 13, 2019, 8:34am UTC](https://discourse.mcneel.com/t/offset-problem/78364/15 "2019-02-13T08:34:01Z")

</div>

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