Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
Kent1Cooper
Posts: 5,409
Registered: ‎09-13-2004
Message 11 of 17 (1,051 Views)

Re: Silent Pedit

06-04-2011 07:10 PM in reply to: hmsilva

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:smileytongue:EJA (/ 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.

Kent Cooper
Active Member
beaufordt
Posts: 9
Registered: ‎03-25-2009
Message 12 of 17 (1,035 Views)

Re: Silent Pedit

06-06-2011 10:50 AM in reply to: Kent1Cooper

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.

 

64bit AutoCAD Map & Civil 3D 2013 Infrastructure Design Suite 2014
Windows 7 Dell Xeon 3.2 Ghz 12GB Novell network
Valued Mentor
Ktelang
Posts: 287
Registered: ‎09-23-2010
Message 13 of 17 (1,018 Views)

Re: Silent Pedit

06-07-2011 01:48 PM in reply to: beaufordt
Thanks for that perfect
------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
Mentor
greg.battin
Posts: 153
Registered: ‎12-10-2010
Message 14 of 17 (1,004 Views)

Re: Silent Pedit

06-28-2011 08:35 PM in reply to: Kent1Cooper

Hey Kent,

this routine (EJA) is awesome. I use it almost everyday.

Thank you

~Greg

Mentor
ojuris
Posts: 246
Registered: ‎06-08-2010
Message 15 of 17 (997 Views)

Re: Silent Pedit

06-28-2011 11:53 PM in reply to: beaufordt

This one  (ljoin) from beaufordt  is perfect!

 

THANKS

 

 

Juris

*Expert Elite*
Kent1Cooper
Posts: 5,409
Registered: ‎09-13-2004
Message 16 of 17 (988 Views)

Re: Silent Pedit

06-29-2011 06:24 AM in reply to: beaufordt

beaufordt 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:smileytongue:ljoin by beaufordt from AutoCAD Customization Discussion Group
;; Streamlined by Kent Cooper, June 2011
(defun C:smileytongue:J (/ 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

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,409
Registered: ‎09-13-2004
Message 17 of 17 (841 Views)

Re: Silent Pedit

07-16-2012 08:09 AM in reply to: Kent1Cooper

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:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Lines-to-pline-in-one-step/m-p/353442...

where the same subject came up again.

Kent Cooper
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.