Slicing a polyline

Slicing a polyline

ysezgul
Participant Participant
2,735 Views
14 Replies
Message 1 of 15

Slicing a polyline

ysezgul
Participant
Participant

Hi,

 

I need a code to slice a closed polyline which slices by clicking points and creates two ore more closed polylines.  Anyone help me?

 

Yusuf

0 Likes
2,736 Views
14 Replies
Replies (14)
Message 2 of 15

devitg
Advisor
Advisor

Show us your sample .dwg, and state the 2 points

0 Likes
Message 3 of 15

john.uhden
Mentor
Mentor

Maybe this will do what you want:

(defun C:BreakAt ( / *error* cmdecho E Obj P)
;; Created (12-05-06) by John Uhden
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  (defun *error* (error)
    (if (= (type cmdecho) 'INT)(setvar "cmdecho" cmdecho))
    (sssetfirst)
    (vla-endundomark *doc*)
    (cond
      ((not error))
      ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
      (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
  )
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (setq cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "_.expert" (getvar "expert")) ;; dummy command
  (and
    (setq E (car (entsel "\nPick object to break: ")))
    (sssetfirst nil (ssadd E))
    (setq Obj (vlax-ename->vla-object E))
    (or
      (vlax-method-applicable-p Obj 'Offset)
      (prompt "\nCan not break this object")
    )
    (setq P (getpoint "\nSelect break point: "))
    (setq P (vlax-curve-getclosestpointto Obj P))
    (command "_.break" E P "@")
  )
  (*error* nil)
)
(defun c:BA ()(C:BreakAt))

John F. Uhden

Message 4 of 15

Kent1Cooper
Consultant
Consultant

@ysezgul wrote:

... slice a closed polyline ... by clicking points and creates two ore more closed polylines.  ....


 

That's pretty wide open....  The "two or more" is especially scary -- potentially this kind of thing?
SlicePline.PNG

That would result in four  of them, involving six  BREAKings of the original Polyline.

 

Clicking points on  the original Polyline, or just any points that define the axis to split it along?

 

One of the difficulties is that it would almost certainly involve single-point BREAK-ing the original Polyline.  When you do that to a closed one, the result is not  one Polyline that goes around from the Breaking point and back to there, but two  of them, one from the original's start to there, and the other from there to the original's end.  So even with a simple shape that only needs to make two resulting ones, it's not as simple as single-point Breaking it in two places and closing the [it would be nice if it were two] resulting Polylines, because there would be three  resulting Polylines.  So such a routine would need to figure out somehow which two Polylines to join before closing.  It gets much more complicated as the number of intersections of the axis with the original Polyline increases.

 

I suggest you do it manually, by drawing an Xline across your two points, and using BOUNDARY or BPOLY to make the resulting Polylines.  In the very simplest of circumstances, it might be possible to automate that, but it's hard to imagine a way if anything like the image above is possible.

Kent Cooper, AIA
0 Likes
Message 5 of 15

john.uhden
Mentor
Mentor

My apologies.  I missed the request to create closed polylines.

The easiest answer is to agree with @Kent1Cooper.  Draw a line or polyline or xline or whatever across where you want to split the existing polyline and then use the BOUNDARY (aka BPOLY) command to create the new ones.

We do this all the time at work.  It's simple and fast.  Believe me, if it were at all tedious I would have written a routine years ago.

John F. Uhden

0 Likes
Message 6 of 15

phanaem
Collaborator
Collaborator

Replay removed... 🙂 I just saw how old this is



 

0 Likes
Message 7 of 15

ВeekeeCZ
Consultant
Consultant

@john.uhden wrote:

...

The easiest answer is to agree with @Kent1Cooper.  Draw a line or polyline or xline or whatever across where you want to split the existing polyline and then use the BOUNDARY (aka BPOLY) command to create the new ones.

We do this all the time at work.  It's simple and fast.  Believe me, if it were at all tedious I would have written a routine years ago.


 

Disagree!! Sorry, but who you are to tell what's tedious and what's not! If you have to do a job dozens or hundreds times and each requires about 3-5 clicks more that it could be, layer handling... Yes, I would write a routine for myself (and I did, but just self-adjusted solution). 

 

But I agree that its very complex issue... and civil drawings are often to complex and never without errors in geometry, more unpredictable.

And about the BOUNDARY command: It would be really nice, but... since this requires picking an inner point... My head says no, rather not. This still !! so often leads to crash (on complex civil drawing). You never know if that is really closed, without errors in geometry, doesn't have too many vertices...

There should be better native autocad commands for this.

 

0 Likes
Message 8 of 15

john.uhden
Mentor
Mentor

What?  You disagree that I would have written a routine? Man Wink

John F. Uhden

0 Likes
Message 9 of 15

ВeekeeCZ
Consultant
Consultant

Since the topic is quite old and I don't really find "slicing polyline by 2 points" useful, I don't really care. 😕

 

0 Likes
Message 10 of 15

SEANT61
Advisor
Advisor

Apparently this is a resurrection of a rather old thread.  That's okay - I'm posting a reply referencing an even older thread.  

 

Another option to approach this task would be  a quick foray into the Autodesk Solid Modeler realm.  That may require the use of Visual Lisp and/or ActiveX, but it does offer a programmer the functionality of Solids and Regions.  Those entities have functionality that keeps track of the various lumps for you.

 

See the VBA example here:

https://forums.autodesk.com/t5/visual-basic-customization/divide-a-region-into-several-regions/m-p/1...

 


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 11 of 15

SEANT61
Advisor
Advisor

Screencast that should have been attached to the previous message.

 

 


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 12 of 15

john.uhden
Mentor
Mentor
Since I am quite old, I don't really care that you don't really care. :-]

John F. Uhden

0 Likes
Message 13 of 15

tamas.antal
Contributor
Contributor

Hi Everyone!

 

I've just found this thread when I was looking for an LSP for slicing closed geometry polyline geometry to separate closed geometry parts.

 

I was not aware that boundary command exists in autocad and I realized I could save tons of hours of time during my work with this.  

Is it possible, to use this boundary command with an extension with offsetting and closing the contour along the cutting geometry? 

Offset distance would be prompted as X,  the outer contours would be extended till it reaches the extended offset line. 

slicing with offset along cutting line.jpg

Is this possible to create an LSP for this? It would be a lot of help for people who are working with laminates (including me)

Geometry could be line/arc polyline, the extensions are mostly lines only. 

Is it possible to use grouped lines ( net) as cutting pattern? 

Is it possible to slice more than 4pcs, I guess yes.

Is it possible to create multpiple cuts with multiple grouped geometry? 

 slicing multiple groups.JPG

Thank you very much for your time! 

 

 

0 Likes
Message 14 of 15

Sea-Haven
Mentor
Mentor

Like John the bpoly command will be your friend, just pick inside a closed shape and a pline will be created. Yes can be automated to repeat and say move the resulting new pline.

SeaHaven_0-1697244498970.pngSeaHaven_1-1697244592870.png

 

Message 15 of 15

john.uhden
Mentor
Mentor

@Sea-Haven and @ysezgul ,

Please be aware that you should LAYISO or Erase and then later OOPS any other things that the BPOLY (BOUNDARY) command may pick up if you just pick points rather than creating a boundary set, the latter of which is recommended.

John F. Uhden

0 Likes