# Help split polysurface at their corner

**URL:** <https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540>\
**Category:** Scripting\
**Tags:** windows, python, rhino7\
**Created:** [October 1, 2022, 8:52am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540 "2022-10-01T08:52:46Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 1, 2022, 8:52am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/1 "2022-10-01T08:52:46Z")

</div>

My work often has to split polysurface at their corner . I need a solution for this work automatically, please help me.

 ![AS](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/b/2/9b2c622c8d57197a14a1c82a1137f9187c86edbb.png)

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 2, 2022, 1:42pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/2 "2022-10-02T13:42:38Z")

</div>

Simplified, I took the closed curve in the top object. problem is how to draw line with corners of object. Please help

 ![PIC1](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/a/f/baf37a78e9eea48bdb2b3cafe6c804925627cf00.png)

---

<div class="post-metadata">

**Author:** ![Tom\_P](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tom_p/32/766520_2.png) [@Tom\_P](https://discourse.mcneel.com/u/Tom_P)\
**Post date:** [October 2, 2022, 9:35pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/3 "2022-10-02T21:35:16Z")

</div>

Dear @ins_me welcome to the forum.  
are you searching for a script to do this ?  
do you have any scripting experience ?  
do you have a collection of possible special cases ?

maybe post a .3dm file (just drag and drop to the edit - window)

if you need a workflow to do it quite fast:  
one version i am thinking of:

(left to right)

subselect (cmd shift (mac) or ctrl shift (pc) + click / or rectangular selection) the first and last connection.  
delete them  
\_loft the remaining polylines (option split at tangents = yes)  
\_explode

maybe you need  
\_dupBoarder to get the curves

are the initial polylines always parallel with same distance and same amount of points / semgents?  
maybe also check the commands  
\_offset  
\_curveBoolean

 ![Screenshot 2022-10-02 at 23.28.26](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/5/d/45dd3b1aa7b1b90f1af40314ee554f5b2546bbc5.png)

you can combine the above commands into a macro (which is simpler then coding)  
[https://wiki.mcneel.com/rhino/basicmacros](https://wiki.mcneel.com/rhino/basicmacros)

if you want to learn scripting - the point to start

> **[Rhino and Grasshopper Developer Documentation](https://developer.rhino3d.com)**
>
> Official developer resources for Rhino and Grasshopper. Rhino developer tools are royalty free and include support.

kind regards - tom

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 3, 2022, 3:50am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/4 "2022-10-03T03:50:15Z")

</div>

I’m looking for a script to do this. Split polysurface at the corners of the subject for machining.  
[SUBJECT.3dm](https://discourse.mcneel.com/uploads/short-url/fkFdVGXwAnLrYsdWoDHqqGFfTxe.3dm) (262.7 KB)

---

<div class="post-metadata">

**Author:** ![Tom\_P](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tom_p/32/766520_2.png) [@Tom\_P](https://discourse.mcneel.com/u/Tom_P)\
**Post date:** [October 3, 2022, 8:00am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/5 "2022-10-03T08:00:18Z")

</div>

![Screenshot 2022-10-03 at 09.54.40](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/d/4/5d41483dcf444426eadd556fc5785736beb9778d.png)

ok it s a 3d-problem.

- sorry - i do not have a script that does this / nor something that is fast to modify to suit your needs.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 3, 2022, 9:26pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/6 "2022-10-03T21:26:47Z")

</div>

@ins_me

You can try the following script - it might work if all the pieces you do are similar to the image/file you posted above.

For it to work successfully, the following conditions must be met:

- The bottom surface must be planar and parallel to the world XY plane
- All sides of the bottom surface must be linear
- The extrusion direction should be vertical
- The ends (shown in red below) _ **must** _ be the smallest segments, that is how the script determines how to process the object
- The “inside” and “outside” (after the ends are removed) _ **must** _ have the same number of linear segments.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/5/e/e5eed7b6bdb1438406b1c0fd621b08d1374e8414.jpeg)

Maybe it will work for some of your objects… 🤔  
[CornerSplitterSpecial.py](https://discourse.mcneel.com/uploads/short-url/7wKs5jiWfbNqbGMxP9R50elg8Rf.py) (4.1 KB)  
It has a lot of “abort” points, so if you see “Unable to process this object” at the command line, one of the conditions for the script to work has not been met.

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 4, 2022, 2:33pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/7 "2022-10-04T14:33:20Z")

</div>

> [@Helvetosaur](#):
>
> You can try the following script - it might work if all the pieces you do are similar to the image/file you posted above.
> 
> For it to work successfully, the following conditions must be met:
> 
> - The bottom surface must be planar and parallel to the world XY plane
> - All sides of the bottom surface must be linear
> - The extrusion direction should be vertical
> - The ends (shown in red below) _ **must** _ be the smallest segments, that is how the script determines how to process the object
> - The “inside” and “outside” (after the ends are removed) _ **must** _ have the same number of linear segments.

Thank @Helvetosaur .I have a question, if there is more outer loop. I see in you script with such a method

```
   else:
        #need to find outer loop
        loops=Rhino.Geometry.Curve.JoinCurves(loops,tol)
        outer=FindOuterLoop(loops,plane,tol)
    return outer

```

[SUBJECT.3dm](https://discourse.mcneel.com/uploads/short-url/wZPDh6nGRp8rFkK9ilmYMwLYSJh.3dm) (440.4 KB)

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 4, 2022, 4:02pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/8 "2022-10-04T16:02:28Z")

</div>

> [@ins\_me](#):
>
> I have a question, if there is more outer loop.

The script is simply not set up for that. In any case the object should never have more than one outer loop, that represents the outer border of the object.

> [@Helvetosaur](#):
>
> The bottom surface must be planar and parallel to the world XY plane

It is not currently designed to detect anything but the lowest surface in an object and if that surface is parallel to the XY plane. This is one of my stock functions for finding the outlines of object “bottoms” that are supposed to be flat - in this case your example #2 isn’t.

The footprint detector could probably be re-written to use the outer object boundary, however, doing so might introduce other problems.

_ **Edit:** _

You can try the following and see if it works on more of your objects. I can’t say if it will cause other problems, I haven’t tested all possible scenarios…

[CornerSplitterSpecial2.py](https://discourse.mcneel.com/uploads/short-url/hzC0y7psbrHn0JITU2H7YUoIkcK.py) (4.1 KB)

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 5, 2022, 1:19am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/9 "2022-10-05T01:19:24Z")

</div>

Thank @Helvetosaur . The last question, Please help.  
If the object forms a closed loop, for example a rectangle, is the script applicable? In this last case, what would the method look like?  
[SUBJECT.3dm](https://discourse.mcneel.com/uploads/short-url/7sT44AjKABSeZyBsawgiSAetQxn.3dm) (333.2 KB)

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 5, 2022, 7:31am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/10 "2022-10-05T07:31:54Z")

</div>

Well, the current algorithm is based on finding two short “ends” of a single closed loop outline and removing them, then trying to match the corners of the two resulting open polylines to create the cutting planes.

I imagine that it could be modified so that if it finds _two closed loops_, one inside the other, and that the corners can be matched, that this type of figure could be accommodated. I will look into it, I haven’t much time today though.

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 5, 2022, 8:09am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/11 "2022-10-05T08:09:38Z")

</div>

I am very much looking forward to it. Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 5, 2022, 4:47pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/12 "2022-10-05T16:47:51Z")

</div>

So this turned out to be quite a bit more difficult than i thought. Try the following out and see if it works for you.

[CornerSplitterSpecial4.py](https://discourse.mcneel.com/uploads/short-url/aEkkZ7bY5aKdGrwDi6mVPme28JX.py) (6.9 KB)

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 6, 2022, 4:37am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/13 "2022-10-06T04:37:38Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 8, 2022, 1:24am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/14 "2022-10-08T01:24:08Z")

</div>

[SUBJECT.3dm](https://discourse.mcneel.com/uploads/short-url/rw44Nhq1lOCMnLZYaxsHNNX9d5p.3dm) (445.3 KB)  
Hi @Helvetosaur. Objects with curved surfaces cannot be executed by the script. Can you help me take a look?

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 8, 2022, 8:17am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/15 "2022-10-08T08:17:01Z")

</div>

Yes, that’s to be expected. The script is designed to work only with outlines that can be resolved into polylines - i.e. all straight sides. Anything curved will be rejected. There might be a possibility to accept some structures that have curved sides, but it would require a fairly good sized re-write of the outline detection algorithm. I can look into it when I have some time.

Remember, there is no AI at work here trying to figure out what type of piece this is and adapt to that, simply a brute force approach based on finding certain specific criteria and is thus quite limited in its scope of application.

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 8, 2022, 12:20pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/16 "2022-10-08T12:20:19Z")

</div>

Yes I know that, I hope to get help from you.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 10, 2022, 1:47pm UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/17 "2022-10-10T13:47:47Z")

</div>

Here is another version to try. The outline extraction method was re-written to use curves and not polylines, so it will handle some classes of objects with curved outlines. There is also now a command line option to split at G0 (only sharp kinks), G1 (Tangent joints or sharp kinks) or G2 (all sub curve joints including curvature continuous) found.

There will still be many cases where it will fail of course.

[CornerSplitterSpecial5.py](https://discourse.mcneel.com/uploads/short-url/cnv9oNgoioSL4LWnzzHGIyLswdf.py) (9.4 KB)

Oh, and I forgot, here is a ‘manual’ surface/polysurface splitter where you draw lines to indicate where you want it to split. This can help where the other semi-automatic methods fail.  
[SplitBrepsWLines.py](https://discourse.mcneel.com/uploads/short-url/dbgBovgmxH0Z5MVoowuThGTmLYR.py) (5.9 KB)

---

<div class="post-metadata">

**Author:** ![ins\_me](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ins_me/32/406845_2.png) [@ins\_me](https://discourse.mcneel.com/u/ins_me)\
**Post date:** [October 11, 2022, 1:23am UTC](https://discourse.mcneel.com/t/help-split-polysurface-at-their-corner/148540/18 "2022-10-11T01:23:46Z")

</div>

Thanks for your help. It helps me a lot
