Sei sulla pagina 1di 58

PRICOL

(DEFUN C:2()
(COMMAND "DIMLINEAR" PAUSE PAUSE)
)
_______________________________________________________________________________________
______________________________________________________________
(DEFUN C:3()
(COMMAND "DIMCONTINUE" PAUSE)
)
_______________________________________________________________________________________
_____________________________________________________________
(DEFUN C:4()
(COMMAND "QLEADER" PAUSE PAUSE "" "" "" "" )
)
_______________________________________________________________________________________
_____________________________________________________________
(DEFUN C:5()
(COMMAND "aidimtextmove" 1 pause)
)
_______________________________________________________________________________________
_____________________________________________________________
(DEFUN C:SHO()
(SETQ
SO(SSGET)
SO1(SSGET)
)
(COMMAND "COPY" SO "" 12 16 "")(SETQ OBJ1 ENTLAST)
(COMMAND "hatchsetboundary" "L" SO1 "" "N")
;(COMMAND "ERASE" OBJ1 "")
)
_______________________________________________________________________________________
______________________________________________________________
(DEFUN C:DF()
(SETQ
P1(GETPOINT "\n PICK FIRST POINT :")
P2(GETPOINT P1 "\n PICK SECOND POINT :")
DI(DISTANCE P1 P2 )
; fi(fix di)
Page 1

PRICOL
CV(CVUNIT DI "MILLIMETER" "FOOT")
TE(/ DI 10)
)
(ALERT (strcat

(rtos DI )

" MM = " (RTOS TE ) " CM = "(RTOS (* 12 CV) 3 1)))

(PRINT TE)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
____________________________________________________________________
(DEFUN C:CC()
(SETQ
CNU(GETINT "\n ENTER COLOR NUMBER:")
CCL(GETINT "\n ENTER CHANGE COLOR NUMER :")
HO(SSGET (LIST(CONS 62 CNU)))
)
(COMMAND "CHANGE" HO "" "P" "CO" CCL "")
)
_________________________________________________________________
________________________________________________________________
(DEFUN C:HD()
(SETQ
DO(SSGET "X" (LIST(CONS 0 "dimension")))
)
(command "hideobjects" DO "")
(ALERT "ALL DIMENSION ARE HIDDEN")
(VLVBALOAD "D:/pro/HIDEOBJ.DVB")
(VLVBARUN "HIDEOBJ")
)
_________________________________________________________________
________________________________________________________________
(DEFUN C:HT()
(command "layer" "n" "TEXT" "co" 61 "TEXT" "")
(SETQ
TO(SSGET "X" (LIST(CONS 0 "TEXT")))
MO(SSGET "X" (LIST(CONS 0 "MTEXT")))
)
(command "hideobjects" TO MO "")
(ALERT "ALL TEXT ARE HIDDEN")
)
_________________________________________________________________
_________________________________________________________________
(DEFUN C:HB()
(SETQ
bO(SSGET "X" (LIST(CONS 0 "INSERT")))
Page 2

PRICOL
)
(command "hideobjects" bO "")
(ALERT "ALL BLOCK ARE HIDDEN")
)
_______________________________________________________________________________________
_____________

(DEFUN C:HH()
(command "layer" "n" "DIMENSION" "co" "RED" "DIMENSION" "")
(SETQ
DO(SSGET "X" (LIST(CONS 0 "HATCH")))
)
(command "hideobjects" DO "")
(ALERT "ALL HATCH ARE HIDDEN")
)
_________________________________________________________________
(DEFUN C:UH()
(command "UNISOLATEOBJECTS")
)
_________________________________________________________________
(defun c:SD()
(setq a1 (ssget ((0 . "DIMENSION"))))
(command "stretch" a1 pause)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
_____
(defun c:MD()
(setq a1 (ssget ((0 . "DIMENSION"))))
(command "MOVE" a1 pause)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
_____
(DEFUN C:AS()
(setq
Page 3

PRICOL
obj(entsel)
)
(COMMAND "HATCHEDIT" obj "B" "" "" )
(REPEAT 1500
(PRINT "B.MUTHUKUMAR")(TERPRI)
)
(ALERT "THE SELECTED HATCH ARE STRETCHABLE")
)
_______________________________________________________________________________________
________________________________________________________________
(defun c:bl()
(setq
st(getstring "\n enter block name:")
po(getpoint "\n pick a insertion point:")
ob(entsel "\n select object:")
obj1(entlast)
xv(getdist "\n pick x direction:")
yv(getdist "\n pick y direction:")
fx(/ 1 xv)
fy(/ 1 yv)
)
(command "block" st po obj1 "")
(print fx)
(print fy)
(command "insert" st po fx fy "")
(COMMAND "ZOOM" "E")
)
_______________________________________________________________________________________
__________________________________________________________

;;=={ Automatic Block Break }==;;


;;
;;
;; This program enables the user to insert a block at a specified
;;
Page 4

PRICOL
;; point, with surrounding geometry trimmed to the rectangular outline ;;
;; of the block. Optionally, the program will automatically rotate
;;
;; the block to align with a curve object passing through the block
;;
;; insertion point.
;;
;;
;;
;; The program first prompts the user to select a block to insert. At ;;
;; this prompt the user may select a block from the drawing, or type ;;
;; Browse to browse for a drawing file to insert. The user may also ;;
;; alter the program rotation setting by typing Rotation at the
;;
;; prompt.
;;
;;
;;
;; Following a valid response, the program prompts the user to specify ;;
;; an insertion point for the block.
;;
;;
;;
;; If a curve object (Arc, Elliptical Arc, Ellipse, Circle, Line,
;;
;; XLine, Spline, LWPolyline or Polyline) is detected at the block
;;
;; insertion point and the program rotation setting is enabled, the
;;
;; inserted block is automatically rotated to align with the curve.
;;
;;
;;
;; All surrounding compatible objects found to intersect with the
;;
;; inserted block are then trimmed to the rectangular block outline. ;;
;;
;;
;;;;
;; Author: Lee Mac, Copyright 2010 www.leemac.com
;;
;;;;
;; Version 1.0

22112010
;;
;;
;;
;; First Release.
;;
;;;;
;; Version 1.1

07022011
;;
;;
;;
;; Entire program rewritten to allow subfunction to be called with
;;
;; block object argument.
;;
;;
;;
;; Multiple intersecting objects are now trimmed.
;;
;;;;
;; Version 1.2

08022011
;;
;;
;;
;; Changed block insertion to Visual LISP InsertBlock method.
;;
;;
;;
;; Added calling functions to trim blocks insitu (ABBE / ABBS).
;;
;;;;
;; Version 1.3

03082011
;;
;;
;;
;; Altered method used to create bounding polyline to exclude
;;
;; attributes when trimming objects surrounding block.
;;
;;
;;
;; Objects surrounding blocks whose insertion point does not lie on a ;;
;; curve are now also trimmed.
;;
;;;;
;; Version 1.4

30092011
;;
;;
;;
;; Added option to enable/disable automatic block rotation.
;;
;;
;;
;; Updated code formatting.
;;
;;;;
;; Version 1.5

04032013
;;
;;
;;
;; Fixed bug causing program to attempt to break MLines.
;;
;;
;;
;; Added new LM:blockboundingbox function to correctly calculate the ;;
;; bounding box of Dynamic Block references.
;;
;;
;;
;; Entire program rewritten.
;;
Page 5

PRICOL
;;;;
;; Version 1.6

01102013
;;
;;
;;
;; Fixed a bug causing the program to return an error if an object
;;
;; intersects the block bounding box at only one point.
;;
;;;;
(defun c:abb ( / *error* blk obj ins sel )
(defun *error* ( msg )
(LM:endundo (LM:acdoc))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(cond
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar clayer))))))
(princ "\nCurrent layer locked.")
)
( (progn
(while
(progn
(setvar errno 0)
(initget "Browse Rotation")
(princ (strcat "\nAutomatic Block Rotation: " (getenv "LMac\\ABBRotation")))
(setq sel
(entsel
(strcat "\nSelect Block [Browse/Rotation]"
(if (= "" (setq blk (getvar insname)))
": "
(strcat " <" blk "> : ")
)
)
)
)
(cond
( (= 7 (getvar errno))
(princ "\nMissed, Try Again.")
)
( (null sel)
(if (= "" blk)
(setq blk nil)
)
)
( (= "Rotation" sel)
(initget "ON OFF")
(setenv "LMac\\ABBRotation"
(cond
( (getkword
(strcat "\nAutomatic Block Rotation [ON/OFF] <"
(getenv "LMac\\ABBRotation") ">: "
)
)
)
( (getenv "LMac\\ABBRotation") )
)
)
)
( (= "Browse" sel)
(setq blk (getfiled "Select Block" "" "dwg" 16))
nil
)
Page 6

PRICOL
(listp sel)
(if (/= "INSERT" (cdr (assoc 0 (entget (car sel)))))
(princ "\nObject must be a block.")
(setq obj (vlacopy (vlaxename>vlaobject (car sel)))
blk nil
)
)

)
)
)
)
(not (or blk obj))
)
)
(

(setq ins (getpoint "\nSpecify Point for Block: "))


(LM:startundo (LM:acdoc))
(if (null obj)
(setq obj
(vlainsertblock
(vlaxgetproperty (LM:acdoc) (if (= 1 (getvar cvport)) paperspace modelspace))
(vlax3Dpoint (trans ins 1 0))
blk
1.0
1.0
1.0
(angle (0.0 0.0 0.0) (trans (getvar ucsxdir) 0 (trans (0.0 0.0 1.0) 1 0 t) t))
)
)
)
(if blk (setvar insname (vlfilenamebase blk)))
(vlaputinsertionpoint obj (vlax3Dpoint (trans ins 1 0)))
(LM:AutoBlockBreak (vlaxvlaobject>ename obj) (= "ON" (getenv "LMac\\ABBRotation")))
(LM:endundo (LM:acdoc))

)
)
(princ)
)
;;=={ Automatic Block Break Existing }==;;
;;
;;
;; This program enables the user to select an existing block and trim ;;
;; all surrounding geometry to the rectangular outline of the block. ;;
;; Optionally, the program will automatically rotate the selected
;;
;; block to align with a curve object passing through the block
;;
;; insertion point.
;;
;;
;;
;; At the block selection prompt, the user may also alter the program ;;
;; rotation setting by typing Rotation when prompted.
;;
;;
;;
;; If a curve object (Arc, Elliptical Arc, Ellipse, Circle, Line,
;;
;; XLine, Spline, LWPolyline or Polyline) is detected at the block
;;
;; insertion point of the selected block and the program rotation
;;
;; setting is enabled, the block is automatically rotated to align
;;
;; with the curve.
;;
;;
;;
;; All surrounding compatible objects found to intersect with the
;;
;; selected block are then trimmed to the rectangular block outline. ;;
;;
;;
;;;;
;; Author: Lee Mac, Copyright 2010 www.leemac.com
;;
;;;;
(defun c:abbe ( / *error* enx sel )
Page 7

PRICOL
(defun *error* ( msg )
(LM:endundo (LM:acdoc))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(while
(progn
(setvar errno 0)
(initget "Rotation")
(princ (strcat "\nAutomatic Block Rotation: " (getenv "LMac\\ABBRotation")))
(setq sel (entsel "\nSelect Block to Trim [Rotation]: "))
(cond
( (= 7 (getvar errno))
(princ "\nMissed, Try Again.")
)
( (= "Rotation" sel)
(initget "ON OFF")
(setenv "LMac\\ABBRotation"
(cond
( (getkword
(strcat "\nAutomatic Block Rotation [ON/OFF] <"
(getenv "LMac\\ABBRotation") ">: "
)
)
)
( (getenv "LMac\\ABBRotation") )
)
)
)
( (= ename (type (car sel)))
(cond
( (/= "INSERT" (cdr (assoc 0 (setq enx (entget (car sel))))))
(princ "\nObject must be a block.")
)
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 enx)))))))
(princ "\nSelected block is on a locked layer.")
)
( t
(LM:startundo (LM:acdoc))
(LM:AutoBlockBreak (car sel) (= "ON" (getenv "LMac\\ABBRotation")))
(LM:endundo (LM:acdoc))
)
)
t
)
)
)
)
(princ)
)
;;=={ Automatic Block Break Selection }==;;
;;
;;
;; This program enables the user to select multiple existing blocks
;;
;; and automatically trim all surrounding geometry to the rectangular ;;
;; outline of each block. Optionally, the program will automatically ;;
;; rotate each block in the selection to align with curve objects
;;
;; detected to pass through the block insertion point.
;;
;;
;;
;;;;
;; Author: Lee Mac, Copyright 2010 www.leemac.com
;;
Page 8

PRICOL
;;;;
(defun c:abbs ( / *error* inc rot sel )
(defun *error* ( msg )
(LM:endundo (LM:acdoc))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(setq rot (= "ON" (getenv "LMac\\ABBRotation")))
(if (setq sel (ssget "_:L" ((0 . "INSERT"))))
(progn
(LM:startundo (LM:acdoc))
(repeat (setq inc (sslength sel))
(LM:AutoBlockBreak (ssname sel (setq inc (1 inc))) rot)
)
(LM:endundo (LM:acdoc))
)
)
(princ)
)
;;=={ Automatic Block Break SubFunction }==;;
;;
;;
;; Upon calling the function with a VLA Block Reference Object
;;
;; argument, the function will trim all surrounding compatible
;;
;; geometry found to intersect with the rectangular outline of the
;;
;; supplied block reference.
;;
;;
;;
;; Furthermore, if a curve object is detected to pass through (or in ;;
;; the vicinity of) the block insertion point and the rotation flag
;;
;; argument holds a nonnil value, the supplied block reference is
;;
;; rotated to align with the curve.
;;
;;
;;
;;;;
;; Author: Lee Mac, Copyright 2010 www.leemac.com
;;
;;;;
;; Arguments:
;;
;; ent Block Reference Entity
;;
;; rot Rotation flag (if T, block is aligned to curve)
;;
;;;;
(defun LM:AutoBlockBreak
( ent rot / *error* _getfurthestapart ang bbx brk cmd crv enx inc ins int lst ply sel )
(defun *error* ( msg )
(if
(and
(= vlaobject (type ply))
(null (vlaxerasedp ply))
(vlaxwriteenabledp ply)
)
(vladelete ply)
)
(if (= int (type cmd))
(setvar cmdecho cmd)
)
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
Page 9

PRICOL
(princ)
)
(defun _getfurthestapart ( lst / dis mxd out pt1 pt2 )
(setq mxd 0.0)
(while (setq pt1 (car lst))
(foreach pt2 (setq lst (cdr lst))
(if (< mxd (setq dis (distance pt1 pt2)))
(setq mxd dis
out (list pt1 pt2)
)
)
)
)
out
)
(if
(and
(= ename (type ent))
(setq enx (entget ent))
(= "INSERT" (cdr (assoc 0 enx)))
)
(progn
(if
(and rot
(setq ins (cdr (assoc 10 enx)))
(setq crv
(ssget "_C"
(mapcar + (trans ins ent 1) (1e4 1e4))
(mapcar (trans ins ent 1) (1e4 1e4))
((0 . "ARC,ELLIPSE,CIRCLE,LINE,XLINE,SPLINE,*POLYLINE"))
)
)
)
(progn
(setq crv (ssname crv 0))
(setq ang
(angle (0.0 0.0 0.0)
(trans
(vlaxcurvegetfirstderiv crv
(vlaxcurvegetparamatpoint crv
(vlaxcurvegetclosestpointto crv (trans ins ent 0))
)
)
0 (cdr (assoc 210 (entget crv)))
)
)
)
(if (and (< (/ pi 2.0) ang) (<= ang (/ (* 3.0 pi) 2.0)))
(setq ang (+ ang pi))
)
(vlaputrotation (vlaxename>vlaobject ent) ang) ;; VL used to account for
attributes
)
)
(if
(and
(setq bbx (LM:blockboundingbox (vlaxename>vlaobject ent)))
(setq sel
(ssget "_C"
(trans (car bbx) 0 1)
(trans (caddr bbx) 0 1)
((0 . "ARC,ELLIPSE,CIRCLE,LINE,XLINE,SPLINE,*POLYLINE"))
Page 10

PRICOL
)
)
)
(progn
(setq ply
(vlaxename>vlaobject
(entmakex
(append
(list
(000 . "LWPOLYLINE")
(100 . "AcDbEntity")
(100 . "AcDbPolyline")
(090 . 4)
(070 . 1)
(cons 38 (cadddr (assoc 10 enx)))
)
(mapcar (lambda ( p ) (mapcar + (cons 10 (trans p 0 ent)) (0 0 0))) bbx)
(list (assoc 210 enx))
)
)
)
)
(repeat (setq inc (sslength sel))
(setq ent (ssname sel (setq inc (1 inc))))
(if (setq int (LM:Intersections (vlaxename>vlaobject ent) ply
acextendthisentity))
(setq lst (cons (cons ent int) lst))
)
)
(vladelete ply)
(setq cmd (getvar cmdecho))
(setvar cmdecho 0)
(foreach int lst
(if (setq brk (_getfurthestapart (cdr int)))
(command
"_.break" (list (car int) (trans (car brk) 0 1)) "_F"
"_non"
(trans (car brk) 0 1)
"_non"
(trans (cadr brk) 0 1)
)
)
)
(setvar cmdecho cmd)
)
)
)
)
(princ)
)
;;
;;
;;
;;
;;

Intersections Lee Mac


Returns a list of all points of intersection between two objects.
obj1,obj2 [vla] VLAObjects with intersectwith method applicable
mode
[int] acextendoption enum of intersectwith method
Returns: [lst] List of 3D WCS intersection points, else nil

(defun LM:Intersections ( obj1 obj2 mode / l r )


(setq l (vlaxinvoke obj1 intersectwith obj2 mode))
(repeat (/ (length l) 3)
(setq r (cons (list (car l) (cadr l) (caddr l)) r)
l (cdddr l)
)
)
(reverse r)
)
Page 11

PRICOL
;;=={ Block BoundingBox }==;;
;;
;;
;; Returns a point list describing a rectangular frame
;;
;; bounding all geometry of a supplied block reference.
;;
;; Excludes Text, MText & Attribute Definitions.
;;
;;;;
;; Author: Lee Mac, Copyright 2013 www.leemac.com
;;
;;;;
;; Arguments:
;;
;; blk VLA Block Reference Object
;;
;;;;
;; Returns: WCS Point list describing boundingbox of block ;;
;;;;
(defun LM:blockboundingbox ( blk / bnm llp lst urp )
(setq bnm (strcase (vlagetname blk)))
(cond
( (setq lst (cdr (assoc bnm *blockboundingboxes*))))
( (progn
(vlaxfor obj (vlaitem (LM:acblk) bnm)
(cond
( (= "AcDbBlockReference" (vlagetobjectname obj))
(setq lst (append lst (LM:blockboundingbox obj)))
)
( (and
(= :vlaxtrue (vlagetvisible obj))
(not (wcmatch (vlagetobjectname obj) "AcDbAttributeDefinition,AcDb*Text"))
(vlaxmethodapplicablep obj getboundingbox)
(not (vlcatchallerrorp (vlcatchallapply vlagetboundingbox (list obj
llp urp))))
)
(setq lst (vllist* (vlaxsafearray>list llp) (vlaxsafearray>list urp) lst))
)
)
)
(setq lst (mapcar (lambda ( fun ) (apply mapcar (cons fun lst))) (min max)))
(setq lst
(list
(car lst)
(list (caadr lst) (cadar lst))
(cadr lst)
(list (caar lst) (cadadr lst))
)
)
(setq *blockboundingboxes* (cons (cons bnm lst) *blockboundingboxes*))
)
)
)
(apply
(function
(lambda ( m v )
(mapcar (function (lambda ( p ) (mapcar + (mxv m p) v))) lst)
)
)
(refgeom (vlaxvlaobject>ename blk))
)
)
;;
;;
;;
;;
;;

RefGeom (gile)
Returns a list which first item is a 3x3 transformation matrix (rotation,
scales, normal) and second item the object insertion point in its parent
(xref, block or space)
Page 12

PRICOL
;; Argument : an ename
(defun refgeom ( ent / ang ang mat ocs )
(setq enx (entget ent)
ang (cdr (assoc 050 enx))
ocs (cdr (assoc 210 enx))
)
(list
(setq mat
(mxm
(mapcar (lambda ( v ) (trans v 0 ocs t))
(
(1.0 0.0 0.0)
(0.0 1.0 0.0)
(0.0 0.0 1.0)
)
)
(mxm
(list
(list (cos ang) ( (sin ang)) 0.0)
(list (sin ang) (cos ang)
0.0)
(0.0 0.0 1.0)
)
(list
(list (cdr (assoc 41 enx)) 0.0 0.0)
(list 0.0 (cdr (assoc 42 enx)) 0.0)
(list 0.0 0.0 (cdr (assoc 43 enx)))
)
)
)
)
(mapcar (trans (cdr (assoc 10 enx)) ocs 0)
(mxv mat (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 enx))))))
)
)
)
;; Matrix x Vector Vladimir Nesterovsky
;; Args: m nxn matrix, v vector in R^n
(defun mxv ( m v )
(mapcar (lambda ( r ) (apply + (mapcar * r v))) m)
)
;; Matrix Transpose Doug Wilson
;; Args: m nxn matrix
(defun trp ( m )
(apply mapcar (cons list m))
)
;; Matrix x Matrix Vladimir Nesterovsky
;; Args: m,n nxn matrices
(defun mxm ( m n )
((lambda ( a ) (mapcar (lambda ( r ) (mxv a r)) m)) (trp n))
)
;; Start Undo Lee Mac
;; Opens an Undo Group.
(defun LM:startundo ( doc )
(LM:endundo doc)
(vlastartundomark doc)
Page 13

PRICOL
)
;; End Undo Lee Mac
;; Closes an Undo Group.
(defun LM:endundo ( doc )
(while (= 8 (logand 8 (getvar undoctl)))
(vlaendundomark doc)
)
)
;; Active Document Lee Mac
;; Returns the VLA Active Document Object
(defun LM:acdoc nil
(eval (list defun LM:acdoc nil (vlagetactivedocument (vlaxgetacadobject))))
(LM:acdoc)
)
;; Block Collection Lee Mac
;; Returns the VLA Block Collection Object
(defun LM:acblk nil
(eval (list defun LM:acblk nil (vlagetblocks (LM:acdoc))))
(LM:acblk)
)
;;;;
(if (null (getenv "LMac\\ABBRotation"))
(setenv "LMac\\ABBRotation" "ON")
)
;;;;
(vlloadcom)
(princ
(strcat
"\n:: AutoBlockBreak.lsp | Version 1.6 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,0,yyyy)")
" www.leemac.com ::"
"\n:: Type \"ABB\" to insert & break or \"ABBE\" / \"ABBS\" to break existing ::"
)
)
(princ)
;;;;
;;
End of File
;;
;;;;
_______________________________________________________________________________________
_________________________________________________________________________

(DEFUN C:1()
(COMMAND "LAYUNISO")
Page 14

PRICOL
)
_______________________________________________________________________________________
_______________________________________________________________________________________
___________________________
(DEFUN C:0()
(COMMAND "LAYISO")

)
_______________________________________________________________________________________
_______________________________________________________________________________________
___________________________

(defun c:6()
(command "refedit")
)
_______________________________________________________________________________________
________________________________________________________________
; ELECTRICAL PLAN POINTS
(defun c:NP(/ ss cnt blkname donelist Grp Update)
(command "layer" "n" "NEW POINTS" "co" 3 "NEW POINTS" "")

(defun Grp (gc el) (cdr (assoc gc el)))


(defun Update (bname / ename elist)
(setq ename (tblobjname "BLOCK" bname))
(while ename
(setq elist (entget ename ("*"))
elist (subst (8 . "0") (assoc 8 elist) elist)
elist (if (assoc 62 elist) (subst (62 . 0) (assoc 62 elist) elist) (append elist ((62 . 0)))))
(entmake elist)
(setq ename (entnext ename)))
(if (/= "ENDBLK" (Grp 0 elist)) (entmake ((0 . "ENDBLK") (8 . "0") (62 . 0))))
)
(if (> (logand (Grp 70 (tblsearch "layer" "0")) 1) 0)
(princ "\nLayer 0 must be thawed before running FIXBLOCK!\n")
(progn
(if
(progn
(princ "\nPress <Enter> to fix all defined blocks\n")
(setq ss (ssget ((0 . "INSERT")))))
(progn
(setq cnt (sslength ss))
(while (>= (setq cnt (1 cnt)) 0)
(if (not (member (setq blkname (Grp 2 (entget (ssname ss cnt)))) donelist))
(progn
Page 15

PRICOL
(Update blkname)
(setq donelist (cons blkname donelist)))))
(setq cnt (sslength ss)))
(progn
(setq cnt 0)
(while (setq blkname (Grp 2 (tblnext "BLOCK" (not blkname))))
(Update blkname)
(setq cnt (1+ cnt)))))
(princ (strcat "\n" (itoa cnt) " block" (if (= cnt 1) "" "s") " redefined\n"))))
(COMMAND "CHANGE" SS "" "P" "LA" "NEW POINTS" "")
(COMMAND "CHANGE" SS "" "P" "CO" 3 "")
(princ)
)
;Endoffile
_______________________________________________________________________________________
_________________________________________________________________
(defun c:CP(/ ss cnt blkname donelist Grp Update)
(command "layer" "n" "CHANGEPOINTS" "co" 1 "CHANGEPOINTS" "")
(defun Grp (gc el) (cdr (assoc gc el)))
(defun Update (bname / ename elist)
(setq ename (tblobjname "BLOCK" bname))
(while ename
(setq elist (entget ename ("*"))
elist (subst (8 . "0") (assoc 8 elist) elist)
elist (if (assoc 62 elist) (subst (62 . 0) (assoc 62 elist) elist) (append elist ((62 . 0)))))
(entmake elist)
(setq ename (entnext ename)))
(if (/= "ENDBLK" (Grp 0 elist)) (entmake ((0 . "ENDBLK") (8 . "0") (62 . 0))))
)
(if (> (logand (Grp 70 (tblsearch "layer" "0")) 1) 0)
(princ "\nLayer 0 must be thawed before running FIXBLOCK!\n")
(progn
(if
(progn
(princ "\nPress <Enter> to fix all defined blocks\n")
(setq ss (ssget ((0 . "INSERT")))))
(progn
(setq cnt (sslength ss))
(while (>= (setq cnt (1 cnt)) 0)
(if (not (member (setq blkname (Grp 2 (entget (ssname ss cnt)))) donelist))
(progn
(Update blkname)
(setq donelist (cons blkname donelist)))))
(setq cnt (sslength ss)))
(progn
(setq cnt 0)
(while (setq blkname (Grp 2 (tblnext "BLOCK" (not blkname))))
(Update blkname)
(setq cnt (1+ cnt)))))
(princ (strcat "\n" (itoa cnt) " block" (if (= cnt 1) "" "s") " redefined\n"))))
(COMMAND "CHANGE" SS "" "P" "LA" "CHANGEPOINTS" "")
(COMMAND "CHANGE" SS "" "P" "CO" 1 "")
(princ)
)
;Endoffile
Page 16

PRICOL
_______________________________________________________________________________________
_________________________________________________________________
(defun c:SP(/ ss cnt blkname donelist Grp Update)
(command "layer" "n" "STANDARDPOINTS" "co" 7 "STANDARDPOINTS" "")
(defun Grp (gc el) (cdr (assoc gc el)))
(defun Update (bname / ename elist)
(setq ename (tblobjname "BLOCK" bname))
(while ename
(setq elist (entget ename ("*"))
elist (subst (8 . "0") (assoc 8 elist) elist)
elist (if (assoc 62 elist) (subst (62 . 0) (assoc 62 elist) elist) (append elist ((62 . 0)))))
(entmake elist)
(setq ename (entnext ename)))
(if (/= "ENDBLK" (Grp 0 elist)) (entmake ((0 . "ENDBLK") (8 . "0") (62 . 0))))
)
(if (> (logand (Grp 70 (tblsearch "layer" "0")) 1) 0)
(princ "\nLayer 0 must be thawed before running FIXBLOCK!\n")
(progn
(if
(progn
(princ "\nPress <Enter> to fix all defined blocks\n")
(setq ss (ssget ((0 . "INSERT")))))
(progn
(setq cnt (sslength ss))
(while (>= (setq cnt (1 cnt)) 0)
(if (not (member (setq blkname (Grp 2 (entget (ssname ss cnt)))) donelist))
(progn
(Update blkname)
(setq donelist (cons blkname donelist)))))
(setq cnt (sslength ss)))
(progn
(setq cnt 0)
(while (setq blkname (Grp 2 (tblnext "BLOCK" (not blkname))))
(Update blkname)
(setq cnt (1+ cnt)))))
(princ (strcat "\n" (itoa cnt) " block" (if (= cnt 1) "" "s") " redefined\n"))))
(COMMAND "CHANGE" SS "" "P" "LA" "STANDARDPOINTS" "")
(COMMAND "CHANGE" SS "" "P" "CO" 7 "")
(princ)
)
;Endoffile
_______________________________________________________________________________________
_________________________________________________________________
;;=={ Copy/Rename Block Reference }==;;
;;
;;
;; This program allows a user to copy and/or rename a single block
;;
;; reference in the working drawing.
;;
;;
;;
;; Many existing programs enable the user to rename the block
;;
;; definition for a given block reference, with the new name
;;
;; subsequently reflected across all references of the block
;;
;; definition in the drawing. However, this program will allow a
;;
;; single selected block reference to be renamed (or for the user to ;;
;; create a renamed copy of the selected block reference), by
;;
;; generating a duplicate renamed block definition for the selected
;;
;; block.
;;
;;
;;
Page 17

PRICOL
;; The program may be called from the commandline using either CB ;;
;; to create a renamed copy of a selected block reference, or RB to ;;
;; simply rename the selected block reference.
;;
;;
;;
;; Following selection of a block reference, the user is prompted to ;;
;; specify a name for the selected/copied block reference; a default ;;
;; block name composed of the original block name concatenated with
;;
;; both an underscore and the minimum integer required for uniqueness ;;
;; within the block collection of the active drawing is offered.
;;
;;
;;
;; The program will then proceed to duplicate the block definition
;;
;; using the new block name. To accomplish this without resulting in ;;
;; a duplicate key in the block collection of the active drawing, the ;;
;; program utilises an ObjectDBX interface to which the block
;;
;; definition of the selected block reference is deepcloned, renamed, ;;
;; and then deepcloned back to the active drawing. This method also ;;
;; enables Dynamic Block definitions to be successfully copied
;;
;; & renamed.
;;
;;
;;
;; Finally, this program will perform successfully in all UCS/Views
;;
;; and is compatible with Anonymous Blocks, Dynamic Blocks & XRefs.
;;
;;;;
;; Author: Lee Mac, Copyright 2013 www.leemac.com
;;
;;;;
;; Version 1.5

05072013
;;
;;;;
(defun c:cb nil (LM:RenameBlockReference t))
(defun c:rb nil (LM:RenameBlockReference nil))
(defun LM:RenameBlockReference ( cpy / *error* abc app dbc dbx def doc dxf new old prp src tmp vrs )
(defun *error* ( msg )
(if (and (= vlaobject (type dbx)) (not (vlaxobjectreleasedp dbx)))
(vlaxreleaseobject dbx)
)
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(while
(progn
(setvar errno 0)
(setq src (car (entsel (strcat "\nSelect block reference to " (if cpy "copy & " "") "rename: "))))
(cond
( (= 7 (getvar errno))
(princ "\nMissed, try again.")
)
( (= ename (type src))
(setq dxf (entget src))
(cond
( (/= "INSERT" (cdr (assoc 0 dxf)))
(princ "\nPlease select a block reference.")
)
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 dxf)))))))
(princ "\nSelected block is on a locked layer.")
)
)
)
)
)
)
Page 18

PRICOL
(if (= ename (type src))
(progn
(setq app (vlaxgetacadobject)
doc (vlagetactivedocument app)
src (vlaxename>vlaobject src)
old (vlaxgetproperty src (if (vlaxpropertyavailablep src effectivename)
effectivename name))
tmp 0
)
(while (tblsearch "block" (setq def (strcat (vlstringlefttrim "*" old) "_" (itoa (setq tmp (1+
tmp)))))))
(while
(and (/= "" (setq new (getstring t (strcat "\nSpecify new block name <" def ">: "))))
(or (not (snvalid new))
(tblsearch "block" new)
)
)
(princ "\nBlock name invalid or already exists.")
)
(if (= "" new)
(setq new def)
)
(setq dbx
(vlcatchallapply vlagetinterfaceobject
(list app
(if (< (setq vrs (atoi (getvar acadver))) 16)
"objectdbx.axdbdocument"
(strcat "objectdbx.axdbdocument." (itoa vrs))
)
)
)
)
(if (or (null dbx) (vlcatchallerrorp dbx))
(princ "\nUnable to interface with ObjectDBX.")
(progn
(setq abc (vlagetblocks doc)
dbc (vlagetblocks dbx)
)
(vlaxinvoke doc copyobjects (list (vlaitem abc old)) dbc)
(if (wcmatch old "**")
(vlaputname (vlaitem dbc (1 (vlagetcount dbc))) new)
(vlaputname (vlaitem dbc old) new)
)
(vlaxinvoke dbx copyobjects (list (vlaitem dbc new)) abc)
(vlaxreleaseobject dbx)
(if cpy (setq src (vlacopy src)))
(if
(and
(vlaxpropertyavailablep src isdynamicblock)
(= :vlaxtrue (vlagetisdynamicblock src))
)
(progn
(setq prp (mapcar vlagetvalue (vlaxinvoke src getdynamicblockproperties)))
(vlaputname src new)
(mapcar
(lambda ( a b )
(if (/= "ORIGIN" (strcase (vlagetpropertyname a)))
(vlaputvalue a b)
)
)
(vlaxinvoke src getdynamicblockproperties) prp
)
)
(vlaputname src new)
Page 19

PRICOL
)
(if (= :vlaxtrue (vlagetisxref (setq def (vlaitem (vlagetblocks doc) new))))
(vlareload def)
)
(if cpy (sssetfirst nil (ssadd (vlaxvlaobject>ename src))))
)
)
)
)
(princ)
)
;;;;
(vlloadcom)
(princ
(strcat
"\n:: CopyRenameBlock.lsp | Version 1.5 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,$(getvar,date),YYYY)")
" www.leemac.com ::"
"\n:: Available Commands:"
"\n::
\"CB\" Copy & Rename Block Reference."
"\n::
\"RB\" Rename Block Reference."
)
)
(princ)
;;;;
;;
End of File
;;
;;;;
_______________________________________________________________________________________
_______________________________________________________________________________________
_________________________________
(DEFUN C:OM();ENTER VALUE IN FEET CONVERT MM VALUE IN OFFSE
(COMMAND "LUNITS" 4)
(SETQ

ED(GETDIST "\n ENTER OFFSET DISTANCE :")


SS(ENTSEL)
ST(GETPOINT "\n SPECIFY POINT ON SIDE:")
FI(*(* 0.0833333333 ED)12)
MM(/ FI 0.04)

)
(COMMAND "OFFSET" MM SS ST "")
Page 20

PRICOL
(COMMAND "LUNITS" 2)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
______________________________
(defun C:TM (/ str basept ss n); = Text Mark
(setq
str (getstring "\nText content to mark: ")
basept (getpoint "\nBase point for marking Lines: ")
); setq
; (COMMAND "LAYER" "N" STR "" )(COMMAND "LAYER" "S" STR "" )
(if
(setq ss (ssget "_X" (list (0 . "TEXT") (cons 1 str) (cons 410 (getvar CTAB)))))
(repeat (setq n (sslength ss)); then
(entmake
(list
(0 . "LINE")
(cons 10 basept)
(cons 11 (cdr (assoc 10 (entget (ssname ss (setq n (1 n)))))))
); list
); entmake
); repeat
(alert "No Text found with that content."); else
); if
(alert (strcat (strcase str) "\t" "=" "\t" (itoa (sslength ss)) "Nos"))
(princ)
); defun
_______________________________________________________________________________________
_______________________________________________________________________________________
__________________________
(defun C:MTM (/ str basept ss n); = MText Mark
(setq
str (getstring "\nText content to mark: ")
basept (getpoint "\nBase point for marking Lines: ")
); setq
;(COMMAND "LAYER" "N" STR "" )(COMMAND "LAYER" "S" STR "" )
(if
(setq ss (ssget "_X" (list (0 . "MTEXT") (cons 1 str) (cons 410 (getvar CTAB)))))
(repeat (setq n (sslength ss)); then
(entmake
(list
(0 . "LINE")
(cons 10 basept)
(cons 11 (cdr (assoc 10 (entget (ssname ss (setq n (1 n)))))))
); list
); entmake
); repeat
(alert "No Text found with that content."); else
); if
(alert (strcat (strcase str) "\t" "=" "\t" (itoa (sslength ss)) "Nos"))
(princ)
); defun
_______________________________________________________________________________________
_______________________________________________________________________________________
_____________________________
(defun C:BM (/ str basept ss n); = BLOCK Mark
Page 21

PRICOL
(setq
str (getstring "\nText content to mark: ")
basept (getpoint "\nBase point for marking Lines: ")
); setq
(COMMAND "LAYER" "N" STR "" )(COMMAND "LAYER" "S" STR "" )
(if
(setq ss (ssget "_X" (list (0 . "insert") (cons 2 str) (cons 410 (getvar CTAB)))))
(repeat (setq n (sslength ss)); then
(entmake
(list
(0 . "LINE")
(cons 10 basept)
(cons 11 (cdr (assoc 10 (entget (ssname ss (setq n (1 n)))))))
); list
); entmake
); repeat
(alert "No Text found with that content."); else
); if
(alert (strcat (strcase str) "\t" "=" "\t" (itoa (sslength ss)) "Nos"))
(princ)
); defun
_______________________________________________________________________________________
_______________________________________________________________________________________
_______________________________
;;; Function to get the block data
(defun getAttData(/ eset hdrStr dataList blkCntr en enlist blkType blkName entName
entPoint entRot entX entY entZ entLay attTag attVal entSty entClr
dStr group66)
;;; Set up an empty list
(setq dataList(list))
;;; If that type of entity exist in drawing
(if (setq eset(ssget "X" (list (cons 0 "INSERT"))))
(progn
;;; Set up some counters
(setq blkCntr 0 cntr 0)
;;; Loop through each entity
(while (< blkCntr (sslength eset))
;;; Get the entitys name
(setq en(ssname eset blkCntr))
;;; Get the DXF group codes of the entity
(setq enlist(entget en))
;;; Get the name of the block
(setq blkName(cdr(assoc 2 enlist)))
;;; Check to see if the blocks attribute flag is set
(if(cdr(assoc 66 enlist))
(progn
;;; Get the entity name
(setq en(entnext en))
;;; Get the entity dxf group codes
(setq enlist(entget en))
Page 22

PRICOL
;;; Get the type of block
(setq blkType (cdr(assoc 0 enlist)))
;;; If group 66 then there are attributes nested inside this block
(setq group66(cdr(assoc 66 enlist)))
;;; Loop while the type is an attribute or a nested attribute exist
(while(or (= blkType "ATTRIB")(= group66 1))
;;; Get the block type
(setq blkType (cdr(assoc 0 enlist)))
;;; Get the block name
(setq entName (cdr(assoc 2 enlist)))
;;; Check to see if this is an attribute or a block
(if(= blkType "ATTRIB")
(progn
;;; Save the name of the attribute
(setq attTag(cdr(assoc 2 enlist)))
;;; Get the value of the attribute
(setq attVal(cdr(assoc 1 enlist)))
;;; Save the data gathered
(setq dataList(append dataList(list (list blkName attTag attVal))))
;;; Increment the counter
(setq cntr (+ cntr 1))
;;; Get the next subentity or nested entity as you will
(setq en(entnext en))
;;; Get the dxf group codes of the next subentity
(setq enlist(entget en))
;;; Get the block type of the next subentity
(setq blkType (cdr(assoc 0 enlist)))
;;; See if the dxf group code 66 exist. if so, there are more nested attributes
(setq group66(cdr(assoc 66 enlist)))
)
)
)
)
;;; Else, the block does not contain attributes
(progn
;;; Setup a bogus tag and value
(setq attTag "" attVal "")
;;; Save the data gathered
(setq dataList(append dataList(list (list blkName attTag attVal))))
)
)
(setq blkCntr (+ blkCntr 1))
)
)
)
dataList
)
Page 23

PRICOL

;;; Function to count occurences within a list


(defun goCountData(ele lst / cnt a)
(setq cnt 0)
(foreach a lst
(if(equal a ele)
(setq cnt(+ cnt 1))
)
)
cnt
)

;;; Function to update the data


(defun updateData()
;;; Setup a list to hold the selected items
(setq blkDataList(list))
;;; Save the list setting
(setq readlist(get_tile "blklist"))
;;; Setup a variable to run through the list
(setq count 1)
;;; cycle through the list getting all of the selected items
(while (setq item (read readlist))
(setq blkDataList(append blkDataList (list (nth item blkList))))
(while
(and
(/= " " (substr readlist count 1))
(/= "" (substr readlist count 1))
)
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
;;; Setup a list to hold the selected items
(setq tagDataList(list))
;;; Save the list setting
(setq readlist(get_tile "taglist"))
;;; Setup a variable to run through the list
(setq count 1)
;;; cycle through the list getting all of the selected items
(while (setq item (read readlist))
(setq tagDataList(append tagDataList (list (nth item tagList))))
(while
(and
(/= " " (substr readlist count 1))
(/= "" (substr readlist count 1))
)
(setq count (1+ count))
)
(setq readlist (substr readlist count))
Page 24

PRICOL
)
;;; Setup a list to hold the selected items
(setq valDataList(list))
;;; Save the list setting
(setq readlist(get_tile "vallist"))
;;; Setup a variable to run through the list
(setq count 1)
;;; cycle through the list getting all of the selected items
(while (setq item (read readlist))
(setq valDataList(append valDataList (list (nth item valList))))
(while
(and
(/= " " (substr readlist count 1))
(/= "" (substr readlist count 1))
)
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
;;; Set up a list to hold all data that matches the block name
(setq myData(list))
;;; Cycle through all data and find block name matches
(foreach a dataList
(if(or(member "All" blkDataList)(member (car a) blkDataList))
(setq myData(append myData (list a)))
)
)
;;; Set up a list to hold the data that matches the tag name
(setq myData2(list))
;;; Filter through all previous matches to find tag matches
(foreach a myData
(if(or(member "All" tagDataList)(member (cadr a) tagDataList))
(setq myData2(append myData2 (list a)))
)
)
;;; Filter the previous matches for attribute value matches
(setq myData3(list))
(foreach a myData2
(if(or(member "All" valDataList)(member (caddr a) valDataList))
(setq myData3(append myData3 (list a)))
)
)
;;; Set up a list to hold the used data [old data]
(setq usedData(list))
;;; Reset the orignal list to hold the new data
(setq myData(list))
;;; Cycle through each match
(foreach a myData3
;;; Make sure we havent counted it already
(if(not(member a usedData))
Page 25

PRICOL
(progn
;;; Count the number of times the match appears in the list
(setq cnt(goCountData a myData3))
;;; Add the data and the count to the new list
(setq myData(append myData (list(list cnt a))))
;;; Add the data to the used list so we dont count it twice
(setq usedData(append usedData (list a)))
)
)
)
;;; Set up a list to hold the formatted data for the dialog box
(setq newData(list))
;;; If new data was found
(if myData
(progn
;;; Format the data
(foreach a myData
(setq qty(substr (strcat
(setq bna(substr (strcat
(setq tgn(substr (strcat
(setq van(substr (strcat

(itoa (car a))"


(car (cadr a)) "
(cadr (cadr a)) "
(caddr(cadr a)) "

") 1 6))
") 1 20))
") 1 20))
") 1 20))

;;; Add it to the new data list


(setq newData(append newData (list (strcat qty bna tgn van))))
)
;;; Add a horizontal line
(setq newData
(append
(list
""
)
newData
)
)
;;; Add a header
(setq newData
(append
(list
"Qty. Block Name
)
newData
)
)

Tag

Value"

;;; Add the list to the dialog box


(start_list "totallist" 3)
(mapcar add_list newData)
(end_list)
)
(progn
;;; Clear the list in the dialog box
(start_list "totallist" 3)
(mapcar add_list newData)
(end_list)
)
Page 26

PRICOL
)
)

;;; Function to sort a list


;;;
;;; Usage (sort (list "F" "A" "B"))
;;;
(defun sort(alist / n)(setq lcup nil rcup nil)
(defun cts(a b)
(cond
((> a b)t)
((= a b )t)
(t nil)
))
(foreach n alist
(while (and rcup(cts n(car rcup)))(setq lcup(cons(car rcup)lcup)rcup(cdr rcup)))
(while (and lcup(cts(car lcup)n))(setq rcup(cons(car lcup)rcup)lcup(cdr lcup)))
(setq rcup(cons n rcup))
)
(append(reverse lcup)rcup)
)

;;; Function to write the data to a file


(defun writeData()
;;; Set up a counter
(setq lineCntr 0)
;;; Get a file name from the user
(if(setq filName(getfiled "Select File Name" "" "csv" 1))
(progn
;;; Open the file to write
(if(setq fil(open filName "w"))
(progn
;;; Print a header string
(princ "QTY.,Block Name,Tag,Value\n" fil)
(foreach a myData
(princ (strcat (itoa(car a)) "," (car(cadr a))","(cadr(cadr a))","(caddr(cadr a))"\n") fil)
(setq lineCntr(+ lineCntr 1))
)
;;; Close the file
(close fil)
(alert
(strcat "Finished Sending " (itoa lineCntr)
" lines to the CSV file!\n\nNote: Double click the CSV file and Excel will open it."
)
)
)
(princ "\n ERROR Could not open CSV file!")
)
)
(princ "\n ERROR Invalid file name!")
)
Page 27

PRICOL
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;
;;;
888
888
888
8888888
8888 888
;;;
;;;
8888
8888
88888
888
88888 888
;;;
;;;
88888 88888
888 888
888
888888 888
;;;
;;;
888888 888888
888 888
888
888 888888
;;;
;;;
888 88888 888
88888888888
888
888 88888
;;;
;;;
888 888 888
888
888
8888888
888 8888
;;;
;;;
;;;
;;;
;;;
;;;
888
888888888
888888888
;;;
;;;
88888
888 888
888 888
;;;
;;;
888 888
888 888
888 888
;;;
;;;
888 888
888888888
888888888
;;;
;;;
88888888888
888
888
;;;
;;;
888
888
888
888
;;;
;;;
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun C:BLOCKS()
;;; Setup an empty list to hold all of the data
(setq myData(list))
;;; Get a the data from the blocks
(if(setq dataList(getattData))
(progn
;;; Setup list to hold the block names, tag names, and values
(setq blkList(list) tagList(list) valList(list))
;;; Seperate the data
(foreach a dataList
(if(not (member (car a) blkList))
(setq blkList(append blkList (list (car a))))
)
(if(not (member (cadr a) tagList))
(setq tagList(append tagList (list (cadr a))))
)
(if(not (member (caddr a) valList))
(setq valList(append valList (list (caddr a))))
)
)
;;; Sort the list
(setq blkList(sort blkList))
(setq tagList(sort tagList))
(setq valList(sort valList))
;;; Add the "ALL" option
(setq blkList(append (list "All") blkList))
(setq tagList(append (list "All") tagList))
(setq valList(append (list "All") valList))
;;; Build the data list
(setq blkDataList blkList tagDataList tagList valDataList valList)
Page 28

PRICOL
;;; Put up the dialog box
(setq dcl_id (load_dialog "BLOCKS.dcl"))
;;; See if it is already loaded
(if (not (new_dialog "BLOCKS" dcl_id))
(progn
(alert "The BLOCKS.DCL file could not be found!")
(exit)
)
)
;;; Add the list to the dialog box
(start_list "blklist" 3)
(mapcar add_list blkList)
(end_list)
(start_list "taglist" 3)
(mapcar add_list tagList)
(end_list)
(start_list "vallist" 3)
(mapcar add_list valList)
(end_list)
(updateData)
;;; If an action event occurs, do this function
(action_tile "blklist" "(updateData)")
(action_tile "taglist" "(updateData)")
(action_tile "vallist" "(updateData)")
(action_tile "write" "(writeData)")
(action_tile "cancel" "(done_dialog)")
;;; Display the dialog box
(start_dialog)
)
(alert "No blocks with attributes found in drawing!")
)
(princ)
)
_______________________________________________________________________________________
__________________________________________________________________
(defun c:tfind()
(tfindfun nil nil 0)
)
(defun tfindfun(inputF inputR caseSn / goto goWhile strinF strinR selSet selTxt searep case count
error)
; 01 Create selection set. GOTO 02 if success, or GOTO 08 if fail
; 02 Check passed input. If both nil, GOTO 03. If first string and second nil, GOTO 06. If both strings,
GOTO 07. Otherwise, return error and GOTO 08
; 03 Display menus and obtain data from user. If Search, GOTO 04. If Replace, GOTO 05
; 04 Search option selected. Prompt user for single search term. GOTO 06
; 05 Replace option selected. Prompt user for search term and replace term. GOTO 07
; 06 One string has been passed. Assume automatic search. Run same as current (tfind). GOTO FINISH
; 07 Two strings have been passed. Assume automatic replace. Pass both strings to (replace) function.
GOTO FINISH
; 08 FINISH. Return errors if needed. End loop and program.
(vlloadcom)
(setq goTo 1)
(setq goWhile 1)
Page 29

PRICOL
(setq count 0)
(if (not (mlml (list caseSn) (list 0 1))) (progn (setq goWhile nil) (princ "\nCase selection not
recognized.")))
(if (= caseSn 0) (setq case "N") (setq case "Y"))
(while goWhile
(cond
((= goTo 1)
(setq selSet (extTxtPt (ssget "_X" (list (cons 4 "<OR") (cons 0 "TEXT,MTEXT") (cons 4 "<AND")
(cons 0 "INSERT") (cons 66 1) (cons 4 "AND>") (cons 4 "OR>")))))
(if selSet (setq goTo 2) (setq error "\nSelection set not found." goTo 8))
)
((= goTo 2)
; Check input, pass to whatever.
(cond
((and (= inputF nil) (= inputR nil))
(setq goTo 3)
)
((and (= (type inputF) STR) (= inputR nil))
(setq strinF inputF)
(setq goTo 6)
)
((and (= (type inputF) STR) (= (type inputR) STR))
(setq strinF inputF)
(setq strinR inputR)
(setq goTo 7)
)
(t
(setq error "\nPassed arguments are not accepted.")
(setq goTo 8)
)
)
)
((= goTo 3)
; Obtain desired option from user
(while (not (mlml (list (setq searep (strcase (getstring nil "\nSelect option
[Find/Replace/Quit/Case]: "))))
(list "F" "FIND" "R" "REPLACE" "Q" "QUIT" "C" "CASE")
))
)
(cond
((mlml (list searep) (list "F" "FIND"))
(setq goTo 4)
)
((mlml (list searep) (list "R" "REPLACE"))
(setq goTo 5)
)
((mlml (list searep) (list "Q" "QUIT"))
(setq goTo 8)
)
((mlml (list searep) (list "C" "CASE"))
(while (not (mlml (list (setq case (strcase (getstring nil "\nCase sensitive? [Yes/No]: "))))
(list "Y" "YES" "N" "NO")
))
)
)
)
)
((= goTo 4)
; Obtain search string from user, set to strinF
(while (eq "" (setq strinF (getstring T "\nEnter search term: "))))
(setq goTo 6)
)
((= goTo 5)
; Obtain search string and replace string from user, set to strinF and strinR respectively
Page 30

PRICOL
(while (eq "" (setq strinF (getstring T "\nEnter find term: "))))
(while (eq "" (setq strinR (getstring T "\nEnter replace term: "))))
(setq goTo 7)
)
((= goTo 6)
; Search drawing for strinF
(cond
((mlml (list case) (list "Y" "YES"))
; Compare using (vlstringsearch strinF input), view selection
; use "while" to get all search occurances
(foreach selVar selSet
(if (vlstringsearch strinF (nth 0 selVar))
(progn
(setq count (1+ count))
(if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
(command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar)))
(getstring "\nPress Enter to continue: ")
)
)
)
)
((mlml (list case) (list "N" "NO"))
; Compare using (vlstringsearch (strcase strinF) (strcase input)), view selection
; use "while" to get all search occurances
(foreach selVar selSet
(if (vlstringsearch (strcase strinF) (strcase (nth 0 selVar)))
(progn
(setq count (1+ count))
(if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
(command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar)))
(getstring "\nPress Enter to continue: ")
)
)
)
)
)
(if (= count 0) (setq error "\nNo matches found.") (setq error (strcat (itoa count) " matches
found.")))
(setq goTo 8)
)
((= goTo 7)
; Replace strinF with strinR
(cond
((mlml (list case) (list "Y" "YES"))
; Compare using (vlsearchstring strinF input), modify using (vlstringsubst) within a while loop
(foreach selVar selSet
(setq selTxt (nth 0 selVar))
(setq seaLoc 0)
(while (setq seaLoc (vlstringsearch strinF selTxt seaLoc))
(setq selTxt (vlstringsubst strinR strinF selTxt seaLoc))
(setq seaLoc (+ seaLoc (strlen strinR)))
(setq count (1+ count))
)
(vlaputTextString (vlaxename>vlaobject (nth 4 selVar)) selTxt)
)
)
((mlml (list case) (list "N" "NO"))
; Compare using (vlstringsearch (strcase strinF) (strcase input)), modify using (vlstringsubst)
within a while loop
(foreach selVar selSet
(setq selTxt (nth 0 selVar))
(setq seaLoc 0)
(while (setq seaLoc (vlstringsearch (strcase strinF) (strcase selTxt) seaLoc))
(setq selTxt (strcat (substr selTxt 1 seaLoc) strinR (substr selTxt (+ 1 seaLoc (strlen
Page 31

PRICOL
strinF)))))
(setq seaLoc (+ seaLoc (strlen strinR)))
(setq count (1+ count))
)
(vlaputTextString (vlaxename>vlaobject (nth 4 selVar)) selTxt)
)
)
)
(if (= count 0) (setq error "\nNo occurances found.") (setq error (strcat (itoa count) " occurances
modified.")))
(setq goTo 8)
)
((= goTo 8)
(if error (princ error))
(setq goWhile nil)
)
)
)
(princ)
)
(defun mlml(inSMLChar inSMLStri / returnVarMS toCheck chkWith)
(setq returnVarMS nil)
(if (and (= (type inSMLChar) LIST)
(= (type inSMLStri) LIST)
)
(progn
(foreach toCheck inSMLStri
(foreach chkWith inSMLChar
(if (eq toCheck chkWith) (setq returnVarMS T))
)
)
);/progn
)
returnVarMS
); Checks a list to see if a member of that list is the same as a member of another list. Returns T or
nil
(defun extTxtPt(ssList / subVar getEnt entTyp entTxt entPnt entLay entHgt grp66 entAtt getEntAtt
entAttTyp uniLst)
(setq uniLst nil)
(setq subVar 0)
(if ssList
(repeat (sslength ssList)
(setq getEnt (entget (cadr (car (ssnamex ssList subVar)))))
(setq entTyp (cdr (assoc 0 getEnt)))
(cond
((or (= entTyp "TEXT") (= entTyp "MTEXT"))
(setq entTxt (cdr (assoc 1 getEnt)))
(setq entPnt (cdr (assoc 10 getEnt)))
(setq entHgt (cdr (assoc 40 getEnt)))
(setq entLay (cdr (assoc 410 getEnt)))
(setq entNam (cdr (assoc 1 getEnt)))
(setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
)
((= entTyp "INSERT")
(setq grp66 (assoc 66 getEnt))
(if grp66
(progn
(setq entAtt (entnext (cdr (assoc 1 getEnt))))
(setq getEntAtt (entget entAtt))
(setq entAttTyp (cdr (assoc 0 getEntAtt)))
)
Page 32

PRICOL
)
(while (= entAttTyp "ATTRIB")
(setq entTxt (cdr (assoc 1 getEntAtt)))
(setq entPnt (cdr (assoc 10 getEntAtt)))
(setq entHgt (cdr (assoc 40 getEntAtt)))
(setq entLay (cdr (assoc 410 getEntAtt)))
(setq entNam (cdr (assoc 1 getEntAtt)))
(setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
; Get next entity.
(setq entAtt (entnext (cdr (assoc 1 getEntAtt))))
; Get ent and ent type
(setq getEntAtt (entget entAtt))
(setq entAttTyp (cdr (assoc 0 getEntAtt)))
)
)
(t
)
)
(setq subVar (1+ subVar))
)
)
uniLst
); Return list of all textbased objects (Text, MText, Attribute) in the current drawing
_______________________________________________________________________________________
__________________________________________________________________
(defun c:FC(/ ss l sset str e); FEET CHECK AND CONVERT IN MM
(COMMAND "lunits" 2)
(COMMAND "luprec" 0)
(SETQ
P1(GETPOINT "\n PICK HOR FIRST POINT :")
P2(GETPOINT P1 "\n PICK HOR SECOND POINT :")

DI(DISTANCE P1 P2 )

; fi(fix di)
CV(CVUNIT DI "MILLIMETER" "FOOT")
TE(RTOS (FIX DI))
P2(GETPOINT "\n PICK VER FIRST POINT :")
P3(GETPOINT P2 "\n PICK VER SECOND POINT :")
Page 33

PRICOL

DI1(DISTANCE P2 P3 )
; fi(fix di)
CV1(CVUNIT DI1 "MILLIMETER" "FOOT")
TE1(RTOS (FIX DI1))
)
(alert (strcat (RTOS (* 12 CV) 3 1) " ""x "" " (RTOS (* 12 CV1) 3 1) "\n" "\n" (rtos di) " ""x "" "(rtos di1) "
" "MM" ))

(if
(setq ss (ssget "_:L" ((0 . "TEXT,MTEXT"))))
(repeat
(setq l (sslength ss))
(setq sset (ssname ss (setq l (1 l))))
(setq str (cdr (assoc 1 (setq e (entget sset)))))
(entupd
(cdr
(assoc
1
(entmod (subst (cons 1 (strcat (rtos di) " ""x"" " (rtos di1))) (assoc 1 e) e))
)
)
)
)
(princ)
)
(princ)
(COMMAND "luprec" 2)
(VLVBALOAD "D:/PRICOL/FM.DVB")
(VLVBARUN "FM")
)
_______________________________________________________________________________________
_______________________________________________________________________________________
_____________________________
(defun c:CF(/ ss l sset str e); FEET CHECK AND CONVERT IN MM TO FEET
(COMMAND "lunits" 2)
(COMMAND "luprec" 0)
(SETQ
P1(GETPOINT "\n PICK HOR FIRST POINT :")
P2(GETPOINT P1 "\n PICK HOR SECOND POINT :")
Page 34

PRICOL

DI(DISTANCE P1 P2 )

; fi(fix di)
CV(CVUNIT DI "MILLIMETER" "FOOT")
TE(RTOS (FIX DI))
P2(GETPOINT "\n PICK VER FIRST POINT :")
P3(GETPOINT P2 "\n PICK VER SECOND POINT :")

DI1(DISTANCE P2 P3 )
; fi(fix di)
CV1(CVUNIT DI1 "MILLIMETER" "FOOT")
TE1(RTOS (FIX DI1))
)
(alert (strcat (RTOS (* 12 CV) 3 0) " ""x "" " (RTOS (* 12 CV1) 3 0) "\n" "\n" (rtos di) " ""x "" "(rtos di1) "
" "MM" ))

(if
(setq ss (ssget "_:L" ((0 . "TEXT,MTEXT"))))
(repeat
(setq l (sslength ss))
(setq sset (ssname ss (setq l (1 l))))
(setq str (cdr (assoc 1 (setq e (entget sset)))))
(entupd
(cdr
(assoc
1
(entmod (subst (cons 1 (strcat (RTOS (* 12 CV) 3 0) " ""x"" " (RTOS (* 12 CV1) 3 0))) (assoc 1 e)
e))
)
)
)
)
(princ)
)
(princ)
(COMMAND "luprec" 2)
Page 35

PRICOL
(VLVBALOAD "D:/PRICOL/FM.DVB")
(VLVBARUN "FM")
)
_______________________________________________________________________________________
_______________________________________________________________________________________
_____________________________
(DEFUN C:FTC()
(VLVBALOAD "D:/PRICOL/FM.DVB")
(VLVBARUN "FM")
)
_______________________________________________________________________________________
____________________________________________________________
(DEFUN C:0()
(COMMAND "LAYOFF" PAUSE)
)
_______________________________________________________________________________________
______________________________________________________
(defun c:eq()
(setq ent (car (entsel "\nSelect Dimension: "))
entlist (entget ent)
newtext "eq"
entlist (subst (cons 1 newtext) (assoc 1 entlist) entlist)
);setq
(entmod entlist)
)
_______________________________________________________________________________________
__________________________________________________________
(DEFUN C:CMO()
(SETQ
LN(GETSTRING "\n ENTER LAYER NAME:")
AS(GETINT"\n ENTER CLOUD SIZE:")
)
(REPEAT 10
(SETQ
P1(GETPOINT "\n PICK FIRST CORNER :")
P2(GETCORNER P1 "\n PICK FIRST CORNER :")
)

Page 36

PRICOL
(COMMAND "LAYER" "N" LN "CO" "RED" LN "")
(COMMAND "LAYER" "S" LN "")
(COMMAND "RECTANGLE" P1 P2 )(SETQ OBJ1(ENTLAST))
(COMMAND "REVCLOUD" "A" AS AS "O" OBJ1 "")
(SETQ
P3(GETPOINT "\n PICK FIRST POINT :")
P4(GETPOINT P3 "\n PICK SECOND POINT :")
P5(GETPOINT P4 "\n PICK THIRD POINT :")
)
(SETQ
JJ(getvar CLAYER)
)
(COMMAND "PLINE" P3 P4 P5 "")
(COMMAND "TEXT" P4 (/ AS 2) 0 JJ "")
)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
________________________________
(defun c:DLP( / confirm )
(princ "\nCaution: this will delete all layouts and data contained in layouts. ")
(initget 1 "Y N ") (setq confirm (getkword "\nProceed? [Yes/No] : "))
(if (or (= confirm "") (= confirm "Y"))
(vlaxfor x (vlagetlayouts (vlagetactivedocument (vlaxgetacadobject)))
(if (/= "Model" (vlagetname x)) (vladelete x) ) ) (princ "\nLayouts were not deleted. ") )
(princ)
(REPEAT 100
(command "PURGE" "A" "*" "N")
)
)
_______________________________________________________________________________________
_______________________________________________________________________________________
___________________________________
(DEFUN C:KK()
Page 37

PRICOL
(startapp "C:/AutoLisp/convert.exe")
)
_______________________________________________________________________________________
_______________________________________________________________________________________
_____________________________
;; DimPoly.lsp [command names: DPI, DPO]
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;

To dimension the lengths of all segments of a Polyline on the Inboard or Outboard


side; for selfintersecting or open Polyline without a clear "inside" and "outside,"
will determine a side if not as desired, undo and run other command.
Dimensions along arc segments will be angular Dimensions, showing length of arc
as text override, not included angle native to angular Dimensions. They will not
update if Polyline is stretched, as those along line segments will; redo DPI/DPO.
Uses current Dimension and Units settings; dimension line location distance from
Polyline segment = 1.5 x dimension text height for stacked fractions to clear [see
commentary at setting of dimtxt variable re: stacked fractions].
Accepts LW and 2D "heavy" Polylines, but not 3D Polylines or meshes.
Kent Cooper, last edited 17 March 2014

(vlloadcom)
(defun DP (side / *error* clay osm cmde styht plsel pl cw inc pt1 pt3 pt2 ang1 ang2 dimtxt pt4)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(setvar clayer clay)
(setvar osmode osm)
(command "_.undo" "_end")
(setvar cmdecho cmde)
(princ)
); defun *error*
(setq clay (getvar clayer) osm (getvar osmode) cmde (getvar cmdecho))
(setvar cmdecho 0)
(setvar osmode 0)
(command
"_.undo" "_begin"
"_.layer" "_make" "AANNODIMS" "_color" 2 "" "" ;; <EDIT Layer name/color as desired
); command
(setq styht (cdr (assoc 40 (tblsearch "style" (getvar dimtxsty))))); height of text style in current
dimension style
(if (= styht 0.0) (setq styht (* (getvar dimtxt) (getvar dimscale)))); if above is nonfixedheight
(while
(not
(and
(setq plsel (entsel "\nSelect Polyline: "))
(wcmatch (cdr (assoc 0 (entget (car plsel)))) "*POLYLINE")
(= (logand (cdr (assoc 70 (entget (car plsel)))) 88) 0)
;; not 3D or mesh [88 = 8 (3D) + 16 (polygon mesh) + 64 (polyface mesh)]
); and
); not
(prompt "\nNothing selected, or not a LW or 2D Polyline.")
); while
(setq pl (vlaxename>vlaobject (car plsel)))
(vlaoffset pl styht); temporary
(setq cw (< (vlagetarea (vlaxename>vlaobject (entlast))) (vlagetarea pl)))
;; clockwise for closed or clearly inside/outside open; may not give
;; desired result for open without obvious inside/outside
Page 38

PRICOL
(entdel (entlast))
(repeat (setq inc (fix (vlaxcurvegetEndParam pl)))
(setq
pt1 (vlaxcurvegetPointAtParam pl inc)
pt3 (vlaxcurvegetPointAtParam pl (1 inc))
); setq
(if (not (equal pt1 pt3 1e8)); not coincident vertices
(progn ; then proceed to dimension segment
(setq
pt2 (vlaxcurvegetPointAtParam pl ( inc 0.5)); segment midpoint
ang1 (angle pt1 pt2)
ang2 (angle pt2 pt3)
); setq
(if
(or ; line segment?
(equal ang1 ang2 1e8); any non0 direction or both reading as 0 or 2 pi
(equal (abs ( ang2 ang1)) (* pi 2) 1e8); 0degree with one reading as 2 pi +/
); or
(command "_.dimaligned" pt1 pt3); then [leaves at dimension line location prompt]
(progn ; else [arc segment]
(setq dimtxt
(rtos
(abs ; length along arc segment
( (vlaxcurvegetDistAtParam pl inc) (vlaxcurvegetDistAtParam pl (1 inc)))
); abs
;; [include mode/precision here if current dimension styles settings not desired]
); rtos
); setq
(if (wcmatch dimtxt "*/*"); includes fraction?
;; can omit this entire (if) function if you dont use stacked fractions
(setq dimtxt ; stack it
(strcat
"\\A1;"
(vlstringsubst ";}\"" "\""
;
(vlstringsubst "#" "/"
;; remove ; from beginning of above line and its closing parenthesis
;; below to make diagonal stack [makes horizontalline stack without]
(vlstringsubst "{\\H0.875x;\\S" " " dimtxt)
;; change 0.875 ratio to agree with Dimension Styles setting
;
); subst
); subst
); strcat & dimtxt
); setq
); if
(command
"_.dimangular" ""
(inters ; arc center
(setq pt4 (mapcar / (mapcar + pt1 pt2) (2 2 2)))
(polar pt4 (+ (angle pt1 pt2) (/ pi 2)) 1)
(setq pt4 (mapcar / (mapcar + pt2 pt3) (2 2 2)))
(polar pt4 (+ (angle pt2 pt3) (/ pi 2)) 1)
nil
); inters
pt1 pt3
"_text" dimtxt
); command [leaves at dimension line location prompt]
); progn
); if
(command ; complete Dimension: dimension line location
(polar
pt2
(apply ; angle
(if (or (and cw (= side "in")) (and (not cw) (= side "out"))) +)
(list
Page 39

PRICOL
(angle (0 0 0) (vlaxcurvegetFirstDeriv pl ( inc 0.5)))
(/ pi 2)
); list
); apply
(* styht 1.5); distance
;; [If you dont use stacked fractions, consider using styht without multiplier]
); polar
); command
); progn
); if [not coincident]
(setq inc (1 inc))
); repeat
(setvar clayer clay)
(setvar osmode osm)
(command "_.undo" "_end")
(setvar cmdecho cmde)
(princ)
); defun DP
(defun C:DPI () (DP "in")); = Dimension Polyline Inside
(defun C:DPO () (DP "out")); = Dimension Polyline Outside
(prompt "\nType DPI to Dimension a Polyline on the Inside, DPO to do so on the Outside.")
_______________________________________________________________________________________
_______________________________________________________________________________________
_________________________________
;; By Joe Burke
;;
;;
;;
;;
;;
;;

What does CC2 do which ExpressTools extrim, AKA CookieCutter, doesnt?


Works with blocks, hatches and regions by exploding them.
Other object types which cannot be trimmed are left intact.
Works with objects which do not use a Continuous linetype.
Offers an option to delete all objects on visible layers either
inside or outside the selected trim object.

;; The interface is similar to extrim.


;;
;;
;;
;;
;;

First extrim prompt:


Pick a POLYLINE, LINE, CIRCLE, ARC, ELLIPSE, IMAGE or TEXT for cutting edge...
Select objects:
Confusing because the routine does not allow multiple object selection.
Plus it works with some object types not mentioned, like splines.

;; First CookieCutter2 prompt:


;; Select circle or closed polyline, ellipse or spline for trimming edge:
;; The object must be closed or appear to be closed.
;; Second extrim prompt:
;; Specify the side to trim on:
;; Second CookieCutter2 prompt:
;; Pick point on side to trim:
;; Third CookieCutter2 prompt:
;; One of the following depending on whether the point picked is inside
;; or outside the trim object.
;; Erase all objects inside? [Yes/No] <N>:
;; Erase all objects outside? [Yes/No] <N>:
;; If Yes, all objects on visible layers are erased. If No it behaves
;; like extrim.
Page 40

PRICOL
;; Both CC2 and extrim only operate on objects on visible layers.
;; The routine will display an additional prompt if one or more solid
;; hatches intersects the trim object.
;; Convert solid hatch to lines? [Yes/No] <N>:
;; If Yes, solid hatches are converted to lines using the ANSI31 pattern
;; and the lines are trimmed. If No, solid hatches are not trimmed.
;; Miscellaneous Notes:
;; The routine may be used to simply erase all objects inside or
;; outside the trim object.
;; The routine does not trim annotation objects such as text, mtext,
;; dimensions, leaders, mleaders and tables. The user may choose to
;; explode some of these objects types before running the routine.
;; It ignores xrefs. Bind xrefs beforehand if those block objects
;; should be trimmed.
;; Some cleanup may be needed after the routine ends.
;;
;;
;;
;;
;;

The routine offsets the selected trim object inside or outside in


order to determine trim points. The offset distance is a variable
which depends on the size if the trim object. Likewise, if solid
hatches are converted to lines, the scale of the ANSI31 pattern
depends on the same variable.

;; The routine will end (exit) if offset fails or offset creates more
;; than one new object. Message at the command line:
;; "Problem detected with selected object. Try another. Exiting... "
;; Selfintersecting trim objects are not allowed. The select object
;; part of the routine checks for this and cycles if a selfintersecting
;; object is selected.
(defun c:CookieCutter2 ( / *error* *acad* doc ps osm as om emode pmode offd
elev locked typ typlst e d notclosed splinetyp
i o intpts lst sc minpt maxpt hidelst dellst
offsetename offsetobj trimename trimobj curcoord
mark postlst coord reg selfinter ext UCSpkpt
UCStrimobjpts WCStrimobjpts delother side
ssinside ssall sscross ssoutside ssintersect
solidflag solidans solidlst CC:GetScreenCoords
CC:TraceObject CC:GetInters CC:SpinBar CC:AfterEnt
CC:CommandExplode CC:ExpNestedBlock CC:FirstLastPts
CC:GetBlock CC:AttributesToText CC:UniformScale
CC:SSVLAList CC:Inside CC:UnlockLayers
CC:RelockLayers CC:ZoomToPointList Extents)
(defun *error* (msg)
(cond
((not msg))
((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
(T (princ (strcat "\nError: " msg)))
)
(setvar "pickstyle" ps)
(setvar "osmode" osm)
(setvar "autosnap" as)
(setvar "edgemode" emode)
(setvar "projmode" pmode)
(setvar "orthomode" om)
(setvar "elevation" elev)
(setvar "offsetdist" offd)
Page 41

PRICOL
(setvar "cmdecho" 1)
(if (and offsetobj (not (vlaxerasedp offsetobj)))
(vladelete offsetobj)
)
(foreach x hidelst
(if (not (vlaxerasedp x))
(vlaxput x Visible acTrue)
)
)
(if (and trimobj (not (vlaxerasedp trimobj)))
(vlahighlight trimobj acFalse)
)
(CC:RelockLayers locked)
(vlaEndUndoMark doc)
(princ)
) ;end error
;;;; START SUBFUNCTIONS ;;;;
;; by Tony Tanzillo
;; Returns the lower left and upper right corners of a point list.
(defun Extents (plist)
(list
(apply mapcar (cons min plist))
(apply mapcar (cons max plist))
)
) ;end
;; Argument: WCS point list.
;; In lieu of (command "zoom" "object"...) which requires 2005 or later.
(defun CC:ZoomToPointList (pts)
(setq pts (Extents pts))
(vlaxinvoke *acad* ZoomWindow (car pts) (cadr pts))
(vlaxinvoke *acad* ZoomScaled 0.85 acZoomScaledRelative)
) ;end
;; Unlock any locked layers in the active file.
;; Returns a list of unlocked layers if any.
(defun CC:UnlockLayers (doc / laylst)
(vlaxfor x (vlagetLayers doc)
;filter out xref layers
(if
(and
(not (vlstringsearch "|" (vlaxget x Name)))
(eq :vlaxtrue (vlagetlock x))
)
(progn
(setq laylst (cons x laylst))
(vlaputlock x :vlaxfalse)
)
)
)
laylst
) ;end
;; Argument: a list of layer objects from CC:UnlockLayers.
(defun CC:RelockLayers (lst)
(foreach x lst
(vlcatchallapply vlaputlock (list x :vlaxtrue))
)
) ;end
;Returns the coordinates of the current view, lower left and upper right.
;Works in a rotated view.
Page 42

PRICOL
(defun CC:GetScreenCoords ( / ViwCen ViwDim ViwSiz VptMin VptMax)
(setq ViwSiz (/ (getvar "VIEWSIZE") 2.0)
ViwCen (getvar "VIEWCTR")
ViwDim (list
(* ViwSiz (apply / (getvar "SCREENSIZE")))
ViwSiz
)
VptMin (mapcar ViwCen ViwDim)
VptMax (mapcar + ViwCen ViwDim)
)
(list VptMin VptMax)
) ;end
;; By John Uhden. Return T if point is inside point list.
;; Check how many intersections found with an "infinite" line (like a ray).
;; If the number intersections is odd, point is inside.
;; If the number intersections is even, point is outside.
(defun CC:Inside (p ptlist / p2 i n #)
;; define a point at a sufficiently large distance from p...
(setq p2 (polar p 0.0 (distance (getvar "extmin")(getvar "extmax"))))
;; Make sure the ptlist is closed...
(if (not (equal (car ptlist) (last ptlist) 1e10))
(setq ptlist (append ptlist (list (car ptlist))))
)
(setq i 0 # 0 n (1 (length ptlist)))
(while (< i n)
(if (inters p p2 (nth i ptlist)(nth (1+ i) ptlist))
(setq # (1+ #))
)
(setq i (1+ i))
)
(not (zerop (rem # 2)))
) ; end CC:Inside
;Argument: selection set.
;Returns: list of VLA objects.
(defun CC:SSVLAList (ss / obj lst i)
(setq i 0)
(if ss
(repeat (sslength ss)
(setq obj (vlaxename>vlaobject (ssname ss i))
lst (cons obj lst)
i (1+ i)
)
)
)
(reverse lst)
) ;end
;; Returns a list of primary enames after ename ent.
;; Filter out subentities and entities not in current space.
(defun CC:AfterEnt (ent / lst entlst)
(while (setq ent (entnext ent))
(setq entlst (entget ent))
(if
(and
(not (wcmatch (cdr (assoc 0 entlst)) "ATTRIB,VERTEX,SEQEND"))
(eq (cdr (assoc 410 entlst)) (getvar "ctab"))
)
(setq lst (cons ent lst))
)
)
(reverse lst)
) ;end
Page 43

PRICOL
(defun CC:SpinBar (sbar)
(cond ((= sbar "\\") "|")
((= sbar "|") "/")
((= sbar "/") "")
(t "\\")
)
) ;end
(defun CC:TraceObject (obj / typlst typ ZZeroList TracePline
TraceCE TraceSpline)
;;;; start trace subfunctions ;;;;
;; Argument: 2D or 3D point list.
;; Returns: 3D point list with zero Z values.
(defun ZZeroList (lst)
(mapcar (lambda (p) (list (car p) (cadr p) 0.0)) lst)
)
;; Argument: vlaobject, a heavy or lightweight pline.
;; Returns: WCS point list if successful.
;; Notes: Duplicate adjacent points are removed.
;; The last closing point is included given a closed pline.
(defun TracePline (obj / param endparam anginc tparam pt blg
ptlst delta inc arcparam flag)
(setq param (vlaxcurvegetStartParam obj)
endparam (vlaxcurvegetEndParam obj)
;anginc (* pi (/ 7.5 180.0)) ;;;; note 7.5 here vs 2.5 at circle
anginc (* pi (/ 2.5 180.0)) ;; the two should be the same
)
(while (<= param endparam)
(setq pt (vlaxcurvegetPointAtParam obj param))
;Avoid duplicate points between start and end.
(if (not (equal pt (car ptlst) 1e12))
(setq ptlst (cons pt ptlst))
)
;A closed pline returns an error (invalid index)
;when asking for the bulge of the end param.
(if
(and
(/= param endparam)
(setq blg (abs (vlaxinvoke obj GetBulge param)))
(/= 0 blg)
)
(progn
(setq delta (* 4 (atan blg)) ;included angle
inc (/ 1.0 (1+ (fix (/ delta anginc))))
arcparam (+ param inc)
)
(while (< arcparam (1+ param))
(setq pt (vlaxcurvegetPointAtParam obj arcparam)
ptlst (cons pt ptlst)
arcparam (+ inc arcparam)
)
)
)
)
(setq param (1+ param))
) ;while
(if (> (length ptlst) 1)
Page 44

PRICOL
(progn
(setq ptlst (vlremove nil ptlst))
(ZZeroList (reverse ptlst))
)
)
) ;end
;; Argument: vlaobject, an arc, circle or ellipse.
;; Returns: WCS point list if successful.
(defun TraceCE (obj / startparam endparam anginc
delta div inc pt ptlst)
;start and end angles
;circles dont have StartAngle and EndAngle properties.
(setq startparam (vlaxcurvegetStartParam obj)
endparam (vlaxcurvegetEndParam obj)
;;;;;;;;;;;;;; note change here, was using 7.5 ;;;;;;;;;;;;;
;anginc (* pi (/ 7.5 180.0))
;; This version is from SuperFlatten.
;; I think it returns a tighter trace.
anginc (* pi (/ 2.5 180.0))
)
(if (equal endparam (* pi 2) 1e6)
(setq delta endparam)
;added abs 6/23/2007, testing
(setq delta (abs ( endparam startparam)))
)
;Divide delta (included angle) into an equal number of parts.
(setq div (1+ (fix (/ delta anginc)))
inc (/ delta div)
)
;Or statement allows the last point on an open ellipse
;rather than using (<= startparam endparam) which sometimes
;fails to return the last point. Not sure why.
(while
(or
(< startparam endparam)
(equal startparam endparam 1e12)
;(equal startparam endparam)
)
(setq pt (vlaxcurvegetPointAtParam obj startparam)
ptlst (cons pt ptlst)
startparam (+ inc startparam)
)
)
(ZZeroList (reverse ptlst))
) ;end
(defun TraceSpline (obj / startparam endparam ncpts inc param
fd ptlst pt1 pt2 ang1 ang2 a)
(setq startparam (vlaxcurvegetStartParam obj)
endparam (vlaxcurvegetEndParam obj)
ncpts (vlaxget obj NumberOfControlPoints)
inc (/ ( endparam startparam) (* ncpts 6))
param (+ inc startparam)
fd (vlaxcurvegetfirstderiv obj param)
ptlst (cons (vlaxcurvegetStartPoint obj) ptlst)
)
(while (< param endparam)
(setq pt1 (vlaxcurvegetPointAtParam obj param)
ang1 (angle pt1 (mapcar + pt1 fd))
Page 45

PRICOL
param (+ param inc)
pt2 (vlaxcurvegetPointAtParam obj param)
fd (vlaxcurvegetfirstderiv obj param)
ang2 (angle pt2 (mapcar + pt2 fd))
a (abs (@delta ang1 ang2))
)
(if (> a 0.00436332)
(setq ptlst (cons pt1 ptlst))
)
)
;add last point and check for duplicates
(if
(not
(equal
(setq pt1 (vlaxcurvegetEndPoint obj)) (car ptlst) 1e8))
(setq ptlst (cons pt1 ptlst))
)
(ZZeroList (reverse ptlst))
) ;end
;;;; primary trace function ;;;;
(setq typlst ("AcDb2dPolyline" "AcDbPolyline" "AcDbSpline"
"AcDbCircle" "AcDbEllipse")
)
(or
(eq (type obj) VLAOBJECT)
(setq obj (vlaxename>vlaobject obj))
)
(setq typ (vlaxget obj ObjectName))
(if (vlposition typ typlst)
(cond
((or (eq typ "AcDb2dPolyline") (eq typ "AcDbPolyline"))
(cond
((or
(not (vlaxpropertyavailablep obj Type))
(= 0 (vlaxget obj Type))
)
(TracePline obj)
)
)
)
((or (eq typ "AcDbCircle") (eq typ "AcDbEllipse"))
(TraceCE obj)
)
((eq typ "AcDbSpline")
(TraceSpline obj)
)
)
)
) ;end CC:TraceObject
; Arguments:
; firstobj: first object ename or vlaobject
; nextobj: second object ename or vlaobject
; mode extend options
; acExtendNone: extend neither object
; acExtendThisEntity: extend first object
; acExtendOtherEntity: extend second object
; acExtendBoth: extend both objects
; Returns a WCS point list or nil if intersection not found.
(defun CC:GetInters (firstobj nextobj mode / coord ptlst)
(if (= (type firstobj) ENAME)
Page 46

PRICOL
(setq firstobj (vlaxename>vlaobject firstobj)))
(if (= (type nextobj) ENAME)
(setq nextobj (vlaxename>vlaobject nextobj)))
(if
(not
(vlcatchallerrorp
(setq coord (vlcatchallapply vlaxinvoke
(list firstobj IntersectWith nextobj mode)))
)
)
(repeat (/ (length coord) 3)
(setq ptlst (cons (list (car coord) (cadr coord) (caddr coord)) ptlst))
(setq coord (cdddr coord))
)
)
(reverse ptlst)
) ;end
;; Note 7/24/2008, saw the annonymous *E81 block thing again as in
;; SuperFlatten. It happens when trying to explode an NUS block.
;; In this case a grid block (was xref bound) was NUS. The grid lines
;; were exploded, but the column blocks inside it were not.
;; All of them were placed in the *E81 block.
;; I suppose there might be a report about this. At the end you could
;; check the blocks which remain in the drawing. If any has a name
;; like *E81, report, "A nonuniformly scaled block could not be exploded."
(defun CC:CommandExplode (obj / lay mark attlst name exlst)
(setq mark (entlast))
(if
(and
(not (vlaxerasedp obj))
(eq "AcDbBlockReference" (vlaxget obj ObjectName))
)
(progn
(setq lay (vlaxget obj Layer)
attlst (vlaxinvoke obj GetAttributes)
)
(vlcmdf "._explode" (vlaxvlaobject>ename obj))
;; Is this still fixing error in error handler?
;; Yes it is IMPORTANT!
(command)
(if
(and
(not (eq mark (entlast)))
(setq exlst (CC:SSVLAList (ssget "_p")))
)
(progn
(CC:AttributesToText attlst) ;seems OK here
(foreach x exlst
(if (eq "AcDbAttributeDefinition" (vlaxget x ObjectName))
(vladelete x)
)
)
(setq exlst (vlremoveif vlaxerasedp exlst))
;If an exlpoded object is on layer 0, put it on the
;layer of the exploded object. If its color is byBlock,
;change color to byLayer.
(foreach x exlst
(if (eq "0" (vlaxget x Layer))
(vlaxput x Layer lay)
)
(if (zerop (vlaxget x Color))
(vlaxput x Color 256)
)
Page 47

PRICOL
)
)
)
)
) ;if
;(setq exlst (vlremoveif vlaxerasedp exlst))
(foreach x exlst
(if
(and
(not (vlaxerasedp x))
(eq "AcDbBlockReference" (vlaxget x ObjectName))
)
(CC:ExpNestedBlock x)
)
)
) ;end CC:CommandExplode
;; Argument: block reference vlaobject.
;; Explode the block passed and any nested blocks.
;; Doesnt deal with attributes yet. Convert to text.
;; Based on code by TWVacation at theswamp.
;; Leave this function as is. Trying to condense it
;; will only cause problems.
(defun CC:ExpNestedBlock (obj / lay lst)
;; Do SpinBar here because exploding many blocks is what
;; causes the routine to take a long time in some cases.
(princ
(strcat "\rProcessing blocks... "
(setq *sbar (CC:SpinBar *sbar)) "\t")
)
(if
(and
obj
(not (vlaxerasedp obj))
)
(cond
((not (CC:UniformScale obj))
(CC:CommandExplode obj)
)
(T
(setq lay (vlaxget obj Layer))
(if (eq "AcDbBlockReference" (vlaxget obj ObjectName))
(CC:AttributesToText (vlaxinvoke obj GetAttributes))
)
;; This is primarily intended to catch NUS blocks which
;; the explode method cant handle.
(setq lst (vlcatchallapply vlaxinvoke (list obj Explode)))
(if (listp lst)
(foreach x lst
;; This update call is important!
(vlaupdate x) ;testing
(if (eq "AcDbBlockReference" (vlaxget x ObjectName))
(CC:ExpNestedBlock x)
(progn
(if
(and
(not (vlaxerasedp x))
(eq "0" (vlaxget x Layer))
)
(vlaxput x Layer lay)
)
;; If color is byblock, change to bylayer.
(if
Page 48

PRICOL
(and
(not (vlaxerasedp x))
(zerop (vlaxget x Color))
)
(vlaxput x Color 256)
)
(if
(and
(not (vlaxerasedp x))
(eq "AcDbAttributeDefinition" (vlaxget x ObjectName))
)
(vladelete x)
)
)
)
)
)
(vladelete obj)
)
) ;cond
) ;if
) ;end
;; Allow an object which is not closed, but has equal first and last points,
;; to pass the test.
(defun CC:FirstLastPts (obj / p1 p2)
(setq p1 (vlaxcurvegetPointAtParam obj (vlaxcurvegetStartParam obj)))
(setq p2 (vlaxcurvegetPointAtParam obj (vlaxcurvegetEndParam obj)))
(equal p1 p2 1e10)
)
(defun CC:GetBlock ()
(vlaxget (vlagetActiveLayout doc) Block)
) ;end
;; Convert a list of attribute reference objects to text objects.
(defun CC:AttributesToText (attlst / elst n obj res)
(foreach x attlst
(setq elst (entget (vlaxvlaobject>ename x)))
(entmake
(list
(0 . "TEXT")
(cons 1 (vlaxget x TextString))
(cons 7 (vlaxget x StyleName))
(cons 8 (vlaxget x Layer))
(cons 10 (vlaxget x InsertionPoint))
(cons 11 (vlaxget x TextAlignmentPoint))
(cons 40 (vlaxget x Height))
(cons 41 (vlaxget x ScaleFactor))
(cons 50 (vlaxget x Rotation))
(cons 51 (vlaxget x ObliqueAngle))
(cons 62 (vlaxget x Color))
(cons 67 (cdr (assoc 67 elst)))
(cons 71 (cdr (assoc 71 elst)))
(cons 72 (cdr (assoc 72 elst)))
(cons 73 (cdr (assoc 74 elst)))
(cons 410 (cdr (assoc 410 elst)))
)
) ;make
)
) ;end
;; Return T ig block is uniformly scaled within fuzz range.
(defun CC:UniformScale (obj / x y z)
Page 49

PRICOL
(and
(or
(= (type obj) VLAobject)
(if (= (type obj) ENAME)
(setq obj (vlaxename>vlaobject obj))
)
)
(or
(wcmatch (vlaxget obj ObjectName) "*Dimension")
(and
(= "AcDbBlockReference" (vlaxget obj ObjectName))
(setq x (vlaxget obj XScaleFactor))
(setq y (vlaxget obj YScaleFactor))
(setq z (vlaxget obj ZScaleFactor))
(and
;; this fuzz 1e8 seems sufficient for this application
;; it does not involve transformby which seems more sensitive
;; to NUS blocks
(equal (abs x) (abs y) 1e8)
(equal (abs y) (abs z) 1e8)
)
)
)
)
) ;end
;; Added 7/28/2008
;; Arguments: ename or vlaobject and an intersection point list.
;; Returns: the original point list if an error occurs due to object type.
;; Otherwise the point list sorted by param at point along the curve.
;; Notes: the order of the point list returned by IntersectWith is
;; unpredictable. Sorting the point list allows multiple trim operations
;; on an object to occur in more predictable fashion.
(defun SortInterPoints (obj pts / lst)
(if
(vlcatchallerrorp
(vlcatchallapply vlaxcurvegetEndParam (list obj))
)
pts
(progn
(setq lst (mapcar (lambda (y) (vlaxcurvegetParamAtPoint obj y)) pts)
lst (mapcar (lambda (y z) (list y z)) lst pts)
lst (vlsort lst (lambda (a b) (< (car a) (car b))))
)
(mapcar cadr lst)
)
)
) ;end
;;;; END SUBFUNCTIONS ;;;;
;;;; START MAIN FUNCTION ;;;;
(vlloadcom)
(setq *acad* (vlaxgetacadobject)
doc (vlagetActiveDocument *acad*)
)
(vlaStartUndoMark doc)
(setq locked (CC:UnlockLayers doc))
;; Avoid problems with groups.
(setq ps (getvar "pickstyle"))
(setvar "pickstyle" 0)
Page 50

PRICOL
(setvar "cmdecho" 0)
(setq elev (getvar "elevation"))
;; So the Z value of the point picked (inside or outside)
;; is not at the current elevation.
(setvar "elevation" 0.0)
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
;; polar and ortho should be off too?
(setq as (getvar "autosnap"))
(setvar "autosnap" 0)
(setq om (getvar "orthomode"))
(setvar "orthomode" 0)
;; These following added 8/14/2008
(setq emode (getvar "edgemode"))
(setvar "edgemode" 0)
(setq pmode (getvar "projmode"))
(setvar "projmode" 0)
(setq offd (getvar "offsetdist"))
(sssetfirst)
(setq typlst ("AcDbCircle" "AcDbPolyline" "AcDb2dPolyline"
"AcDbEllipse" "AcDbSpline"))
(setvar "errno" 0)
(while
(or
(not (setq e (car (entsel
"\nSelect circle or closed polyline, ellipse or spline for trimming edge: "))))
(not (setq trimobj (vlaxename>vlaobject e)))
(not (vlposition (setq typ (vlaxget trimobj ObjectName)) typlst))
(and
(not (CC:FirstLastPts trimobj))
(setq notclosed T)
)
(and
(wcmatch typ "*Polyline")
(vlaxpropertyavailablep trimobj Type)
(not (zerop (vlaxget trimobj Type)))
(setq splinetyp T)
)
;; Test for selfintersecting pline or spline.
;; Concept by Tony Tanzillo. If region fails the object
;; probably intersects itself. Seems reliable so far.
(and
(wcmatch typ "*Polyline,AcDbSpline")
(vlcatchallerrorp
(setq reg
(vlcatchallapply vlaxinvoke
(list (CC:GetBlock) AddRegion (list trimobj))
)
)
)
(setq selfinter T)
)
)
(cond
((= 52 (getvar "errno"))
(exit)
)
((not e)
(princ "\n Missed pick. ")
)
Page 51

PRICOL
(selfinter
(princ "\n Selected object intersects itself, try again. ")
(setq selfinter nil)
)
(notclosed
(princ "\n Selected object is not closed, try again. ")
(setq notclosed nil)
)
(splinetyp
(princ "\n Polyline spline selected, try again. ")
(setq splinetyp nil)
)
(typ
(princ (strcat "\n " (substr typ 5) " selected, try again. "))
(setq typ nil)
)
)
)
;; Delete region if one was created.
(if
(and
reg
(not (vlcatchallerrorp reg))
)
(vladelete (car reg))
)
(setq trimename (vlaxvlaobject>ename trimobj))
;; View to restore at end.
(setq curcoord (CC:GetScreenCoords))
;; Highlighting the trim object helps in crouded situations.
(vlahighlight trimobj acTrue)
(initget 1)
(setq UCSpkpt (getpoint "\nPick point on side to trim: "))
(setq WCStrimobjpts (CC:TraceObject trimobj))
(setq UCStrimobjpts
(mapcar (lambda (x) (trans x 0 1)) WCStrimobjpts)
)
(if (CC:Inside UCSpkpt UCStrimobjpts)
(setq side "inside")
(setq side "outside")
)
(setq ext (Extents WCStrimobjpts))
(setq d (distance (car ext) (cadr ext)))
;; d is used below to specify offset distance.
(setq d (/ d 1500.0))
;; testing for decimal units
;; initial test indicates this may be needed
;; An exploded hatch was trimmed better with this.
;; Keep this for now.
(if (= 2 (getvar "lunits"))
(setq d (/ d 12.0))
)
(setq mark (entlast))
(vlcmdf "._offset" d (vlaxvlaobject>ename trimobj) UCSpkpt "_exit")
Page 52

PRICOL
(setq offsetename (entlast))
(if (/= 1 (length (setq dellst (CC:AfterEnt mark))))
(progn
(princ "\nProblem detected with selected object. Try another. Exiting... ")
;; If offset created multiple objects they need to be deleted.
;; This can happen with a spline.
;; Also exit if offset failed.
(foreach x dellst (entdel x))
(exit)
)
)
(setq offsetobj (vlaxename>vlaobject offsetename))
(vlaxput offsetobj Visible 0)
(setq hidelst (cons offsetobj hidelst))
(initget "Yes No")
(setq delother (getkword (strcat "\nErase all objects " side "? [Yes/No] <N>: ")))
(if (not delother) (setq delother "No"))
;(starttimer)
(vlaxinvoke *acad* ZoomExtents)
(setq sc (CC:GetScreenCoords))
;; These are 2D points.
(setq minpt (car sc))
(setq maxpt (cadr sc))
;; This must follow zoom extents.
(vlaxput trimobj Visible 0)
(setq hidelst (cons trimobj hidelst))
;; Explode blocks which intersect the trim object first.
;; Deal with hatches and regions afterwards.
(setq sscross (ssget "cp" UCStrimobjpts ((0 . "INSERT"))))
(if (not (setq ssinside (ssget "wp" UCStrimobjpts ((0 . "INSERT")))))
(setq ssinside (ssadd))
)
(setq i 0)
(if sscross
(repeat (sslength sscross)
(setq e (ssname sscross i))
(if
(and
(not (ssmemb e ssinside))
(setq o (vlaxename>vlaobject e))
(not (vlaxerasedp o))
(vlaxpropertyavailablep o Path)
)
(progn
;; Hiding true xrefs here. If the block was not
;; erased/explode above then hide it. The reason for
;; this nonsense method is sometimes after an xref
;; is bound, AutoCAD thinks it is still an xref.
;; Theres no way to test for this condition AFAIK.
;; (Command "explode"...) can explode a false xref.
;; So this cond passes all xref blocks to the
;; CommandExplode function. If it fails to explode
;; then make the xref invisible. Note, there will be a
;; nonfatal message generated within the CommandExplode
;; function when the block is really an xref.
;; "The object is an external reference."
Page 53

PRICOL
;; Just have to live with that.
;; Also, the explode method cannot be used on false xrefs.
;; The reason for attention to this problem is the user
;; may bind xrefs before running the routine.
(CC:CommandExplode o)
(if (not (vlaxerasedp o))
(progn
(vlaxput o Visible 0)
(setq hidelst (cons o hidelst))
)
)
)
;else
(CC:ExpNestedBlock o)
)
(setq i (1+ i))
)
)
;; Solid hatches...
(setq i 0 sscross nil ssinside nil)
(setq sscross (ssget "cp" UCStrimobjpts ((0 . "HATCH"))))
(if (not (setq ssinside (ssget "wp" UCStrimobjpts ((0 . "HATCH")))))
(setq ssinside (ssadd))
)
;; Just check for solid hatces.
(if sscross
(repeat (sslength sscross)
(setq e (ssname sscross i))
(if
(and
(not (ssmemb e ssinside))
(setq o (vlaxename>vlaobject e))
(eq "AcDbHatch" (vlaxget o ObjectName))
(eq "SOLID" (vlaxget o PatternName))
)
(setq solidflag T
solidlst (cons e solidlst)
)
)
(setq i (1+ i))
)
) ;if
(if solidflag
(progn
(initget "Yes No")
(setq solidans (getkword "\nConvert solid hatch to lines? [Yes/No] <N>: "))
(if (eq "Yes" solidans)
(foreach x solidlst
;; check for erased?
(command "._hatchedit" x
"_properties" "ANSI31" (* d 8) 0.0)
;; Prevent message, "Hatch boundary associativity removed."
(vlaxput (vlaxename>vlaobject x) AssociativeHatch 0)
(command "._explode" x)
)
)
)
)
;; Now regions and not solid hatches.
(setq i 0 sscross nil ssinside nil)
(setq sscross (ssget "cp" UCStrimobjpts ((0 . "HATCH,REGION"))))
Page 54

PRICOL
(if (not (setq ssinside (ssget "wp" UCStrimobjpts ((0 . "HATCH,REGION")))))
(setq ssinside (ssadd))
)
;; Ignore solid hatches. If any still exist the user answered No to question.
(if sscross
(repeat (sslength sscross)
(setq e (ssname sscross i))
(if
(and
(not (ssmemb e ssinside))
(not (vlposition e solidlst))
)
(progn
;; Prevent message, "Hatch boundary associativity removed."
(setq o (vlaxename>vlaobject e))
(if (vlaxpropertyavailablep o AssociativeHatch)
(vlaxput o AssociativeHatch 0)
)
(command "._explode" e)
)
)
(setq i (1+ i))
)
)
(setq sscross nil ssinside nil)
;; Note: xrefs and the trim object are invisible at this point
;; so they are not included in following selections.
(setq ssall (ssget "c" minpt maxpt))
;; Selection set of objects completely inside trimobj.
(if (not (setq ssinside (ssget "wp" UCStrimobjpts)))
(setq ssinside (ssadd))
)
;; Selection set of all objects crossing trimobj.
(if (not (setq sscross (ssget "cp" UCStrimobjpts))) ;var added
(setq sscross (ssadd))
)
;; now ssoutside can be set
(setq i 0)
(setq ssoutside (ssadd))
(repeat (sslength ssall)
(setq e (ssname ssall i))
(if (not (ssmemb e sscross))
(ssadd e ssoutside)
)
(setq i (1+ i))
)
;; ssintersect objects which intersect the trim object.
(setq i 0)
(setq ssintersect (ssadd))
(repeat (sslength sscross)
(setq e (ssname sscross i))
(if
(and
(not (ssmemb e ssinside))
(not (vlposition e solidlst))
;; Added intersect test 8/7/2008.
;; Was removed, put back 8/19/2008. Seems OK.
;; If the following returns nil then trim will fail.
;; "Cannot TRIM this object." This can happen with
;; some unusual spline objects.
Page 55

PRICOL
(CC:GetInters e trimobj acExtendNone)
;(not (eq e trimename))
)
(ssadd e ssintersect)
(ssadd e ssinside)
)
(setq i (1+ i))
)
;; Added check 8/22/2008.
;; Likely only applies to an ellipse as trim object.
;; An ellipse is converted to a spline when offset.
;; For some unknown reason the trim object may be
;; included in the objects which are erased. It should not
;; happen since the trim object is invisible as this point.
;; Regardless, this check fixes a bug which may cause the
;; trim object to be erased. Which in turn causes other problems.
(if (eq "Yes" delother)
(cond
((eq side "inside")
(ssdel trimename ssinside) ;check
(command "._erase" ssinside "")
)
((eq side "outside")
(ssdel trimename ssoutside) ;check
(command "._erase" ssoutside "")
)
)
)
;; List of VLAobjects which intersect the trim object.
(setq lst (CC:SSVLAList ssintersect))
;; Remove these object types from list to trim.
;; There is error checking elsewhere which should prevent
;; errors with other object types which cannot be trimmed.
;; Note 8/17/2008 the only hatches which still exist are
;; solid hatches which the user chose not to convert to lines.
;; So hatches can be added here.
(setq lst
(vlremoveif
(lambda (x)
(setq typ (vlaxget x ObjectName))
(or
(eq "AcDbText" typ)
(eq "AcDbMText" typ)
(eq "AcDbLeader" typ)
(wcmatch typ "*Dimension")
(eq "AcDbHatch" typ) ;; added 8/17/2008
(eq "AcDbSolid" typ)
(eq "AcDbTrace" typ)
(eq "AcDbMLeader" typ)
;; Likely not needed, Added 8/22/2008.
(eq trimobj x)
)
)
lst
)
)
(CC:ZoomToPointList WCStrimobjpts)
;;; Start primary loop ;;;
Page 56

PRICOL
(foreach x lst
;; Helps with trimming closed plines.
(if (not (vlaxerasedp x))
(progn
(setq typ (vlaxget x ObjectName))
(cond
((and
(eq "AcDbPolyline" typ)
(= 1 (vlaxget x Closed))
)
(vlaxput x Closed 0)
(setq coord (vlaxget x Coordinates))
(vlaxput x Coordinates
(append coord (list (car coord) (cadr coord)))
)
(vlaupdate x)
)
((and
(eq "AcDb2dPolyline" typ)
(= 1 (vlaxget x Closed))
)
(vlaxput x Closed 0)
(setq coord (vlaxget x Coordinates))
(vlaxput x Coordinates
(append coord (list (car coord) (cadr coord) (caddr coord)))
)
(vlaupdate x)
)
)
)
)
(if (setq intpts (CC:GetInters offsetobj x acExtendNone))
(progn
;; More than two points seems good here and below.
(if (> (length intpts) 2)
(setq intpts (SortInterPoints x intpts))
)
(foreach p intpts
(setq mark (entlast))
(if
(and
(not (vlcatchallerrorp
(vlcatchallapply vlaxcurvegetParamAtPoint (list x p)))
)
(vlaxcurvegetParamAtPoint x p)
)
(vlcmdf "._trim" trimename ""
(list (vlaxvlaobject>ename x) (trans p 0 1)) "")
)
(if (not (eq mark (entlast)))
(setq postlst (cons (entlast) postlst))
)
)
)
)
)
;;; End primary loop ;;;
;; This part trims any new objects created above.
(while postlst
(setq intpts nil)
(foreach x postlst
Page 57

PRICOL
(if (setq intpts (CC:GetInters offsetobj x acExtendNone))
(progn
(if (> (length intpts) 2)
(setq intpts (SortInterPoints x intpts))
)
(foreach p intpts
(setq mark nil) ; is this needed?
(setq mark (entlast))
(if
(and
(not (vlcatchallerrorp
(vlcatchallapply vlaxcurvegetParamAtPoint (list x p)))
)
(vlaxcurvegetParamAtPoint x p)
)
(vlcmdf "._trim" trimename "" (list x (trans p 0 1)) "")
)
(setq postlst (vlremove x postlst))
(if (not (eq mark (entlast)))
(setq postlst (cons (entlast) postlst))
)
)
(setq postlst (vlremove x postlst))
)
(setq postlst (vlremove x postlst))
)
)
)
;; Zoom to original view.
(command "._zoom" "_window" (car curcoord) (cadr curcoord))
;(endtimer)
(*error* nil)
) ;end
;
;shortcut
(defun c:CC () (c:CookieCutter2))
;
;(defun c:DelOutside (obj / pts)
; (setq pts (TraceObject obj))
_______________________________________________________________________________________
____________________________________________________________________

Page 58

Potrebbero piacerti anche