Autolisp: Polyline Outline of Objects

Here is another polyline routine that only works with closed objects (closed polylines, circles, ellipses…). This time however, you can select all of your objects at once and the combined outline of all of the shapes will be turned into a polyline.

Here’s how:

  • PLOUTLINE <enter> to start
  • Select all of the closed objects that overlap each other to make the outline <enter>

~enjoy

Link to original post at www.autocadtips.wordpress.com

;Shusei Hayashi
;OffshoreCad&Management Inc.
;10F Jaka Bldg., 6780 Ayala Ave.,
;Makati, Philippines
;http://www.offshorecad.com.ph/
;http://www.offshore-management.com.ph/
(defun c:PLOUTLINE (/ MadeObjL ObjNameL ObjSet LastOb)
(princ "\n OUTLINE POLYLINES")
(princ "\n **********************************")
(setq *error* *myerror*)
(SD1028)
(setvar "CMDECHO" 0)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget '((-4 . "<OR")
(0 . "LWPOLYLINE")
(0 . "ELLIPSE")
(0 . "CIRCLE")
(0 . "POLYLINE")
(0 . "LINE")
(0 . "ARC")
(-4 . "OR>")
)
)
)
)
(setq i -1
ObjNameL nil
)
(repeat (setq m (sslength ObjSet))
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(Procedure_1706) ;Region
(Procedure_1706_2) ;Union
(SD2056)
(setq *error* nil)
(princ)
)
;*********;Region
(defun Procedure_1706 (/)
(setq LastOb (entlast))
(command ".region")
(mapcar 'command ObjNameL)
(command "")
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
MadeObjL
)
;*********;Union
(defun Procedure_1706_2 (/)
(mapcar '(lambda (x) (print (SD3511 0 x))) MadeObjL)
(command ".union")
(mapcar 'command MadeObjL)
(command "")
(setq LastOb (entlast)
MadeObjL nil
)
(command ".EXPLODE" LastOb)
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
(command ".PEDIT" "M")
(mapcar 'command MadeObjL)
(command "" "Y" "J" "0.000" "")
)
(defun SD1028 ()
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "undo" "be")
(setq OldOsmode (getvar "OSMODE"))
(setq OldLayer (getvar "CLAYER"))
(setq OldLType (getvar "CeLType"))
(setq OldCeLWeight (getvar "CeLWeight"))
(setq OldColor (getvar "CeColor"))
(setq OldOrtho (getvar "ORTHOMODE"))
(setq OldDStyle (getvar "DIMSTYLE"))
(setq OldExpert (getvar "Expert"))
(setvar "EXPERT" 0)
(princ)
)
;********************************
(defun SD2056 ()
(setvar "OSMODE" OldOsmode)
(command "undo" "end")
(setvar "CLAYER" OldLayer)
(setvar "CeLType" OldLType)
(setvar "CeLWeight" OldCeLWeight)
(setvar "CeColor" OldColor)
(setvar "ORTHOMODE" OldOrtho)
(setvar "Expert" OldExpert)
(if (and (/= (getvar "DIMSTYLE") OldDStyle)
(tblsearch "DIMSTYLE" OldDStyle)
)
(command "-dimstyle" "Restore" OldDStyle)
)
(princ "\n (C)OffshoreCad&Management")
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;**********************
(defun SD3511 (g e)
(cond
((= (type e) 'ename) (cdr (assoc g (entget e))))
((= (type e) 'list) (cdr (assoc g e)))
)
)
;********************************
(defun *myerror* (msg)
(setq *error* nil)
(SD2056)
(princ "\n Error Cancelled")
(princ)
)
(princ "\n Command Name: PLOUTLINE \n")
(princ)
Posted in AutoLISP, AutoLISP: Modify, AutoLISP: Polylines | 1 Comment

AUtoLISP: Subract Objects from a Closed Polyline

Link to www.autocadtips.wordpress.com

Here is a nice routine that lets you subtract closed objects (polylines, ellipses, circles…) from a closed polyline. That might sound restrictive but at least it is an option…

TIP: this routine is finicky – when you select the objects that are to be subtracted from the outside of the main polyline (refer to animation below).

Here’s how:

  • PLSUB <enter> (Polyline Subtract)
  • Select the main Polyline that you want the other objects subtracted from <enter>
  • Select the objects that you want subtracted from their outer portion <enter>

(defun c:PLSUB ()
(princ "\n Subtract Polylines")
(princ "\n First selected object must be a Polyline")
(setq *error* *myerror*)
(SD1028)
(princ "\n Select Objects subtract from :")
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget '((-4 . "<OR")
(0 . "LWPOLYLINE")
(0 . "ELLIPSE")
(0 . "CIRCLE")
(0 . "POLYLINE")
(0 . "LINE")
(0 . "ARC")
(-4 . "OR>")
)
)
)
)
(setq i -1
ObjNameL1 nil
)
(repeat (setq m (sslength ObjSet))
(setq ObjNameL1 (cons (ssname ObjSet (setq i (1+ i))) ObjNameL1))
)
(princ "\n Select Objects subtract :")
(setq ObjSet2 nil)
(while (= ObjSet2 nil)
(setq ObjSet2 (ssget '((-4 . "<OR")
(0 . "LWPOLYLINE")
(0 . "ELLIPSE")
(0 . "CIRCLE")
(0 . "POLYLINE")
(0 . "LINE")
(0 . "ARC")
(-4 . "OR>")
)
)
)
)
(setq i -1
ObjNameL2 nil
)
(repeat (setq m (sslength ObjSet2))
(setq ObjNameL2 (cons (ssname ObjSet2 (setq i (1+ i))) ObjNameL2))
)
;region
(setq MadeObjL1 (Procedure_1707 ObjNameL1))
(setq MadeObjL2 (Procedure_1707 ObjNameL2))
(Procedure_1707_2 MadeObjL1 MadeObjL2) ;SUBTRACT
(SD2056)
(setq *error* nil)
(princ)
)
;*********;SUBTRACT
(defun Procedure_1707_2 (MadeObjL1 MadeObjL2 /)
(command ".SUBTRACT")
(mapcar 'command MadeObjL1)
(command "")
(mapcar 'command MadeObjL2)
(command "")
(setq LastOb (entlast)
MadeObjL nil
)
(command ".EXPLODE" LastOb)
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
(command ".PEDIT" "M")
(mapcar 'command MadeObjL)
(command "" "Y" "J" "0.000" "")
)
;*********;Region
(defun Procedure_1707 (ObjL /)
(setq LastOb (entlast))
(command ".region")
(mapcar 'command ObjL)
(command "")
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
MadeObjL
)
;
(defun SD1028 ()
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "undo" "be")
(setq OldOsmode (getvar "OSMODE"))
(setq OldLayer (getvar "CLAYER"))
(setq OldLType (getvar "CeLType"))
(setq OldCeLWeight (getvar "CeLWeight"))
(setq OldColor (getvar "CeColor"))
(setq OldOrtho (getvar "ORTHOMODE"))
(setq OldDStyle (getvar "DIMSTYLE"))
(setq OldExpert (getvar "Expert"))
(setvar "EXPERT" 0)
(princ)
)
;********************************
(defun SD2056 ()
(setvar "OSMODE" OldOsmode)
(command "undo" "end")
(setvar "CLAYER" OldLayer)
(setvar "CeLType" OldLType)
(setvar "CeLWeight" OldCeLWeight)
(setvar "CeColor" OldColor)
(setvar "ORTHOMODE" OldOrtho)
(setvar "Expert" OldExpert)
(if (and (/= (getvar "DIMSTYLE") OldDStyle)
(tblsearch "DIMSTYLE" OldDStyle)
)
(command "-dimstyle" "Restore" OldDStyle)
)
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;********************************
(defun *myerror* (msg)
(setq *error* nil)
(SD2056)
(princ "\n Error Cancelled")
(princ)
)
(princ "\n Command Name: PLSUB to Subtract Polylines\n")
(princ)
Posted in Attributes, AutoLISP: Modify, AutoLISP: Polylines | 3 Comments

AutoLISP: Align Viewports Vertically

Link to http://www.autocadtips.wordpress.com

This routine compliments the previous routine quite nicely. But this time it aligns viewports vertically.

The same tip that I mentioned in the previous tip applies here as well. If you need to cycle through to another viewport, use CTRL + R to cycle through viewports…

Here’s how:

  • VPALV <enter> to start (ViewPort ALign Vertically)
  • Specify the base point that the other viewport will be aligned to
  • Click inside another viewport to activate that viewport
  • Specify a base point in this viewport to be aligned (vertically) with the first base point.

~enjoy

;Shusei Hayashi
;OffshoreCad&Management Inc.
;10F Jaka Bldg., 6780 Ayala Ave.,
;Makati, Philippines
;http://www.offshorecad.com.ph/
;http://www.offshore-management.com.ph/
;Modified by Greg battin and featured @ www.autocadtips.wordpress.com
; modified for english only use and removed registry stuff
(defun c:VPALV ( / Pt1 VP1 VP2 Pt1P ok Pt2 Pt2P Delta DeltaM ObjSet ObjNameL OpSwitch
Delta theAng ViewName)
(setq OpSwitch 2)
(SD_5202)
)
;***************
(defun SD_5202 ( / )
(princ "\n Viewport Alignment Vertically")
(princ "\n **********************************")
(setq *error* *myerror*)
(SD1028)
(OnlyLayout_5003)
(AllLock_5202)
(Procedure_5202)
(AllLock_5202)
(SD2056)
(setq *error* nil)
(princ)
)
;***************
(defun Procedure_5202()
(command "._MSPACE")
(setq Pt1 (getpoint "\n Select Basepoint in any Viewport :"))
(setq VP1 (getvar "CVPORT"))
(setq Pt1P (trans Pt1 1 2))
(setq Pt1P (trans Pt1P 2 3))
; (command "PSPACE")
; (checkcircle Pt1P 0.1 "A21")
; (command "MSPACE")
(setq ok nil)
(while (null ok)
(setq Pt2 (getpoint "\n Select Basepoint in Viewport to be adjusted :"))
(setq Pt2P (trans Pt2 1 2))
(setq Pt2P (trans Pt2P 2 3))
(if (/= (setq VP2 (getvar "CVPORT")) VP1)
(setq ok T)
(princ "\n Pick point in different Viewport.")
)
)
(AllUnLock_5202) ;UnLockŒ
;UnLock
(command "._MSPACE")
(setvar "CVPORT" VP2)
(setq ViewName (ssname (ssget "X" '((0 . "VIEWPORT")(68 . 1))) 0))
(cond ((= OpSwitch 1)
(setq Delta (- (cadr Pt1P)(cadr Pt2P)))
(princ "\n Delta : ")
(princ Delta)
(setq theAng (SD3511 51 ViewName))
(princ "\n theAng : ")
(princ theAng)
(setq Delta (* (/ (SD3511 45 ViewName)(SD3511 41 ViewName)) Delta))
(princ "\n Delta : ")
(princ Delta)
(setq DeltaP (trans (SD8446 (list 0 Delta) '(0 0) (* -1.0 theAng)) 0 1))
(princ "\n DeltaP : ")
(princ DeltaP)
(command "._pan" DeltaP "")
)
((= OpSwitch 2)
(setq Delta (- (car Pt1P)(car Pt2P)))
(setq theAng (SD3511 51 ViewName))
(setq Delta (* (/ (SD3511 45 ViewName)(SD3511 41 ViewName)) Delta))
(setq DeltaP (trans (SD8446 (list Delta 0) '(0 0) (* -1.0 theAng)) 0 1))
(command "._pan" DeltaP "")
)
)
)
;***************
(defun AllLock_5202()
(if (/= (getvar "CVPORT") 1)
(command "._PSPACE")
)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget "X" '((0 . "VIEWPORT"))))
)
;
(setq i -1 ObjNameL nil)
(repeat (sslength ObjSet)
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(foreach item ObjNameL
(if (/= (logand (SD3511 90 item) 16384) 16384)
(command "._VPORTS" "LOCK" "ON" item "")
)
)
)
;***************
(defun AllUnLock_5202()
(if (/= (getvar "CVPORT") 1)
(command "._PSPACE")
)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget "X" '((0 . "VIEWPORT"))))
)
;
(setq i -1 ObjNameL nil)
(repeat (sslength ObjSet)
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(foreach item ObjNameL
(if (= (logand (SD3511 90 item) 16384) 16384)
(command "._VPORTS" "LOCK" "OFF" item "")
)
)
)
;***************
(defun OnlyLayout_5003()
(if (= (getvar "TILEMODE") 1)
(progn
(alert "This command is for Layout Tab")
(vl-exit-with-error "")
)
)
)
;
(defun SD1028 ()
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "undo" "be")
(setq OldOsmode (getvar "OSMODE"))
(setq OldLayer (getvar "CLAYER"))
(setq OldLType (getvar "CeLType"))
(setq OldCeLWeight (getvar "CeLWeight"))
(setq OldColor (getvar "CeColor"))
(setq OldOrtho (getvar "ORTHOMODE"))
(setq OldDStyle (getvar "DIMSTYLE"))
(setq OldExpert (getvar "Expert"))
(setvar "EXPERT" 0)
(princ)
)
;********************************
(defun SD2056 ()
(setvar "OSMODE" OldOsmode)
(command "undo" "end")
(setvar "CLAYER" OldLayer)
(setvar "CeLType" OldLType)
(setvar "CeLWeight" OldCeLWeight)
(setvar "CeColor" OldColor)
(setvar "ORTHOMODE" OldOrtho)
(setvar "Expert" OldExpert)
(if (and (/= (getvar "DIMSTYLE") OldDStyle)(tblsearch "DIMSTYLE" OldDStyle))
(command "-dimstyle" "Restore" OldDStyle)
)
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;**********************
(defun SD3511 (g e)
(cond
((= (type e) 'ename) (cdr (assoc g (entget e))))
((= (type e) 'list) (cdr (assoc g e)))
)
)
;;;---------Rotate----------------------------
(defun SD8446 ( PointA PointB Ang / XA YA XB YB PointC)
(setq XA2(- (car PointA) (car PointB))
YA2(- (cadr PointA) (cadr PointB))
)
(setq PointC (list (- (* XA2 (cos Ang))(* YA2 (sin Ang))) (+ (* XA2 (sin Ang))(* YA2 (cos Ang)))))
(setq PointC (mapcar '+ PointC PointB))
PointC
)
;********************************
(defun *myerror* (msg)
(setq *error* nil)
(SD2056)
(princ "\n Error Cancelled")
(princ)
)
(princ "\n Command Name: VPALV = Vertical Viewport Alignment\n")
(princ)
Posted in AutoLISP, AutoLISP: Modify, Layout, Paper Space, Viewports | Leave a comment

AutoLISP: Align Viewports Horizontally

Link to www.autocadtips.wordpress.com

This routine is a gem. It allows you to easily align a viewport to another viewport by snapping to objects within the viewport. It works with viewports that have the same scale and for viewports with different scales applied to them. One tip that will help is to remember how to cycle through the viewports on a layout tab. To do this you use CTRL + R to cycle through the layouts [shown here].

Here’s how:

  • VPALH <enter> to start (ViewPort ALign Horizontal)
  • Select a base point in the viewport to define where you want the other VP to be aligned to.
  • Click inside another viewport to activate it
  • Select a base point within this viewport to be aligned (horizontally) to the first base point

~enjoy

;Shusei Hayashi
;OffshoreCad&Management Inc.
;10F Jaka Bldg., 6780 Ayala Ave.,
;Makati, Philippines
;http://www.offshorecad.com.ph/
;http://www.offshore-management.com.ph/
;Modified and featured by Greg Battin at www.autocadtips.wordpress.com
; modified for english use only and to remove registry stuff
(defun c:VPALH ( / Pt1 VP1 VP2 Pt1P ok Pt2 Pt2P Delta DeltaM ObjSet ObjNameL OpSwitch
Delta theAng ViewName)
(setq OpSwitch 1)
(SD_5202)
)
;***************
(defun SD_5202 ( / )
(princ "\n Viewport Alignment Horizontally")
(princ "\n **********************************")
(setq *error* *myerror*)
(SD1028)
(OnlyLayout_5003)
(AllLock_5202)
(Procedure_5202)
(AllLock_5202)
(SD2056)
(setq *error* nil)
(princ)
)
;***************
(defun Procedure_5202()
(command "._MSPACE")
(setq Pt1 (getpoint "\n Select Basepoint in any Viewport :"))
(setq VP1 (getvar "CVPORT"))
(setq Pt1P (trans Pt1 1 2))
(setq Pt1P (trans Pt1P 2 3))
; (command "PSPACE")
; (checkcircle Pt1P 0.1 "A21")
; (command "MSPACE")
(setq ok nil)
(while (null ok)
(setq Pt2 (getpoint "\n Select Basepoint in Viewport to be adjusted :"))
(setq Pt2P (trans Pt2 1 2))
(setq Pt2P (trans Pt2P 2 3))
(if (/= (setq VP2 (getvar "CVPORT")) VP1)
(setq ok T)
(princ "\n Pick point in different Viewport.")
)
)
(AllUnLock_5202) ;UnLock
;UnLock
(command "._MSPACE")
(setvar "CVPORT" VP2)
(setq ViewName (ssname (ssget "X" '((0 . "VIEWPORT")(68 . 1))) 0))
(cond ((= OpSwitch 1)
(setq Delta (- (cadr Pt1P)(cadr Pt2P)))
(princ "\n Delta : ")
(princ Delta)
(setq theAng (SD3511 51 ViewName))
(princ "\n theAng : ")
(princ theAng)
(setq Delta (* (/ (SD3511 45 ViewName)(SD3511 41 ViewName)) Delta))
(princ "\n Delta : ")
(princ Delta)
(setq DeltaP (trans (SD8446 (list 0 Delta) '(0 0) (* -1.0 theAng)) 0 1))
(princ "\n DeltaP : ")
(princ DeltaP)
(command "._pan" DeltaP "")
)
((= OpSwitch 2)
(setq Delta (- (car Pt1P)(car Pt2P)))
(setq theAng (SD3511 51 ViewName))
(setq Delta (* (/ (SD3511 45 ViewName)(SD3511 41 ViewName)) Delta))
(setq DeltaP (trans (SD8446 (list Delta 0) '(0 0) (* -1.0 theAng)) 0 1))
(command "._pan" DeltaP "")
)
)
)
;***************
(defun AllLock_5202()
(if (/= (getvar "CVPORT") 1)
(command "._PSPACE")
)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget "X" '((0 . "VIEWPORT"))))
)
(setq i -1 ObjNameL nil)
(repeat (sslength ObjSet)
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(foreach item ObjNameL
(if (/= (logand (SD3511 90 item) 16384) 16384)
(command "._VPORTS" "LOCK" "ON" item "")
)
)
)
;***************
(defun AllUnLock_5202()
(if (/= (getvar "CVPORT") 1)
(command "._PSPACE")
)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget "X" '((0 . "VIEWPORT"))))
)
(setq i -1 ObjNameL nil)
(repeat (sslength ObjSet)
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(foreach item ObjNameL
(if (= (logand (SD3511 90 item) 16384) 16384)
(command "._VPORTS" "LOCK" "OFF" item "")
)
)
)
;***************
(defun OnlyLayout_5003()
(if (= (getvar "TILEMODE") 1)
(progn
(alert "This command is for Paper Space")
(vl-exit-with-error "")
)
)
)
;
(defun SD1028 ()
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "undo" "be")
(setq OldOsmode (getvar "OSMODE"))
(setq OldLayer (getvar "CLAYER"))
(setq OldLType (getvar "CeLType"))
(setq OldCeLWeight (getvar "CeLWeight"))
(setq OldColor (getvar "CeColor"))
(setq OldOrtho (getvar "ORTHOMODE"))
(setq OldDStyle (getvar "DIMSTYLE"))
(setq OldExpert (getvar "Expert"))
(setvar "EXPERT" 0)
(princ)
)
;********************************
(defun SD2056 ()
(setvar "OSMODE" OldOsmode)
(command "undo" "end")
(setvar "CLAYER" OldLayer)
(setvar "CeLType" OldLType)
(setvar "CeLWeight" OldCeLWeight)
(setvar "CeColor" OldColor)
(setvar "ORTHOMODE" OldOrtho)
(setvar "Expert" OldExpert)
(if (and (/= (getvar "DIMSTYLE") OldDStyle)(tblsearch "DIMSTYLE" OldDStyle))
(command "-dimstyle" "Restore" OldDStyle)
)
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;**********************
(defun SD3511 (g e)
(cond
((= (type e) 'ename) (cdr (assoc g (entget e))))
((= (type e) 'list) (cdr (assoc g e)))
)
)
;;;---------Rotate----------------------------
(defun SD8446 ( PointA PointB Ang / XA YA XB YB PointC)
(setq XA2(- (car PointA) (car PointB))
YA2(- (cadr PointA) (cadr PointB))
)
(setq PointC (list (- (* XA2 (cos Ang))(* YA2 (sin Ang))) (+ (* XA2 (sin Ang))(* YA2 (cos Ang)))))
(setq PointC (mapcar '+ PointC PointB))
PointC
)
;********************************
(defun *myerror* (msg)
(setq *error* nil)
(SD2056)
(princ "\n Error Cancelled")
(princ)
)
(princ "\n Command Name: VPALH = Viewport Alignment Horizontal\n")
(princ)
Posted in AutoLISP, Paper Space, Viewports | Leave a comment

AutoLISP: Copy Text to Table Cells

Link to www.autocadtips.wordpress.com

There used to be a web site called ASMITOOLS.com where this particular LISP routine was posted. After the website went down, the author basically dumped all the routines in a forum as he decided to move on and let anyone use these LISP routines.

This routine is a great routine that lets you copy existing text objects (DTEXT, MTEXT & Attributes) to table cells.

Here’s how:

TTC <enter>

Specify whether you want to place text multiple time by choosing “Multiple” or “Pair-wise’ which will let you select a text object and then place it and then select another text object and place that object.

When placing the text objects one tip to help is that the table cell that receives the text object is determined by how much of the pick-box (cursor) is in the cell. You place your cursor over a line in the table and the more of the pick-box that is in a cell will determine which cell the text gets placed in. It’s a little tricky at first but you will get the hang of it…

;; ==================================================================== ;;
;; ;;
;; TTC.LSP - The program copies the text from: DText, MText, ;;
;; Tables, Dimensions, Attributes, Attributes, ;;
;; Attributes Definitions, DText, MText and inner ;;
;; block's DText and MText to: DText, MText, Tables, ;;
;; Attribures and Attributes Definitions. There are ;;
;; Multiple and Pair-wise modes. ;;
;; ;;
;; ==================================================================== ;;
;; ;;
;; Command(s) to call: TTC ;;
;; ;;
;; ==================================================================== ;;
;; ;;
;; THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD ON ANY ;;
;; MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS PROGRAM OR ;;
;; PARTS OF IT ABSOLUTELY FREE. ;;
;; ;;
;; THIS PROGRAM PROVIDES 'AS IS' WITH ALL FAULTS AND SPECIFICALLY ;;
;; DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS ;;
;; FOR A PARTICULAR USE. ;;
;; ;;
;; ==================================================================== ;;
;; ;;
;; V1.3, 29 November, 2005, Riga, Latvia ;;
;; © Aleksandr Smirnov (ASMI) ;;
;; For AutoCAD 2000 - 2008 (isn't tested in a next versions) ;;
;; ;;
;; http://www.asmitools.com ;;
;; ;;
;; ==================================================================== ;;
(defun c:ttc (/ actDoc vlaObj sObj sText curObj oldForm
oType oldMode conFlag errFlag *error*)
(vl-load-com)
(setq actDoc(vla-get-ActiveDocument
(vlax-get-acad-object)))
(vla-StartUndoMark actDoc)
(defun TTC_Paste(pasteStr / nslLst vlaObj hitPt
hitRes Row Column)
(setq errFlag nil)
(if
(setq nslLst(nentsel "\nPaste text >"))
(progn
(cond
((and
(= 4(length nslLst))
(= "DIMENSION"(cdr(assoc 0(entget(car(last nslLst))))))
); end and
(setq vlaObj(vlax-ename->vla-object
(cdr(assoc -1(entget(car(last nslLst)))))))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-TextOverride(list vlaObj pasteStr)))
(progn
(princ "\n<!> Can't paste. Object may be on locked layer <!> ")
(setq errFlag T)
); end progn
); end if
); end condition #1
((and
(= 4(length nslLst))
(= "ACAD_TABLE"(cdr(assoc 0(entget(car(last nslLst))))))
); end and
(setq vlaObj
(vlax-ename->vla-object
(cdr(assoc -1(entget(car(last nslLst))))))
hitPt(vlax-3D-Point(trans(cadr nslLst)1 0))
hitRes(vla-HitTest vlaObj hitPt
(vlax-3D-Point '(0.0 0.0 1.0)) 'Row 'Column)
); end setq
(if(= :vlax-true hitRes)
(progn
(if(vl-catch-all-error-p
(vl-catch-all-apply
'vla-SetText(list vlaObj Row Column pasteStr)))
(progn
(princ "\n<!> Can't paste. Object may be on locked layer <!> ")
(setq errFlag T)
); end progn
); end if
); end progn
); end if
); end condition # 2
((and
(= 4(length nslLst))
(= "INSERT"(cdr(assoc 0(entget(car(last nslLst))))))
); end and
(princ "\n<!> Can't paste to block's DText or MText <!> ")
(setq errFlag T)
); end condition #3
((and
(= 2(length nslLst))
(member(cdr(assoc 0(entget(car nslLst))))
'("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))
); end and
(setq vlaObj(vlax-ename->vla-object(car nslLst)))
(if(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-TextString(list vlaObj pasteStr)))
(progn
(princ "\n<!> Error. Can't pase text <!> ")
(setq errFlag T)
); end progn
); end if
); end condition #4
(T
(princ "\n<!> Can't paste. Invalid object <!> ")
(setq errFlag T)
); end condition #5
); end cond
T
); end progn
nil
); end if
); end of TTC_Paste
(defun TTC_MText_Clear(Mtext / Text Str)
(setq Text "")
(while(/= Mtext "")
(cond
((wcmatch(strcase
(setq Str
(substr Mtext 1 2)))"\\[\\{}`~]")
(setq Mtext(substr Mtext 3)
Text(strcat Text Str)
); end setq
); end condition #1
((wcmatch(substr Mtext 1 1) "[{}]")
(setq Mtext
(substr Mtext 2))
); end condition #2
((and
(wcmatch
(strcase
(substr Mtext 1 2)) "\\P")
(/=(substr Mtext 3 1) " ")
); end and
(setq Mtext (substr Mtext 3)
Text (strcat Text " ")
); end setq
); end condition #3
((wcmatch
(strcase
(substr Mtext 1 2)) "\\[LOP]")
(setq Mtext(substr Mtext 3))
); end condition #4
((wcmatch
(strcase
(substr Mtext 1 2)) "\\[ACFHQTW]")
(setq Mtext
(substr Mtext
(+ 2(vl-string-search ";" Mtext))))
); end condition #5
((wcmatch
(strcase (substr Mtext 1 2)) "\\S")
(setq Str(substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
Text(strcat Text (vl-string-translate "#^\\" " " Str))
Mtext(substr Mtext (+ 4 (strlen Str)))
); end setq
(print Str)
); end condition #6
(T(setq Text(strcat Text(substr Mtext 1 1))
Mtext (substr Mtext 2)
); end setq
); end condition #7
); end cond
); end while
Text
); end of TTC_MText_Clear
(defun TTC_Copy (/ sObj sText tType actDoc)
(if
(and
(setq sObj(car(nentsel "\nCopy text... ")))
(member(setq tType(cdr(assoc 0(entget sObj))))
'("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))
); end and
(progn
(setq actDoc(vla-get-ActiveDocument
(vlax-get-Acad-object))
sText(vla-get-TextString
(vlax-ename->vla-object sObj))
); end setq
(if(= tType "MTEXT")
(setq sText(TTC_MText_Clear sText))
); end if
); end progn
); end if
sText
); end of TTC_Copy
(defun CCT_Str_Echo(paseStr / comStr)
(if(< 20(strlen paseStr))
(setq comStr
(strcat
(substr paseStr 1 17)"..."))
(setq comStr paseStr)
); end if
(princ(strcat "\nText = \"" comStr "\""))
(princ)
); end of CCT_Str_Echo
(defun *error*(msg)
(vla-EndUndoMark
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(princ "\nQuit TTC")
(princ)
); end of *error*
(if(not ttc:Mode)(setq ttc:Mode "Multiple"))
(initget "Multiple Pair-wise")
(setq oldMode ttc:Mode
ttc:Mode(getkword
(strcat "\nSpecify mode [Multiple/Pair-wise] <"ttc:Mode">: "))
conFlag T
paseStr ""
); end setq
(if(null ttc:Mode)(setq ttc:Mode oldMode))
(if(= ttc:Mode "Multiple")
(progn
(if(and(setq paseStr(TTC_Copy))conFlag)
(progn
(CCT_Str_Echo paseStr)
(while(setq conFlag(TTC_Paste paseStr))T
); end while
); end progn
); end if
); end progn
(progn
(while(and conFlag paseStr)
(setq paseStr(TTC_Copy))
(if(and paseStr conFlag)
(progn
(CCT_Str_Echo paseStr)
(setq errFlag T)
(while errFlag
(setq conFlag(TTC_Paste paseStr))
);end while
); end progn
); end if
); end while
); end progn
); end if
(vla-EndUndoMark actDoc)
(princ "\nQuit TTC")
(princ)
); end c:ttc
(princ "\n[Info] http:\\\\www.AsmiTools.com [Info]")
(princ "\n[Info] Type TTC to run text to text copy tool [Info]")
Posted in AutoLISP, AutoLISP: Attributes, AutoLISP: Modify, AutoLISP: Text | 2 Comments

3D UCS Icon Color

Link to AutoCAD Tips

When you are in a 3D Visual Style or even when you are in “2D Wireframe” and your view is something other than in plan, you may notice that your UCS Icon and/or your cursor have 3 colors. One color for each axis. This tip also applies to 3DS Max…

The colors on the UCS Icon and cursor are helpful to understand for easier navigation.

Simply remember this “XYZ relates to RGB” and you’ve got it.

The XYZ axis relates to RGB respectively (RGB = Red, Green, Blue)

Posted in 3D Intro, BASICS | Leave a comment

AutoLISP: X Shape Wall Intersection Clean Up

Link to AutoCAD Tips

This is the last of the wall intersection clean up routines that I have. This one does X-shape (cross shape) intersections.

Command to start:

  • WALL-X <enter>

This routine acts the same as the others
in that it lets you simply make a selection set of the crossing objects first and then specify the outside of the walls (shown below).

You can also simply use the default setting which lets you simply make a selection window over the intersection and the routine will clean up the intersections for you (shown below).

~enjoy
(defun c:wall-x (/ >90 @work dists edata etype fuzzy get getslope head i l0
merge neatx1 nukenz perp perps pt0 pt1 pt2 pt3 pt4 pt5 pt6
slope sort ss ssfunc tail wall1 wall2 walls work
)
(setq clayer nil)
(princ "\nLoading -")
(setq @WORK '("\\" "|" "/" "-"))
(defun WORK ()
; Backspace
(prompt "\010")
(setq @work (append (cdr @work) (list (princ (car @work)))))
)
(work)
(defun NUKENZ (x)
(cdr (reverse (cdr x)))
)
(work)
(defun NEATX1 (dist1 dist2)
(cond
((cdr dist1)
(work)
(neatx2
; 1st wall - line 1
(nth (cadar dist1) wall1)
; 1st wall - line 2
(nth (cadr (last dist1)) wall1)
; 2nd wall - line 1
(nth (cadar dist2) wall2)
; 2nd wall - line 2
(nth (cadr (last dist2)) wall2)
)
(neatx1 (nukenz dist1) (nukenz dist2))
)
(T (princ "\rComplete."))
)
)
(work)
(defun NEATX2 (a1 a2 b1 b2)
(mapcar
'(lambda (x l1 l2)
(work)
(setq
pt1 (cadr l1)
pt2 (caddr l1)
pt3 (cadr l2)
pt4 (caddr l2)
)
(foreach
l0
x
(setq
pt5 (cadr l0)
pt6 (caddr l0)
)
(command
".BREAK" (car l0)
(inters pt5 pt6 pt1 pt2)
(inters pt5 pt6 pt3 pt4)
)
)
)
(list (list a1 a2) (list b1 b2))
(list b1 a1)
(list b2 a2)
)
)
(work)
(defun GET (key alist)
(if (atom key)
(cdr (assoc key alist))
(mapcar '(lambda (x) (cdr (assoc x alist))) key)
)
)
(work)
(defun FUZZY (x y)
(< (abs (- x y)) 1.0e-6)
)
(work)
(defun SORT (x)
(work)
(cond
((null (cdr x)) x)
(T
(merge
(sort (head x (1- (length x))))
(sort (tail x (1- (length x))))
)
)
)
)
(work)
(defun MERGE (a b)
(work)
(cond
((null a) b)
((null b) a)
((< (caar a) (caar b))
(cons (car a) (merge (cdr a) b))
)
(t (cons (car b) (merge a (cdr b))))
)
)
(work)
(defun HEAD (l n)
(cond
((minusp n) nil)
(t (cons (car l) (head (cdr l) (- n 2))))
)
)
(work)
(defun TAIL (l n)
(cond
((minusp n) l)
(t (tail (cdr l) (- n 2)))
)
)
(work)
(defun GETSLOPE (pt1 pt2 / x)
; Vertical?
(if (fuzzy (setq x (abs (- (car pt1) (car pt2)))) 0.0)
; Yes, return NIL
nil
; No, compute slope
(rtos (/ (abs (- (cadr pt1) (cadr pt2))) x) 2 4)
)
)
(work)
(defun ETYPE (edata match)
(member (get 0 edata) (if (listp match) match (list match)))
)
(work)
(defun SSFUNC (ss func / i ename)
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(apply func nil)
)
)
(work)
(defun PERP (pt0 pt1 pt2)
(inters pt1 pt2 pt0 (polar pt0 (+ (angle pt1 pt2) >90) 1.0) nil)
)
;---------------
; Main Function
;---------------
(setq >90 (/ pi 2))
; Stuff Gary will want to fix...
(setvar "CmdEcho" 0)
(setvar "BlipMode" 0)
(princ "\rLoaded. ")
(while
(progn
(initget "Select")
(setq pt0 (getpoint "\nSelect objects/<First corner>: "))
)
(setq
dists nil
perps nil
walls nil
)
(cond
((eq (type pt0) 'LIST)
(initget 33)
(setq
pt1 (getcorner pt0 "\nOther corner: ")
ss (ssget "C" pt0 pt1)
)
)
(T
(while
(progn
(princ "\nSelect objects: ")
(command ".SELECT" "Au" pause)
(not (setq ss (ssget "P")))
)
(print "No objects selected, try again.")
)
(initget 1)
(setq pt0 (getpoint "\nPoint to outside of wall: "))
)
)
(princ "\nWorking ")
(command ".UNDO" "Group")
(ssfunc ss
'(lambda ()
(work)
(setq edata (entget ename))
; Issa LINE entity, fall thru
(if (etype edata "LINE")
(setq
; Get relevant groups
edata (get '(-1 10 11) edata)
slope (getslope (cadr edata) (caddr edata))
walls
; Does this slope already exist in walls list
(if (setq temp (assoc slope walls))
; Yes, add new line info to assoc group
(subst (append temp (list edata)) temp walls)
; Nope, add new assoc group w/line info
(cons (cons slope (list edata)) walls)
)
)
)
)
)
(cond
((< (length walls) 2)
(princ "\rerror: Use MEND to join colinear walls.")
)
((> (length walls) 2)
(princ "\rerror: Only two walls may be cleaned.")
)
((not (apply '= (mapcar 'length walls)))
(princ "\rerror: Walls have unequal number of lines.")
)
(T
;-------------------------------
; Create List of Perpendiculars
;-------------------------------
(setq perps
(mapcar
'(lambda (x)
(work)
(mapcar
'(lambda (y)
(work)
(perp pt0 (cadr y) (caddr y))
)
(cdr x)
)
)
walls
)
)
;--------------------------
; Create List of Distances
;--------------------------
(setq dists
(mapcar
'(lambda (x)
(work)
(setq i 0)
(mapcar
'(lambda (y)
(work)
; Create list of distances (with pointers to WALLS)
(list
; Compute distances
(distance pt0 y)
; Key
(setq i (1+ i))
)
)
x
)
)
; List of perpendicular points
perps
)
)
; Sort distance index
(setq dists (mapcar 'sort dists))
; Clean intersections
(setq wall1 (car walls) wall2 (cadr walls))
(neatx1 (car dists) (cadr dists))
)
)
(command ".UNDO" "End")
)
;----------------------------
; Restore enviroment, memory
;----------------------------
(princ)
;---< End Of File >---
)
(princ)
Posted in AutoLISP, AutoLISP: Modify | 3 Comments

AutoLISP: T Shape Wall Clean Up

Link to AutoCAD Tips

Today’s featured routine will clean up wall intersections that are T-shaped.

  • WALL-T <enter> to start

To be honest, this one is the most confusing routine of “wall clean up” routines. Just like the previous routine, this routine lets you select the objects first and then specify how the T-shape will be determined. This is done by asking the user to specify the “Lower Left leg” Shown Below:

Shown Below:

Default Function – The first pick specifies the “Lower Left Leg”

Shown Below:

Select object first and then specify the “Lower Left Leg” of the T

~enjoy

(defun c:wall-t (/ >90 @work ang dist1 dist2 dists edata eqpnt etype fuzzy
get getside getslope head i merge neatt1 neatt2 neatt3
nukenz perp perps pt0 pt1 pt2 pt3 pt4 slope sort ss ssfunc
temp tail wall1 wall2 walls work x y
)
(setq clayer nil)
(princ "\nLoading -")
(setq @WORK '("\\" "|" "/" "-"))
(defun WORK ()
; Backspace
(prompt "\010")
(setq @work (append (cdr @work) (list (princ (car @work)))))
)
(work)
(defun NUKENZ (x)
(cdr (reverse (cdr x)))
)
(work)
(defun NEATT1 (dist1 dist2 / x y line1 line2 pt1 pt2 ip1)
(work)
(cond
((cdr dist1)
(setq
x (cadar dist1)
y (cadr (last dist1))
)
(neatt2
; 2nd wall - line 1
(nth (cadar dist2) wall2)
; 1st wall - line 1
(nth x wall1)
; 1st wall - line 2
(nth y wall1)
; 1st wall - perpend 1
(nth (1- x) perps)
; 1st wall - perpend 2
(nth (1- y) perps)
)
(neatt1 (nukenz dist1) (cdr dist2))
)
((car dist1)
(setq
; 1st line
line1 (nth (cadar dist1) wall1)
; 2nd line
line2 (nth (cadar dist2) wall2)
; 1st line endpoints
pt1 (cadr line1)
pt2 (caddr line1)
; Intersection point
ip1 (inters pt1 pt2 (cadr line2) (caddr line2) nil)
)
(neatt3 line1 ip1 (nth (1- (cadar dist1)) perps))
)
(T nil)
)
)
(work)
(defun NEATT2 (line1 line2 line3 pp2 pp3 / pt1 pt2 ip2 ip3)
(work)
(setq
; 1st line endpoints
pt1 (cadr line1)
pt2 (caddr line1)
; Intersection points
ip2 (inters pt1 pt2 (cadr line2) (caddr line2) nil)
ip3 (inters pt1 pt2 (cadr line3) (caddr line3) nil)
)
(command ".BREAK" (car line1) ip2 ip3)
(neatt3 line2 ip2 pp2)
(neatt3 line3 ip3 pp3)
)
(work)
(defun NEATT3 (line1 ip1 pp1 / edata group ang1 ang2)
(work)
(setq
pt1 (cadr line1)
pt2 (caddr line1)
ang1 (angle pp1 ip1)
ang2 (angle pt1 pt2)
group (if (eqpnt (polar ip1 ang1 1.0) (polar ip1 ang2 1.0)) 11 10)
edata (entget (car line1))
)
(entmod (subst (cons group ip1) (assoc group edata) edata))
)
(work)
(defun GETSIDE (pt0 pp1 pp2 / temp)
; Get delta angle
(setq temp (- (angle pt0 pp2) (angle pt0 pp1)))
; Figure postive or negative angle direction
(if ((if (minusp temp) < >) (abs temp) pi) nil T)
)
(work)
(defun FUZZY (x y)
(< (abs (- x y)) 1.0e-6)
)
(work)
(defun EQPNT (p1 p2)
(< (distance p1 p2) 1.0e-6)
)
(work)
(defun GET (key alist)
(if (atom key)
(cdr (assoc key alist))
(mapcar '(lambda (x) (cdr (assoc x alist))) key)
)
)
(work)
(defun SORT (x)
(work)
(cond
((null (cdr x)) x)
(T
(merge
(sort (head x (1- (length x))))
(sort (tail x (1- (length x))))
)
)
)
)
(work)
(defun MERGE (a b)
(work)
(cond
((null a) b)
((null b) a)
((< (caar a) (caar b))
(cons (car a) (merge (cdr a) b))
)
(t (cons (car b) (merge a (cdr b))))
)
)
(work)
(defun HEAD (l n)
(cond
((minusp n) nil)
(T (cons (car l) (head (cdr l) (- n 2))))
)
)
(work)
(defun TAIL (l n)
(cond
((minusp n) l)
(T (tail (cdr l) (- n 2)))
)
)
(work)
(defun GETSLOPE (pt1 pt2 / x)
; Vertical?
(if (fuzzy (setq x (abs (- (car pt1) (car pt2)))) 0.0)
; Yes, return NIL
nil
; No, compute slope
(rtos (/ (abs (- (cadr pt1) (cadr pt2))) x) 2 4)
)
)
(work)
(defun ETYPE (edata match)
(member (get 0 edata) (if (listp match) match (list match)))
)
(work)
(defun SSFUNC (ss func / i ename)
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(apply func nil)
)
)
(work)
(defun PERP (pt0 pt1 pt2)
(inters pt1 pt2 pt0 (polar pt0 (+ (angle pt1 pt2) >90) 1.0) nil)
)
(setq >90 (/ pi 2))
(setvar "CmdEcho" 0)
(setvar "BlipMode" 0)
(princ "\rLoaded. ")
(while
(progn
(initget "Select")
(setq pt0 (getpoint "\nSelect objects/<First corner>: "))
)
(setq
dists nil
perps nil
walls nil
)
(cond
((eq (type pt0) 'LIST)
(initget 33)
(setq
pt1 (getcorner pt0 "\nOther corner: ")
ss (ssget "C" pt0 pt1)
)
)
(T
(while
(progn
(princ "\nSelect objects: ")
(command ".SELECT" "Au" pause)
(not (setq ss (ssget "P")))
)
(print "No objects selected, try again.")
)
(initget 1)
(setq pt0 (getpoint "\nPoint to left of 'leg' wall: "))
)
)
(princ "\nWorking ")
(command ".UNDO" "Group")
(ssfunc ss
'(lambda ()
(work)
(setq edata (entget ename))
; Issa LINE entity, fall thru
(if (etype edata "LINE")
(setq
; Get relevant groups
edata (get '(-1 10 11) edata)
slope (getslope (cadr edata) (caddr edata))
walls
; Does this slope already exist in walls list
(if (setq temp (assoc slope walls))
; Yes, add new line info to assoc group
(subst (append temp (list edata)) temp walls)
; Nope, add new assoc group w/line info
(cons (cons slope (list edata)) walls)
)
)
)
)
)
(cond
((< (length walls) 2)
(princ "\rerror: Use MEND to join colinear walls.")
)
((> (length walls) 2)
(princ "\rerror: Only two walls may be cleaned.")
)
; Quick way to compare numbers of lines per wall
((not (apply '= (mapcar 'length walls)))
(princ "\rerror: Walls have unequal number of lines.")
)
(T
;-------------------------------
; Create List of Perpendiculars
;-------------------------------
(setq perps
(mapcar
'(lambda (x)
(work)
(mapcar
'(lambda (y)
(work)
(perp pt0 (cadr y) (caddr y))
)
(cdr x)
)
)
walls
)
)
;--------------------------
; Create List of Distances
;--------------------------
(setq dists
(mapcar
'(lambda (x)
(work)
(setq i 0)
(mapcar
'(lambda (y)
(work)
; Create list of distances (with pointers to WALLS)
(list
; Compute distances
(distance pt0 y)
; Key
(setq i (1+ i))
)
)
x
)
)
; List of perpendicular points
perps
)
)
; Sort distance index
(setq dists (mapcar 'sort dists))
(work)
(cond
; Determine acute angle
((getside pt0 (caar perps) (caadr perps))
(setq
perps (car perps)
wall1 (car walls)
wall2 (cadr walls)
dist1 (car dists)
dist2 (cadr dists)
)
)
(T
(setq
perps (cadr perps)
wall1 (cadr walls)
wall2 (car walls)
dist1 (cadr dists)
dist2 (car dists)
)
)
)
(work)
; Ensure proper intersection specification
(setq
line1 (cadr wall1)
line2 (cadr wall2)
pt1 (cadr line1)
pt2 (caddr line1)
pt3 (cadr line2)
pt4 (caddr line2)
ang (angle pt1 pt2)
pt0 (inters pt1 pt2 pt3 pt4 nil)
)
(cond
((inters pt3 pt4 pt0 (polar pt0 ang 1.0))
; Clean intersections
(neatt1 dist1 dist2)
(princ "\rComplete.")
)
(T
(princ "\rerror: Unable to cleanup specified intersection.")
)
)
)
)
(command ".UNDO" "End")
)
;----------------------------
; Restore enviroment, memory
;----------------------------
(princ)
; ----< End Of File >----
)
(princ)
Posted in AutoLISP, AutoLISP: Modify | 1 Comment

AutoLISP: L Shape Wall Clean Up

Link To AutoCAD Tips

This routine is very handy if you need to clean up wall intersections that are L-shaped. The wall intersections do not have to be 90 degrees and they do not have to be orthogonal.

There are 2 options:

(Shown below) When you start the routine (WALL-L), if you enter S for “Select objects” you must first select the wall objects and then you specify the area for the “Inside corner” with a single click.

The Second Option (shown below) which is also the default option:

Start the command (WALL-L <enter>) and then make a selection window (selection type doesn’t matter). What matters is that your first pick determines the “Inside corner”

 

(defun c:wall-l (/ >90 @work ang1 ang2 dists edata eqpnt etype fuzzy get
getslope head merge perp perps pt0 pt1 neatl slope sort
ss ssfunc tail temp walls work
)
(setq clayer nil)
(princ "\nLoading -")
(setq @WORK '("\\" "|" "/" "-"))
(defun WORK ()
; Backspace
(prompt "\010")
(setq @work (append (cdr @work) (list (princ (car @work)))))
)
(work)
(defun NEATL (dist1 dist2 / line1 line2 pt1 pt2 pt3 pt4 ipt pp1 pp2 x y
group edata enm)
(mapcar
'(lambda (x y)
(work)
(setq
x (cadr x)
y (cadr y)
line1 (nth x (car walls))
line2 (nth y (cadr walls))
pt1 (cadr line1)
pt2 (caddr line1)
pt3 (cadr line2)
pt4 (caddr line2)
pp1 (nth (1- x) (car perps))
pp2 (nth (1- y) (cadr perps))
ipt (inters pt1 pt2 pt3 pt4 nil)
)
(mapcar
'(lambda (enm pt1 pt2 pp)
(work)
(setq
ang1 (angle pp ipt)
ang2 (angle pt1 pt2)
group (if (eqpnt (polar ipt ang1 1.0) (polar ipt ang2 1.0)) 11 10)
edata (entget enm)
)
(entmod (subst (cons group ipt) (assoc group edata) edata))
)
(list (car line1) (car line2))
(list pt1 pt3)
(list pt2 pt4)
(list pp1 pp2)
)
)
dist1
dist2
)
)
(work)
(defun FUZZY (x y)
(< (abs (- x y)) 1.0e-6)
)
(work)
(defun EQPNT (p1 p2)
(< (distance p1 p2) 1.0e-6)
)
(work)
(defun GET (key alist)
(if (atom key)
(cdr (assoc key alist))
(mapcar '(lambda (x) (cdr (assoc x alist))) key)
)
)
(work)
(defun SORT (x)
(work)
(cond
((null (cdr x)) x)
(T
(merge
(sort (head x (1- (length x))))
(sort (tail x (1- (length x))))
)
)
)
)
(work)
(defun MERGE (a b)
(work)
(cond
((null a) b)
((null b) a)
((< (caar a) (caar b))
(cons (car a) (merge (cdr a) b))
)
(t (cons (car b) (merge a (cdr b))))
)
)
(work)
(defun HEAD (l n)
(cond
((minusp n) nil)
(t (cons (car l) (head (cdr l) (- n 2))))
)
)
(work)
(defun TAIL (l n)
(cond
((minusp n) l)
(t (tail (cdr l) (- n 2)))
)
)
(work)
(defun GETSLOPE (pt1 pt2 / x)
; Vertical?
(if (fuzzy (setq x (abs (- (car pt1) (car pt2)))) 0.0)
; Yes, return NIL
nil
; No, compute slope
(rtos (/ (abs (- (cadr pt1) (cadr pt2))) x) 2 4)
)
)
(work)
(defun ETYPE (edata match)
(member (get 0 edata) (if (listp match) match (list match)))
)
(work)
(defun SSFUNC (ss func / i ename)
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(apply func nil)
)
)
(work)
(defun PERP (pt0 pt1 pt2)
(inters pt1 pt2 pt0 (polar pt0 (+ (angle pt1 pt2) >90) 1.0) nil)
)
(setq >90 (/ pi 2))
(setvar "CmdEcho" 0)
(princ "\rLoaded. ")
(while
(progn
(initget "Select")
(setq pt0 (getpoint "\nSelect objects/<Inside corner>: "))
)
(setq
dists nil
perps nil
walls nil
)
(cond
((eq (type pt0) 'LIST)
(initget 33)
(setq
pt1 (getcorner pt0 "\nOutside corner: ")
ss (ssget "C" pt0 pt1)
)
)
(T
(while
(progn
(princ "\nSelect objects: ")
(command ".SELECT" "Au" pause)
(not (setq ss (ssget "P")))
)
(print "No objects selected, try again.")
)
(initget 1)
(setq pt0 (getpoint "\nPoint to inside of wall: "))
)
)
(princ "\nWorking ")
(command ".UNDO" "Group")
(ssfunc ss
'(lambda ()
(work)
(setq edata (entget ename))
; Issa LINE entity, fall thru
(if (etype edata "LINE")
(setq
; Get relevant groups
edata (get '(-1 10 11) edata)
slope (getslope (cadr edata) (caddr edata))
walls
; Does this slope already exist in walls list
(if (setq temp (assoc slope walls))
; Yes, add new line info to assoc group
(subst (append temp (list edata)) temp walls)
; Nope, add new assoc group w/line info
(cons (cons slope (list edata)) walls)
)
)
)
)
)
(cond
((< (length walls) 2)
(princ "\rerror: Use MEND to join colinear walls.")
)
((> (length walls) 2)
(princ "\rerror: Only two walls may be cleaned.")
)
((not (apply '= (mapcar 'length walls)))
(princ "\rerror: Walls have unequal number of lines.")
)
(T
;-------------------------------
; Create List of Perpendiculars
;-------------------------------
(setq perps
(mapcar
'(lambda (x)
(work)
(mapcar
'(lambda (y)
(work)
(perp pt0 (cadr y) (caddr y))
)
(cdr x)
)
)
walls
)
)
;--------------------------
; Create List of Distances
;--------------------------
(setq dists
(mapcar
'(lambda (x)
(work)
(setq i 0)
(mapcar
'(lambda (y)
(work)
; Create list of distances (with pointers to WALLS)
(list
; Compute distances
(distance pt0 y)
; Key
(setq i (1+ i))
)
)
x
)
)
; List of perpendicular points
perps
)
)
; Sort distance index
(setq dists (mapcar 'sort dists))
; Clean intersections
(neatl (car dists) (cadr dists))
(princ "\rComplete.")
)
)
(command ".UNDO" "End")
)
;----------------------------
; Restore enviroment, memory
;----------------------------
(princ)
; ----< End Of File >----
)
(princ)
Posted in AutoLISP, AutoLISP: Modify | Leave a comment

AutoLISP: Erase Inside Closed Polyline

Link to AutoCAD Tips

Here is another erasing routine. This one will erase everything inside of a closed polyline that you select. The main difference between this one and the previously featured routine is that objects that cross the polyline are ignored and not deleted. Another difference is that this routine uses a polyline to specify the area while the other routine uses a selection window.

Here’s how:

  • EICP <enter> to start (Erase Inside Closed Polyline)
  • Select a closed polyline to define the closed area (Only works on polylines)

~enjoy

;;; Erase Inside a Closed Pline
;;;---------------start of routine-----------------------------------
(defun c:EICP ()
(vl-load-com)
(inivar)
(princ
"\nPick a CLOSED POLYLINE (and everything inside will be erased)..."
)
(setq CLOSEDPOLY
(vlax-ename->vla-object
(car (entsel "\nSelect object :"))
)
)
(if (/= CLOSEDPOLY nil)
(progn
(setq POLYTRUEFALSE
(vlax-get-property CLOSEDPOLY 'objectname)
)
(if (= POLYTRUEFALSE "AcDbPolyline")
(progn
(setq CLOSEDTRUEFALSE
(vlax-get-property
CLOSEDPOLY
'closed
)
)
(if (/= CLOSEDTRUEFALSE :vlax-true)
(progn
(setq CLOSEDPOLY nil)
(princ "\nThe POLYLINE isn't CLOSED...")
)
)
)
(progn
(setq CLOSEDPOLY nil)
(princ "\nSelect a POLYLINE...")
)
)
)
)
(while (= CLOSEDPOLY nil)
(progn
(princ "\nNothing Selected...")
(setq CLOSEDPOLY
(vlax-ename->vla-object
(car (entsel "\nSelect object :"))
)
)
(if (/= CLOSEDPOLY nil)
(progn
(setq POLYTRUEFALSE
(vlax-get-property CLOSEDPOLY 'objectname)
)
(if (= POLYTRUEFALSE "AcDbPolyline")
(progn
(setq CLOSEDTRUEFALSE
(vlax-get-property CLOSEDPOLY 'closed)
)
(if (/= CLOSEDTRUEFALSE :vlax-true)
(progn
(setq CLOSEDPOLY nil)
(princ "\nThe POLYLINE isn't CLOSED...")
)
)
)
(progn
(setq CLOSEDPOLY nil)
(princ "\nSelect a POLYLINE...")
)
)
)
)
)
)
(setq ENDPARAM (fix (vlax-curve-getEndParam CLOSEDPOLY)))
(setq COUNT 0)
(setq listapt nil)
(while (<= COUNT ENDPARAM)
(progn
(setq xy (vlax-curve-getPointAtParam CLOSEDPOLY COUNT))
(setq listapt (append listapt (list xy)))
(setq COUNT (1+ COUNT))
)
)
(setq lengthlista (length listapt))
(setq pt1 (nth (- lengthlista 2) listapt)
pt2 (nth (1- lengthlista) listapt)
)
(setq strpt1 (vl-princ-to-string pt1)
strpt2 (vl-princ-to-string pt2)
)
(if (= strpt1 strpt2)
(progn
(setq listapt (vl-remove pt1 listapt))
)
)
(setq selset (ssget "_WP" listapt))
(if (/= selset nil)
(progn
(setq selnumb (sslength selset))
(setq COUNT 0)
(while (< COUNT selnumb)
(progn
(setq ent (ssname selset count))
(entdel ent)
(setq COUNT (1+ COUNT))
)
)
)
(princ "\nNo objects to erase...")
)
(EICP)
(princ)
)
;;;-------------------;;;
(defun inivar ()
(setq cmd_ini (getvar "cmdecho")
fla_ini (getvar "flatland")
osm_ini (getvar "osmode")
ort_ini (getvar "orthomode")
plt_ini (getvar "plinetype")
aup_ini (getvar "auprec")
uni_ini (getvar "unitmode")
lun_ini (getvar "lunits")
diz_ini (getvar "dimzin")
edg_ini (getvar "edgemode")
)
(setvar "CMDECHO" 0)
(setvar "FLATLAND" 0)
(setvar "OSMODE" 0)
(setvar "ORTHOMODE" 0)
(setvar "PLINETYPE" 2)
(setvar "AUPREC" 0)
(setvar "UNITMODE" 1)
(setvar "LUNITS" 2)
(setvar "DIMZIN" 0)
(setvar "EDGEMODE" 1)
)
;;;-------------------;;;
(defun EICP ()
(setvar "CMDECHO" cmd_ini)
(setvar "FLATLAND" fla_ini)
(setvar "OSMODE" osm_ini)
(setvar "ORTHOMODE" ort_ini)
(setvar "PLINETYPE" plt_ini)
(setvar "AUPREC" aup_ini)
(setvar "UNITMODE" uni_ini)
(setvar "LUNITS" lun_ini)
(setvar "DIMZIN" diz_ini)
(setvar "EDGEMODE" edg_ini)
)
;;;--------------------end of routine-------------------------;;;
Posted in AutoLISP, AutoLISP: Modify, AutoLISP: Polylines | Leave a comment