Hello Mr Silva,
Can you please share the code.
I will be performing similar 1000s of
pedits. I think your last post talks about exactly what
I want.
If I am not asking too much and if its fine with
you I will appreciate your help related to same
Thanks
hmsilva wrote:
....My code is an automatic Pedit, by selecting one; line, arc or poly, it scans the endpoints and perform a pedit until there is no more elements to join...
....
That description sounds like a lot more work than necessary. Just do this:
(defun C:PEJA (/ peac cmde); = Polyline Edit: Join All
(setq peac (getvar 'peditaccept))
(setvar 'peditaccept 1)
(setq cmde (getvar 'cmdecho))
(setvar 'cmdecho 0)
(command "_.pedit" pause "_join" "_all" "" "")
(setvar 'peditaccept peac)
(setvar 'cmdecho cmde)
(princ)
)
Yes, in the object selection it will find everything in the current space, but it will ignore anything that doesn't connect end-to-end with the selected object, and anything of the wrong object type, and join everything it can. No scanning of endpoints is needed.
For me back in AutoCAD 2004, setting CMDECHO to 0 does suppress echoing to the Command: line [otherwise I wouldn't have included it here], so the problem in the original post doesn't exist. But even if that's changed in newer versions, the Join All approach means there isn't very much echoed there, anyway [certainly nothing like what would be in the approach quoted above], no matter how many things are joined.
It could be made more sophisticated, such as by restricting object selection to only Peditable types, if desired.
Simular, but if you select more than one line this one will just join the selected segments:
(defun c:pljoin (/ cmdecho peditaccept ss ss1 lent) (setq cmdecho (getvar "cmdecho") peditaccept (getvar "peditaccept") lent (entlast) ) (setvar "cmdecho" 0) (setvar "peditaccept" 1) (princ "\nSelect object to join: ") (setq ss (ssget '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE")))) (if (/= ss nil) (progn (if (= (sslength ss) 1) (progn (sssetfirst nil ss) (command "_.pedit" "_J" (ssget "X" '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE"))) "" "") ) (command "_.pedit" "_M" ss "" "_J" "0.0" "") ) ) ) (setvar "cmdecho" cmdecho) (setvar "peditaccept" peditaccept) (princ) )
I have it in my Edit Shortcut menu. I used to use the Macro: ^C^C^P(ssget);pedit;m;p;;j;0.0;;
I wrote the code because I'll often join a few lines and didn't want to have any extra joined in.
@TomBeauford wrote:....
(defun c:pljoin (/ cmdecho peditaccept ss ss1 lent) (setq cmdecho (getvar "cmdecho") peditaccept (getvar "peditaccept") lent (entlast) ) (setvar "cmdecho" 0) (setvar "peditaccept" 1) (princ "\nSelect object to join: ") (setq ss (ssget '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE")))) (if (/= ss nil) (progn (if (= (sslength ss) 1) (progn (sssetfirst nil ss) (command "_.pedit" "_J" (ssget "X" '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE"))) "" "") ) (command "_.pedit" "_M" ss "" "_J" "0.0" "") ) ) ) (setvar "cmdecho" cmdecho) (setvar "peditaccept" peditaccept) (princ) )....
I like the automatic handling of multiple joins if multiple things are selected, but join-everything-possible if only one is. For my own use, I made a streamlined version [removed unused lent variable and took unused ss1 out of local variables list, removed two unnecessary (progn)'s & an (sssetfirst), simplified (ssget) filtering and join-all-possible object selection, made prompt more descriptive, shortened command name and some variable names, consolidated (setq)'s, repositioned (setvar)'s to eliminate need for error handling to reset if cancelled in selection].
;; PolylineJoin.lsp [command name: PJ]
;; Based on c:pljoin by beaufordt from AutoCAD Customization Discussion Group
;; Streamlined by Kent Cooper, June 2011
(defun C:PJ (/ cmde peac ss); = Polyline Join
(princ "\nTo join touching objects into Polyline(s) [pick 1 to join all possible objects to it],")
(setq
ss (ssget '((0 . "LINE,ARC,*POLYLINE")))
cmde (getvar 'cmdecho)
peac (getvar 'peditaccept)
); end setq
(setvar 'cmdecho 0)
(setvar 'peditaccept 1)
(if ss
(if (= (sslength ss) 1)
(command "_.pedit" ss "_join" "_all" "" ""); then
(command "_.pedit" "_multiple" ss "" "_join" "0.0" ""); else
); end inner if
); end outer if
(setvar 'cmdecho cmde)
(setvar 'peditaccept peac)
(princ)
); end defun
An update of the PolylineJoin.lsp routine [PJ command], with added error handling, rejection of selection 3D Polylines [which can't be joined] and 2D "heavy" Polylines that are spline- or fit-curved [because joining them to other things removes their curvature], preservation of selected Lines/Arcs that don't have contiguous objects to join to as Lines/Arcs rather than single-segment Polylines, and a few other small refinements.
Also posted on this later thread:
where the same subject came up again.
The polylinejoin.lsp doesn't seem to work on ACAD2002. This is the error message I receive:
Error: AutoCAD variable setting rejected: PEDITACCEPT 1; error: An error has
occurred inside the *error* functionAutoCAD variable setting rejected:
PEDITACCEPT nil
I know I'm using an ancient release of ACAD, but is there a way to make this work??
@danielrT8PHL wrote:
The polylinejoin.lsp doesn't seem to work on ACAD2002. ….
Does the PEDITACCEPT variable exist at all in 2002? If not, does it work as if in later versions it was set to 1? That is, in PEDIT, if you select a Line or Arc that isn't already a Polyline, does it just go ahead without challenging you? If that's the case, the routine could be "fixed" to remove all references to it, i.e. remove these lines:
(setvar 'peditaccept peac) ;; in two places
peac (getvar 'peditaccept)
(setvar 'peditaccept 1)
and take 'peac' out of the localized variables list at the top.
What do you want to do?
Maybe my VEDIT routine would be helpful.
John F. Uhden