Script to clean up polylines with overlapping vertices and line segments

Script to clean up polylines with overlapping vertices and line segments

JBW_AIScripts
Contributor Contributor
662 Views
5 Replies
Message 1 of 6

Script to clean up polylines with overlapping vertices and line segments

JBW_AIScripts
Contributor
Contributor

I have a process in which I clean up polyline shapes by exploding them, running Overkill, joining them again, running Overkill again, and then checking that the shapes are closed.

 

Often I will find that the original shapes have been rejoined in open segments because end points are not perfectly on top of each other. When that happens I have to painstakingly check every segment end by zooming in on it and attach it to the next closest point before joining it all again.

JBW_AIScripts_1-1739909816859.pngJBW_AIScripts_2-1739909857619.png

 

I've attached the beginnings of my code, which is essentially trying to automate what I just described.

 

The goal is to wind up with a set of closed polyline shapes with no overlapping line segments or overlapping vertices, without noticeably changing the original shape.

 

Currently I'm unsure if Overkill is running for the whole selection. I am certain that Join is only working for one object in the selection set, and that needs to be fixed. I am aware of PEDIT but I have not gotten that to work either.

0 Likes
663 Views
5 Replies
Replies (5)
Message 2 of 6

pendean
Community Legend
Community Legend

@JBW_AIScripts So AutoCAD is not the best tool is you are trying to create a large-scale sign from a raster conversion for a laser cutter for example: there are way better software packages. Is that your intent?

Or are you just trying to convert a logo to autocad entities to use in your titleblocks (in which case those little tiny imperfections will never get noticed)?

 

IDEA: consider use BOUNDARY command to create new outlines from your conversion then just grab free LISP out there to reduce the number of vertices etc. if a Spline Conversion is not enough.

 

pendean_0-1739913624039.png

 

 

0 Likes
Message 3 of 6

JBW_AIScripts
Contributor
Contributor

Regardless of if it's the best software for the job, I'm trying to use AUTOCAD to do this. I'll look into the BOUNDARY command.

0 Likes
Message 4 of 6

cadffm
Consultant
Consultant

Hi,

 

>>"I have a process"

I would run overkill first (and force the right settings in your lisp, otherwise it is depending on your current settings)

 

Ever tried "more professional" tools to clean up plines? (explode/overkill/join is not bad, but you skip the

I like the idea to do it on your own, I gone the same way, but did you, or not? Out there are some Tools for it.

 

 

>>"(setq sel (ssget "_CP" bbx))"

Why are you using CP bbx? I think maybe you are doing this for a specific reason?
If not, see my sample below

 

 

>> (command "_join" sel) ;; Or PEDIT, whichever works better

>> I am certain that Join is only working for one object in the selection set, and that needs to be fixed. 

(initcommandversion)(command "_.JOIN" sel "")

 

 

>>"The goal is to wind up with a set of closed polyline shapes with no overlapping line segments or overlapping vertices, without noticeably changing the original shape."

Is it possible that your sample .DWG wasn't the best choice? I can't see bigger mistakes.

It's near to the optimum, just one vertic per pline is more than needed.

See Attachment

 

>>"because end points are not perfectly on top of each other."

Why? I can't see the issue in your sample. dwg

and if it was a closed polyline (before explode..) there is no gap.

Your screenshot is clear, but it doesn't match to the .dwg!?

 
 

 

 

Sebastian

0 Likes
Message 5 of 6

pendean
Community Legend
Community Legend

@JBW_AIScripts wrote:

...I'm trying to use AUTOCAD to do this...


Do what please, are you are trying to create a clean pristine outline for a laser cutter?

Or just a logo conversion for titleblocks for example?

0 Likes
Message 6 of 6

JBW_AIScripts
Contributor
Contributor

I have another script that uses the shapes as selection windows that fails if there are overlapping lines or vertices. For all intents and purposes, I need to get a "laser cutter" clean outline.

0 Likes