@Anonymous wrote:
.... I got the iterative code from Leemac.com and added the "pedit" code. The problem is that it crashes on the 3rd iteration every time ....
By "crashes," do you mean AutoCAD crashes, or the routine fails? Is there any error message? And by "iteration," do you mean the third try at PEDITing within the routine, or the third time you run the routine?
My first guess is that by the time it gets to some later object in the selection, that entity name no longer exists, because it's already been joined to an earlier one. That wouldn't always be the third iteration, of course.
Try using the Multiple option in PEDIT to avoid the above issue, and to eliminate the need for iteration through the selection entirely:
(defun c:cplm ()
(if (setq s (ssget '((0 . "LINE,ARC,LWPOLYLINE"))))
(command "pedit" "m" s "" "y" "j" "" "")
)
)
That will also allow a fuzz factor [in place of the first "" after the "j"] if some things may not meet exactly but you want to join them anyway.
In later versions than the one I have where I am now, I think you can add some entity types that are also PEDITable [Spline? Ellipse?].
[By the way, whether in your original or the above, if you set the PEDITACCEPT System Variable to 1, you can omit the "y" answer to the question of whether to convert a selected Line/Arc into a Polyline. That will allow you to include not just Lines and Arcs, but also Polylines in the selection, without resulting in a different string of appropriate answers to prompts.]
Kent Cooper, AIA