Author Topic: Break polyline at points  (Read 6539 times)

0 Members and 1 Guest are viewing this topic.

rkmcswain

  • Swamp Rat
  • Posts: 978
Break polyline at points
« on: November 09, 2007, 08:09:42 AM »
I'll admit, I haven't given this a lot of thought - but before I do, I thought I would run it by you experts and maybe save some time....

Given an LWPOLYLINE and a list of points that fall on this polyline, I need to be able to break the original polyline into smaller segments defined by the points in the polyline. The points may be anywhere on the original polyline, not just at the vertices. The purpose of the breaks is to be able to assign different linetypes to each section.

If you were doing this manually, you could just literally break the polyline at each point. But I need to do this in VBA and there may be hundreds of points along this polyline.

See attached image also.

TIA

SomeCallMeDave

  • Guest
Re: Break polyline at points
« Reply #1 on: November 09, 2007, 08:49:48 AM »
Does it have to be VBA?  It can be done in LISP without a whole lot of trouble.

But I don't think VBA has a Break Method, but (hopeably) I will be proved wrong.

If LISP is an option, you can try something like this (but will need error checking, testing, etc)

Code: [Select]

(defun c:breakatPt()
    (setq pline1 (car (entsel "\nPick Polyline:"))
          ssPoints (ssget '((0 . "POINT")))
          count 0 
          PtList (list)
     );setq
     ;get list of points
     (repeat (sslength ssPoints)
         (setq PtList (append PtList (list (cdr (assoc 10 (entget (ssname sspoints count))))))
               count (+ count 1)
         )
     );repeat
     (setq count 0
           DistList (list)
     );setq

    ;; sort the points so we won't try to break the NEW pline that is created after a successful break
     (repeat (length PtList)
        (setq DistList (append DistList (list (vlax-curve-GetDistAtPoint Pline1 (vlax-curve-getClosestPointTo Pline1 (nth count PtList))))))
         (setq count (+ 1 count)) 
     );repeat
    (setq DistListSortI (vl-sort-i DistList '>)
           count 0
    );setq     
 
     (repeat (sslength sspoints)
          (setq breakPt (nth (nth count DistListSortI ) PtList))
          (command "break" pline1  breakpt "@")
          (setq count (+ 1 count))
     
     );repeat
     (prin1)


)


Bryco

  • Water Moccasin
  • Posts: 1882
Re: Break polyline at points
« Reply #2 on: November 09, 2007, 09:57:33 AM »
It's definately more code than Dave has shown.
You also have to reconfigure every bulge as the bulge is a measure of the included angle.
Quite doable however.

LE

  • Guest
Re: Break polyline at points
« Reply #3 on: November 09, 2007, 01:28:03 PM »
No idea if it is available the method: getSplitCurves(); - from ObjectARX in VBA.

That way, you can pass the points or parameters to the getSplitCurves() function, and it provides an array of pointers for the new segments, to simple added to the database.

SomeCallMeDave

  • Guest
Re: Break polyline at points
« Reply #4 on: November 09, 2007, 02:01:15 PM »
I wrote a similar one in LISP that will talke a start and an end Parameter and a given polyline and the function will recreate a new pline from those params.

but it must be about 1000 lines (including supporting functions).  Like Bryco said,  calcing the sub-arcs and bulges can be a pain.   It was easier in LISP since I could use the VLAX-curve functinos.

sinc

  • Guest
Re: Break polyline at points
« Reply #5 on: November 09, 2007, 06:54:49 PM »
It's definately more code than Dave has shown.
You also have to reconfigure every bulge as the bulge is a measure of the included angle.

Why do you need more code than Dave posted?  What do you mean by reconfigure every bulge?  Doesn't the Break command already take care of that?

Dave's code seems fine to me, assuming the user wants to use Autocad Point objects to indicate the breaks.  Except it needs Undo grouping, so that the entire BreakAtPt operation can be undone at once, rather than one break at a time...  And of course, you would get an awful lot of text echoed to the command line if you select a lot of break points.  But it seems effective to me.

SomeCallMeDave

  • Guest
Re: Break polyline at points
« Reply #6 on: November 09, 2007, 07:36:07 PM »
I think he meant more code would be needed if one was to code it in VBA  and try to recreate the pline segments.

 If any break point was on an arc seg, the bulge would change since the included angle changed.  And the bulge of the new arc seg would have to be calced too.