lsp

118
;;; AreaText.LSP ver 3.0 ;;; Command name is AT ;;; Select a polyline and where to place the text ;;; Sample result: 2888.89 SQ. FT. ;;; As this is a FIELD it is updated based on the FIELDEVAL ;;; or the settings found in the OPTIONS dialog box ;;; By Jimmy Bergmark ;;; Copyright (C) 2007-2010 JTB World, All Rights Reserved ;;; Website: www.jtbworld.com ;;; E-mail: [email protected] ;;; 2007-09-05 - First release ;;; 2009-08-02 - Updated to work in both modelspace and paperspace ;;; 2010-10-29 - Updated to work also on 64-bit AutoCAD ;;; Uses TEXTSIZE for the text height (defun Get-ObjectIDx64 (obj / util) (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object)))) (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj))) (if (= (type obj) 'VLA-OBJECT) (if (> (vl-string-search "x64" (getvar "platform")) 0) (vlax-invoke-method util "GetObjectIdString" obj :vlax-False) (rtos (vla-get-objectid obj) 2 0) ) ) ) (defun c:AT (/ entObject entObjectID InsertionPoint ad) (vl-load-com) (setq entObject (vlax-ename->vla-object(car (entsel))) entObjectID (Get-ObjectIDx64 entObject) InsertionPoint (vlax-3D-Point (getpoint "Select point: ")) ad (vla-get-ActiveDocument (vlax-get-acad-object)) ) (vla-addMText (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) InsertionPoint 0.0 (strcat "%<\\AcObjProp Object(%<\\_ObjId " entObjectID ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%" )) ) ;;;---------------------------------------------------------------------------; ;;; ;;; accdist.lsp ;;; ;;; By Jimmy Bergmark ;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved ;;; Website: www.jtbworld.com ;;; E-mail: [email protected] ;;;

Upload: satydevsinghnegi

Post on 02-Jan-2016

199 views

Category:

Documents


1 download

DESCRIPTION

Lisp file

TRANSCRIPT

Page 1: Lsp

;;; AreaText.LSP ver 3.0;;; Command name is AT;;; Select a polyline and where to place the text;;; Sample result: 2888.89 SQ. FT.;;; As this is a FIELD it is updated based on the FIELDEVAL;;; or the settings found in the OPTIONS dialog box

;;; By Jimmy Bergmark;;; Copyright (C) 2007-2010 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2007-09-05 - First release;;; 2009-08-02 - Updated to work in both modelspace and paperspace;;; 2010-10-29 - Updated to work also on 64-bit AutoCAD

;;; Uses TEXTSIZE for the text height

(defun Get-ObjectIDx64 (obj / util) (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object)))) (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj))) (if (= (type obj) 'VLA-OBJECT) (if (> (vl-string-search "x64" (getvar "platform")) 0) (vlax-invoke-method util "GetObjectIdString" obj :vlax-False) (rtos (vla-get-objectid obj) 2 0) ) ))

(defun c:AT (/ entObject entObjectID InsertionPoint ad) (vl-load-com) (setq entObject (vlax-ename->vla-object(car (entsel))) entObjectID (Get-ObjectIDx64 entObject) InsertionPoint (vlax-3D-Point (getpoint "Select point: ")) ad (vla-get-ActiveDocument (vlax-get-acad-object)) ) (vla-addMText (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) InsertionPoint 0.0 (strcat "%<\\AcObjProp Object(%<\\_ObjId " entObjectID ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%" )))

;;;---------------------------------------------------------------------------;;;;;;; accdist.lsp;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 1999-06-12 - First release;;; 2000-05-11 - Fixed for AutoCAD 2000;;; should be working on older versions too.;;;;;;---------------------------------------------------------------------------;

Page 2: Lsp

;;; Methods to accumulate distances;;; c:accdist - combined;;; c:accdist1 - accumulate distances from first point to next point;;; c:accdist2 - accumulate distances from first point to second point;;;---------------------------------------------------------------------------;

(defun c:accdist (/ errexit undox restore *error* p1 p2 sum) (defun errexit (s) (princ) (restore) )

(defun undox () (redraw) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq p1 (getpoint "\nSpecify first point: ") p2 "First" sum 0 ) (while (and p1 p2) (if (= p2 "First") (progn (initget 32) (setq p2 (getpoint "\nSpecify next point: " p1)) ) (progn (initget 32 "First") (setq p2 (getpoint "\nSpecify next point or [First]: " p1)) ) ) (cond ((not p2)) ((= p2 "First") (setq p1 (getpoint "\nSpecify first point: ")) ) (t (grdraw p1 p2 -1 1) (setq sum (+ sum (distance p1 p2)) p1 p2 ) ) ) ) (princ "\nAccumulated distance = ") (princ sum) (restore))

(defun c:accdist1 (/ p1 p2 sum) (setq sum 0) (setq p1 (getpoint "\nSpecify first point: ")) (while (and p1 (not (initget 32)) (setq p2 (getpoint "\nSpecify next point: " p1)) ) (grdraw p1 p2 -1 1)

Page 3: Lsp

(setq sum (+ sum (distance p1 p2))) (setq p1 p2) ) (redraw) (princ "\nAccumulated distance = ") (princ sum) (princ))

(defun c:accdist2 (/ p1 p2 sum) (setq sum 0) (while (and (setq p1 (getpoint "\nSpecify first point: ")) (not (initget 32)) (setq p2 (getpoint "\nSpecify second point: " p1)) ) (setq sum (+ sum (distance p1 p2))) ) (princ "\nAccumulated distance = ") (princ sum) (princ))

;;; Read and write the settings that AecExportToAutoCAD and the like command uses;;; The effect of writing this settings is directly affecting the commands.;;; By Jimmy Bergmark;;; www.jtbworld.com;;; For ADT 2004

;;; Reads the settings that AecExportToAutoCAD and the like command uses;;; Bind xrefs or not when exporting;;; (0 = no bind, 1 = bind);;; (readAecGuiBase40 "ExportExplodedToAutoCADBindXrefs");;; Bind method when xrefs are bound when exporting;;; (0 = Bind method, 1 = Insert method);;; (readAecGuiBase40 "ExportExplodedToAutoCADInsertWhenBinding");;; File prefix used when exporting;;; (readAecGuiBase40 "ExportExplodedToAutoCADFilePrefix");;; File suffix used when exporting;;; (readAecGuiBase40 "ExportExplodedToAutoCADFileSuffix")(vl-load-com)(defun readAecGuiBase40 (keyname) (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile

(vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))

) "\\Preferences\\AecGuiBase40" ) keyname ))

;;; Writes the settings that AecExportToAutoCAD and the like command uses;;; Bind xrefs or not when exporting

Page 4: Lsp

;;; (0 = no bind, 1 = bind);;; (writeAecGuiBase40 "ExportExplodedToAutoCADBindXrefs" 1);;; Bind method when xrefs are bound when exporting;;; (0 = Bind method, 1 = Insert method);;; (writeAecGuiBase40 "ExportExplodedToAutoCADInsertWhenBinding" 1);;; Set the file prefix used when exporting;;; (writeAecGuiBase40 "ExportExplodedToAutoCADFilePrefix" "");;; Set the file suffix used when exporting;;; (writeAecGuiBase40 "ExportExplodedToAutoCADFileSuffix" "-ACAD-EXPORT")

(defun writeAecGuiBase40 (keyname n) (vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile

(vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))

) "\\Preferences\\AecGuiBase40" ) keyname n ));;; Read and write the settings in the "Explode AEC Objects" dialog box;;; using the command _AecObjExplode;;; The effect of writing this settings is directly affecting the command.;;; By Jimmy Bergmark;;; www.jtbworld.com;;; For ADT 2004

;;; Reads the settings "Explode to anonymous blocks";;; (readAECObjectsExplodeOptions "Anonymous Block");;; 0 = Disable Explode to anonymous blocks;;; 1 = Enable Explode to anonymous blocks;;; (readAECObjectsExplodeOptions "Bind Xrefs");;; 0 = Don't bind xrefs;;; 1 = Bind xrefs;;; Others that can be used are:;;; (readAECObjectsExplodeOptions "Bind Xrefs Bind Type");;; (readAECObjectsExplodeOptions "Erase AEC Objects");;; (readAECObjectsExplodeOptions "Explode AEC Objects");;; (readAECObjectsExplodeOptions "Include Model Tab");;; (readAECObjectsExplodeOptions "Maintain Properties");;; (readAECObjectsExplodeOptions "Name Length");;; (readAECObjectsExplodeOptions "Reuse Existing Names");;; (readAECObjectsExplodeOptions "Short Block Names");;; (readAECObjectsExplodeOptions "Verbose");;; (readAECObjectsExplodeOptions "Views")(vl-load-com)(defun readAECObjectsExplodeOptions (keyname) (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile

(vla-get-profiles (vla-get-preferences (vlax-get-acad-object))

Page 5: Lsp

) ) "\\Dialogs\\AecObjExplode40-Options" ) keyname ))

;;; Writes the settings "Explode to anonymous blocks";;; Disable Explode to anonymous blocks;;; (writeAECObjectsExplodeOptions "Anonymous Block" 0);;; Enable Explode to anonymous blocks;;; (writeAECObjectsExplodeOptions "Anonymous Block" 1);;; Don't bind xrefs;;; (writeAECObjectsExplodeOptions "Bind Xrefs" 0);;; Bind xrefs;;; (writeAECObjectsExplodeOptions "Bind Xrefs" 1);;; Others that can be used are:;;; (writeAECObjectsExplodeOptions "Bind Xrefs Bind Type" 1);;; (writeAECObjectsExplodeOptions "Erase AEC Objects" 1);;; (writeAECObjectsExplodeOptions "Explode AEC Objects" 1);;; (writeAECObjectsExplodeOptions "Include Model Tab" 0);;; (writeAECObjectsExplodeOptions "Maintain Properties" 0);;; (writeAECObjectsExplodeOptions "Name Length" 31);;; (writeAECObjectsExplodeOptions "Reuse Existing Names" 0);;; (writeAECObjectsExplodeOptions "Short Block Names" 1);;; Display status messages;;; (writeAECObjectsExplodeOptions "Verbose" 1);;; (writeAECObjectsExplodeOptions "Views" 0)(defun writeAECObjectsExplodeOptions (keyname n) (vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile

(vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))

) "\\Dialogs\\AecObjExplode40-Options" ) keyname n ));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; returns the area of selected object;;; Made for AutoCAD 2000(defun c:areaOfObject (/ en curve area) (if (setq en (entsel)) (progn (setq curve (vlax-ename->vla-object (car en))) (if (vl-catch-all-error-p (setq area (vl-catch-all-apply 'vlax-curve-getArea (list curve)) )

Page 6: Lsp

) nil area ) ) ))

;;; AreaText.LSP ver 3.0;;; Command name is AT;;; Select a polyline and where to place the text;;; Sample result: 2888.89 SQ. FT.;;; As this is a FIELD it is updated based on the FIELDEVAL;;; or the settings found in the OPTIONS dialog box

;;; By Jimmy Bergmark;;; Copyright (C) 2007-2010 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2007-09-05 - First release;;; 2009-08-02 - Updated to work in both modelspace and paperspace;;; 2010-10-29 - Updated to work also on 64-bit AutoCAD

;;; Uses TEXTSIZE for the text height

(defun Get-ObjectIDx64 (obj / util) (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object)))) (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj))) (if (= (type obj) 'VLA-OBJECT) (if (> (vl-string-search "x64" (getvar "platform")) 0) (vlax-invoke-method util "GetObjectIdString" obj :vlax-False) (rtos (vla-get-objectid obj) 2 0) ) ))

(defun c:AT (/ entObject entObjectID InsertionPoint ad) (vl-load-com) (setq entObject (vlax-ename->vla-object(car (entsel))) entObjectID (Get-ObjectIDx64 entObject) InsertionPoint (vlax-3D-Point (getpoint "Select point: ")) ad (vla-get-ActiveDocument (vlax-get-acad-object)) ) (vla-addMText (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) InsertionPoint 0.0 (strcat "%<\\AcObjProp Object(%<\\_ObjId " entObjectID ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%" )));;; By Jimmy Bergmark;;; Copyright (C) 2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; Created: 2008-03-31

Page 7: Lsp

;;;;;; Convert Attribute definitions to mtext;;;

(defun c:AttDefToMText (/ eset1 blkcnt en enlist tag1 ht pnt vl space) (setq eset1 (ssget (list (cons 0 "ATTDEF")))

blkcnt 0 )

(if eset1 (while (<= blkcnt (- (sslength eset1) 1)) (setq en (ssname eset1 blkcnt)

enlist (entget en) ht (cdr (assoc 40 enlist)) pnt (assoc 10 enlist) pnt (subst (+ ht (caddr pnt)) (caddr pnt) pnt) space (cdr (assoc 67 enlist))

) (setq vl (list

(cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (assoc 7 enlist) (assoc 8 enlist) pnt (assoc 40 enlist) (cond ((assoc 62 enlist)) ((cons 62 256)) ) (cons 1 (cdr (assoc 2 enlist))) (if (= space nil) (cons 67 0) (cons 67 space) )

) ) (entdel en) (entmake vl) (setq blkcnt (1+ blkcnt)) ) ) (setq eset1 nil));;; By Jimmy Bergmark;;; Copyright (C) 2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; Created: 2008-03-31;;;;;; Convert Attribute definitions to text;;;

(defun c:AttDefToText (/ eset1 blkcnt en enlist vl space) (setq eset1 (ssget (list (cons 0 "ATTDEF")))

blkcnt 0 )

(if eset1 (while (<= blkcnt (- (sslength eset1) 1)) (setq en (ssname eset1 blkcnt)

enlist (entget en) space (cdr (assoc 67 enlist))

Page 8: Lsp

) (setq vl (list

(cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (assoc 7 enlist) (assoc 8 enlist) (assoc 10 enlist) (assoc 40 enlist) (cond ((assoc 62 enlist)) ((cons 62 256)) ) (cons 1 (cdr (assoc 2 enlist))) (if (= space nil) (cons 67 0) (cons 67 space) )

) ) (entdel en) (entmake vl) (setq blkcnt (1+ blkcnt)) ) ) (setq eset1 nil));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; Updated: 2003-02-24;;;

;;; (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

;;; Erases all blocks named "revtext2";;; (ax:EraseBlock doc "revtext2")(defun ax:EraseBlock (doc bn / layout i) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (vla-Delete i) ) ) ))

;;; Test if block named "revtext2" exist;;; (ax:ExistBlock doc "revtext2")(defun ax:ExistBlock (doc bn / layout i exist) (setq exist nil) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (setq exist T) )

Page 9: Lsp

) ) exist)

;;; Rename block from "revtext" to "revtext1";;; (ax:RenameBlock doc "revtext" "revtext1")(defun ax:RenameBlock (doc bn nn / layout i) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (vla-put-name i nn) ) ) ))

;;; a list of all block names;;; return example ("*D5" "A$C263E5435" "b2" "b1")(defun ax:blocks (/ b bn tl) (vlax-for b (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (= (vla-get-islayout b) :vlax-false) (setq tl (cons (vla-get-name b) tl)) ) ) (reverse tl))

;;; a list of all xref names;;; return example ("xref1" "x2")(defun ax:xrefs (/ b bn tl) (vlax-for b (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (= (vla-get-isxref b) :vlax-true) (setq tl (cons (vla-get-name b) tl)) ) ) (reverse tl))

;;; Returns a list with references to a given block;;; (blockrefs <block name>);;; example: (blockrefs "b1");;; return: (<Entity name: 2ea6290> <Entity name: 2ea6288>);;; tip: if return is nil it's not inserted(defun blockrefs (bn / lst ed) (if (setq ed (tblobjname "block" bn)) (setq lst (entget (cdr (assoc 330 (entget ed))) ) ) ) (apply 'append (mapcar '(lambda (x) (list (cdr x))

Page 10: Lsp

) (cdr (reverse (cdr (member (assoc 102 lst) lst)))) ) ))

;;; Returns a list containing every reference to a given block;;; Arguments: a string identifying the block to search for(defun listblockrefs (blkName / lst) (setq lst (entget

(cdr (assoc 330 (entget (tblobjname "block" blkName)))) )

) (apply 'append (mapcar '(lambda (x)

(if (entget (cdr x)) (list (cdr x))

) ) (cdr (reverse (cdr (member (assoc 102 lst) lst))))

) ))

;;; Returns a list containing the entity names of block definitions that reference a given block;;; Arguments: a string identifying the block to search for(defun ax:GetParentBlocks (blkName / doc) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (apply 'append (mapcar '(lambda (x)

(if (= :vlax-false (vla-get-IsLayout

(vla-ObjectIdToObject doc (vla-get-OwnerId (vlax-ename->vla-object x)))

) ) (list x)

) ) (listblockrefs blkName)

) ))

;;; Deletes the specified subentity from its block definition;;; Arguments: the entity name of an item within a block reference;;; Returns: the remaining item count of the block definition;;; The drawing must be regenerated for the change to become visible(defun ax:DeleteObjectFromBlock (ent / doc blk) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))

ent (vlax-ename->vla-object ent)blk (vla-ObjectIdToObject doc (vla-get-OwnerID ent))

) (vla-Delete ent) (vla-get-Count blk))

;;; Adds the specified item to a given block definition

Page 11: Lsp

;;; Arguments: the entity name of a block reference;;; a selection set containing the objects to add;;; Returns: nil;;; The drawing must be regenerated for the change to become visible(defun ax:AddObjectsToBlock (blk ss / doc blkref blkdef inspt refpt) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))

blkref (vlax-ename->vla-object blk)blkdef (vla-Item (vla-get-Blocks doc) (vla-get-Name blkref))inspt (vlax-variant-value (vla-get-InsertionPoint blkref))ssarray (selectionset->array ss)refpt (vlax-3d-point '(0 0 0))

) (foreach ent (vlax-safearray->list ssarray) (vla-Move ent inspt refpt) ) (vla-CopyObjects doc ssarray blkdef) (foreach ent (vlax-safearray->list ssarray) (vla-Delete ent) ) (princ))

;;; Utility routine to convert a selection set to an ActiveX array(defun selectionset->array (ss / c r) (vl-load-com) (setq c -1) (repeat (sslength ss) (setq r (cons (ssname ss (setq c (1+ c))) r)) ) (setq r (reverse r)) (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 (1- (length r))) ) (mapcar 'vlax-ename->vla-object r) ))

;;; (ax:GetTagTextString doc "sheet-text" "client-drw")(defun ax:GetTagTextString (doc bn tagname / layout i atts tag str) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (setq str (vla-get-TextString tag)) ) ) )

Page 12: Lsp

) ) ) str)

;;; (ax:FindBlockTagValue (vla-get-activedocument (vlax-get-acad-object)) "blockname" "tagname" "tagvalue")(defun ax:FindBlockTagValue (doc bn tagname value / layout i atts tag sset c) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (progn (foreach tag (vlax-safearray->list atts) (if (and (= (strcase tagname) (strcase (vla-get-TagString tag)) ) (= value (vla-get-TextString tag)) ) (progn (if (not sset) (setq sset (ssadd (vlax-vla-object->ename i))) (ssadd (vlax-vla-object->ename i) sset) ) ) ) ) ) ) ) ) ) (sssetfirst nil sset))

;;; list of all "REV-NO" in block "revtext1" in order of y-coordinate, bottom to up;;; (ax:GetManyTags "revtext1" "REV-NO")(defun ax:GetManyTags (bn tag / ax lst) (foreach x (ax:ListBlockIns doc bn) (setq lst (cons (ax:GetTagTextStringByRef (cadddr x) tag) lst)) ) (reverse lst))

;;; list of all "REV-NO" in block "revtext2" in order of y-coordinate, bottom to up;;; (ax:SetManyTags "revtext2" "revtext1" "REV-NO" "REV-NO")(defun ax:SetManyTags (bn-to bn-from tag-to tag-from / ax lst i) (setq lst (ax:GetManyTags bn-from tag-from)) (setq i 0)

Page 13: Lsp

(foreach x (ax:ListBlockIns doc bn-to) (ax:PutTagTextStringByRef (cadddr x) tag-to (nth i lst)) (setq i (1+ i)) ))

;;; (ax:GetTagTextStringByRef #<VLA-OBJECT IAcadBlockReference 071b9e24> "REV-NO")(defun ax:GetTagTextStringByRef (br tagname / atts tag str) (if (and (= (vla-get-hasattributes br) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes br) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (setq str (vla-get-TextString tag)) ) ) ) str)

;;; (ax:PutTagTextString doc "sheet-text" "client-drw" "new value")(defun ax:PutTagTextString (doc bn tagname textstring / layout i atts tag) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-TextString tag textstring) ) ) (vla-update i) ) ) ) ))

;;; (ax:PutTagTextStringByRef #<VLA-OBJECT IAcadBlockReference 071b9e24> "REV-NO" "new value")(defun ax:PutTagTextStringByRef (br tagname textstring / atts tag) (if (and (= (vla-get-hasattributes br) :vlax-true) (safearray-value (setq atts

Page 14: Lsp

(vlax-variant-value (vla-getattributes br) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-TextString tag textstring) ) ) (vla-update br) ))

;;; (ax:ChangeTagHeight <doc> <block name> <tag name> <tag height>);;; (ax:ChangeTagHeight doc "sheet-text" "client-drw" 0.97)(defun ax:ChangeTagHeight (doc bn tagname tagheight / layout i atts tag) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-height tag tagheight) ) ) (vla-update i) ) ) ) ))

;;; List the insertion point and reference of a block in active layout;;; sort them by y-value;;; (ax:ListBlockIns doc "revtext1");;; return value example:;;; ((341.385 29.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071b9e24>);;; (341.385 34.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071b9e74>);;; (341.385 39.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071bd184>))(defun ax:ListBlockIns (doc bn / layout i pl) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (setq pl (cons (append (safearray-value

Page 15: Lsp

(vlax-variant-value (vla-get-InsertionPoint i)) ) (list i) ) pl ) ) ) ) ) ; sort by y-value (vl-sort pl (function (lambda (e1 e2) (< (cadr e1) (cadr e2)) ) ) ))

;;; Changes the insertion point of a tag;;; (ax:ChangeTagIns doc "sheet-text" "a3-scale" '(703.4722 17.8350 0))(defun ax:ChangeTagIns (doc bn tagname ins / layout i atts tag) (defun list->variantArray (ptsList / arraySpace sArray) (setq arraySpace (vlax-make-safearray vlax-vbdouble (cons 0 (- (length ptsList) 1)) ) ) (setq sArray (vlax-safearray-fill arraySpace ptsList)) (vlax-make-variant sArray) ) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-InsertionPoint tag (list->variantArray ins)) ) ) (vla-update i) ) ) ) ))

;;; Changes attributes on all block references matching <Tag Name>;;; (ChangeAttributes (list <Block Name> '(<Tag Name> . <Tag Value>) ...));;; (ChangeAttributes (list "testblock" '("TESTTAG2" . "item1") '("NEWTAG" . "tagvalue")))(defun ChangeAttributes (lst / sset item atts ename i) (setq i 0) (setq sset (ssget "X" (list '(0 . "INSERT") (cons 2 (car lst)))))

Page 16: Lsp

(if sset (repeat (sslength sset) (setq ename (ssname sset i)) (setq i (+ 1 i)) (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes (vlax-ename->vla-object ename)) ) ) ) (progn (foreach item (cdr lst) (mapcar '(lambda (x) (if (= (strcase (car item)) (strcase (vla-get-tagstring x)) ) (vla-put-textstring x (cdr item)) ) ) (vlax-safearray->list atts) ) ) (vla-update (vlax-ename->vla-object ename)) ) ) ) ) (setq sset nil))

;;; (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)));;; (ax:ChangeTagWidth <doc> <block name> <tag name> <tag height>);;; (ax:ChangeTagWidth doc "panel1" "drw-no" 0.97)(defun ax:ChangeTagWidth (doc bn tagname tagwidth / layout i atts tag) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i) ) ) ) ) (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-scalefactor tag tagwidth) ) ) (vla-update i) ) ) ) )

Page 17: Lsp

);;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected](vl-load-com);;; (ax:CreateVP (vla-get-activedocument (vlax-get-acad-object)) '(200 200 0) 150 100)

(defun ax:CreateVP (ad center width height / ps ent) (setq ps (vla-get-paperspace ad)) (vla-put-activespace ad acpaperspace) (vla-put-mspace ad :vlax-false) (setq ent (vla-addpviewport ps (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 2) ) center ) width height ) ) (vla-put-viewporton ent :vlax-true) (vla-display ent :vlax-true) (vla-update ent));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

;;; Example of inserting a block with ActiveX in modelspace;;;;;; (ax:insert (vla-get-activedocument (vlax-get-acad-object));;; "r:\\projekt\\4045\\B\\revtext3.dwg" "0";;; '(160 120 0) 1 1 1 0)(vl-load-com)(defun ax:insert (doc bn layer ins x y z rt) (setq layer (vla-item (vla-get-layers doc) layer)) ; put the layer on (vla-put-LayerOn layer 1) ; cannot thaw if active layer is 0 (vl-catch-all-apply 'vla-put-Freeze (list layer :vlax-false)) ; put active layer (vla-put-activeLayer doc layer) (setq ins (list->variantArray ins)) (vla-insertblock (vla-get-modelspace doc) ins bn x y z rt))

(defun list->variantArray (ptsList / arraySpace sArray) (setq arraySpace (vlax-make-safearray vlax-vbdouble (cons 0 (- (length ptsList) 1)) ) ) (setq sArray (vlax-safearray-fill arraySpace ptsList)) (vlax-make-variant sArray) )

Page 18: Lsp

;;; BackgroundChanger.LSP ver 1.0;;; Lets you change the background in a simple way;;; Works for both model space and paper space but could simply be customized for your need;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2004 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2003-07-01 - First release;;; Tested on AutoCAD 2002, 2004, 2005

; Set the background in model and paper space to grey(defun c:BGGrey () (vl-load-com) (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object)))) (vla-put-GraphicsWinModelBackgrndColor disp 5987163) (vla-put-GraphicsWinLayoutBackgrndColor disp 5987163) (vla-put-LayoutCrosshairColor disp 16777215) (vla-put-ModelCrosshairColor disp 16777215) (vla-put-AutoTrackingVecColor disp 16777215) (vla-put-AutoSnapMarkerColor drafting 2) (princ))

; Set the background in model and paper space to white(defun c:BGWhite () (vl-load-com) (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object)))) (vla-put-GraphicsWinModelBackgrndColor disp 16777215) (vla-put-GraphicsWinLayoutBackgrndColor disp 16777215) (vla-put-LayoutCrosshairColor disp 0) (vla-put-ModelCrosshairColor disp 0) (vla-put-AutoTrackingVecColor disp 0) (vla-put-AutoSnapMarkerColor drafting 6) (princ))

; Set the background in model and paper space to black(defun c:BGBlack () (vl-load-com) (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object)))) (vla-put-GraphicsWinModelBackgrndColor disp 0) (vla-put-GraphicsWinLayoutBackgrndColor disp 0) (vla-put-LayoutCrosshairColor disp 16777215) (vla-put-ModelCrosshairColor disp 16777215) (vla-put-AutoTrackingVecColor disp 16777215) (vla-put-AutoSnapMarkerColor drafting 2) (princ))

; Background toggle between black and white(defun c:bgt () (vl-load-com) (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object)))) (if (= (vlax-variant-value

(vlax-variant-change-type (vla-get-graphicswinmodelbackgrndcolor disp) vlax-vblong )

Page 19: Lsp

) 0

) (c:bgwhite) (c:bgblack) ) (princ))

(princ);;; BlockToXref.LSP;;; Convert Blocks to Xrefs

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

;;; 2000-04-03 - First release;;; Supports nested blocks, multiple tabs;;; Tested on AutoCAD 2000

(defun c:btx () (c:BlockToXref))(defun c:BlockToXref (/ errexit undox olderr restore errexitA2k ss ss1 e1 ix path bsl bn bnl bl bt not_ok repl oldvport oldregenmode typ ed layer color ltype ang ins tab oldtab ) (defun errexit (s) (princ "\nError: ") (princ s) (restore) )

(defun undox () (setq ss1 nil) (setq ss2 nil) (setvar "ctab" oldtab) (if (> oldcvport 1) (command "._mspace") (command "._pspace")) (setvar "cvport" oldcvport) (setvar "regenmode" oldregenmode) (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setq oldtab (getvar "ctab")) (setq oldcvport (getvar "cvport")) (setq oldregenmode (getvar "regenmode")) (setvar "cmdecho" 0) (setvar "regenmode" 0) (command "._UNDO" "_BE") (setq A2k (wcmatch (getvar "ACADVER") "15*")) (if (and A2k (/= (setq ss1 (ssget '((0 . "INSERT")))) nil)) (progn (vl-load-com)

Page 20: Lsp

(setq ix 0) (setq bsl nil) ; block selection list (setq bnl nil) ; unique block name list (repeat (sslength ss1) (setq e1 (ssname ss1 ix)) (setq bn (cdr (assoc 2 (entget e1)))) ; block name (setq bl (tblsearch "block" bn)) ; block list bn (setq bt (cdr (assoc 70 bl))) ; block type (if (and (/= (logand bt 4) 4) (not (member bn bnl))) ; no xrefs and no duplicates (setq bnl (cons bn bnl)) ) (setq ix (1+ ix)) ); end repeat

(foreach bn bnl (setq ss1 (ssget "X" (list (cons 0 "INSERT") (cons 2 bn)))) (setq ix 0) (repeat (sslength ss1) (setq e1 (ssname ss1 ix)) (setq bsl (cons (entget e1) bsl)) (setq ix (1+ ix)) ) ); end repeat

(foreach bn bnl (setq not_ok T) (while not_ok (setq path (getfiled "Match the block to a file" (if (not path) (strcat (getvar "dwgprefix") bn) (strcat (vl-filename-directory path) "\\" bn)) "dwg" 0)) (if path (if (= (strcase (vl-filename-base path)) (strcase bn)) (setq not_ok nil) (progn (initget 0 "Yes No") (setq repl (getkword "\nAssign a different name? [Yes/No] <No>: ")) (if (not repl) (setq repl "Yes")) (if (= "Yes" repl) (setq not_ok nil) (setq not_ok T) ) ) ) ) (if (not not_ok) (progn (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 bn)))) (setq ix 0) (repeat (sslength ss) (setq ed (ssname ss ix)) (setq tab (cdr (assoc 410 (entget ed)))) (setvar "ctab" tab) (entdel ed) (setq ix (1+ ix)) ) (repeat 10 (vl-cmdf "._purge" "_b" "*" "N") ) (initget 0 "Overlay Attach") (setq repl (getkword "\nEnter an option [Overlay/Attach] <Attach>: ")) (if (not repl) (setq repl "Attach")) (if (= "Attach" repl) (setq typ "_A") (setq typ "_O")) (setq ix 0)

Page 21: Lsp

(repeat (length bsl) (setq ed (nth ix bsl)) (if (= bn (cdr (assoc 2 ed))) (progn (setq layer (cdr (assoc 8 ed))) (setq color (cdr (assoc 62 ed))) (if (not color) (setq color "_ByLayer")) (setq ltype (cdr (assoc 6 ed))) (if (not ltype) (setq ltype "_ByLayer")) (setq ang (/ (* 180.0 (cdr (assoc 50 ed))) pi)) (setq ins (cdr (assoc 10 ed))) (setq tab (cdr (assoc 410 ed))) (setvar "ctab" tab) (if (/= tab "Model") (command "._pspace")) (vl-cmdf "._xref" typ path "_X" (cdr (assoc 41 ed)) "_Y" (cdr (assoc 42 ed)) "_Z" (cdr (assoc 43 ed)) ins ang) (vl-cmdf "._change" "_L" "" "_P" "_C" color "_LA" layer "_LT" ltype "") ) ) (setq ix (1+ ix)) ) ) ) (if (= path nil) (setq not_ok nil)) ) ) ); end progn ); end if (setq ss1 nil) (restore));;;---------------------------------------------------------------------------;;;;;;; bomlengths.lsp;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2007 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 1998-03-31 - First release;;; 2000-05-11 - Fixed for LWPOLYLINES and for A2k;;; 2003-06-10 - Tested on 2004 and fixed a minor bug;;; 2004-03-18 - Added (vl-load-com);;; 2007-09-24 - Shows the result in the active unit;;; Tested on AutoCAD 2000, 2004, 2005, 2008;;; should be working on older versions too with minor modifications.;;; exchange bom-code-old with bom-code;;;;;;---------------------------------------------------------------------------;;;; DESCRIPTION;;;;;; BILL OF LENGTHS. Get the accumulated sum length of multiple objects.;;; c:bomlengths - length of lines, arcs, polylines and splines and total.;;; c:bom_lines - length of lines and total.;;; c:bom_arcs - length of arcs, and total.;;; c:bom_polylines - length of polylines and total.;;; c:bom_splines - length of splines and total.;;;---------------------------------------------------------------------------;

(defun dxf (n ed) (cdr (assoc n ed)))

(defun bom-code (ssfilter / errexit undox restore *error* olderr oldcmdecho %l %t

Page 22: Lsp

sset %i en ed p1 p2 ot a1 a2 r ) (defun errexit (s) (princ) (restore) )

(defun undox () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (setq %i 0 %t 0 ) (vl-load-com) (setq sset (ssget ssfilter)) (if sset (progn (princ "\nLengths:") (repeat (sslength sset)

(setq en (ssname sset %i)) (setq ed (entget en)) (setq ot (dxf 0 ed)) (setq curve (vlax-ename->vla-object en)) (if (vl-catch-all-error-p

(setq len (vl-catch-all-apply 'vlax-curve-getDistAtParam

(list curve (vl-catch-all-apply 'vlax-curve-getEndParam (list curve) )))))

nil len ) (setq %l len)

(setq %i (1+ %i) %t (+ %l %t) )

(terpri) ;(princ %l ) (princ (rtos %l (getvar "lunits")(getvar "luprec")))

) (princ "\nTotal = ") ;(princ %t) (princ (rtos %t (getvar "lunits")(getvar "luprec"))) (textpage) ) ) (setq sset nil) (restore)

Page 23: Lsp

)

(defun bom-code-old (ssfilter / errexit undox restore *error* olderr oldcmdecho %l %t sset %i en ed p1 p2 ot a1 a2 r ) (defun errexit (s) (princ) (restore) )

(defun undox () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (setq %i 0 %t 0 ) (setq sset (ssget ssfilter)) (if sset (progn (princ "\nLengths:") (repeat (sslength sset) (setq en (ssname sset %i)) (setq ed (entget en)) (setq ot (dxf 0 ed)) (cond ((= ot "LINE") (setq p1 (dxf 10 ed) p2 (dxf 11 ed) %l (distance p1 p2) ) ) ((= ot "ARC") (setq a1 (dxf 50 ed) a2 (dxf 51 ed) r (dxf 40 ed) %l (* r (abs (- a2 a1))) ) ) (t (command "._area" "_obj" en) (setq %l (getvar "perimeter"))

) ) (setq %i (1+ %i) %t (+ %l %t) ) (terpri) (princ %l) )

Page 24: Lsp

(princ "\nTotal = ") (princ %t) (textpage) ) ) (setq sset nil) (restore))

(defun c:bomlengths () (initget "Lines Arcs Polylines Splines ALL") (setq ans (getkword "Enter an option [Lines/Arcs/Polylines/Splines] <ALL>: " ) ) (cond ((= ans "Lines") (c:bom_lines)) ((= ans "Arcs") (c:bom_arcs)) ((= ans "Polylines") (c:bom_polylines)) ((= ans "Splines") (c:bom_splines)) (t (bom-code '((-4 . "<OR") (0 . "LINE") (0 . "ARC") (0 . "POLYLINE") (0 . "LWPOLYLINE") (0 . "SPLINE") (-4 . "OR>") ) ) ) ) (princ))

(defun c:bom_lines () (bom-code '((0 . "LINE"))) (princ))

(defun c:bom_arcs () (bom-code '((0 . "ARC"))) (princ))

(defun c:bom_polylines () (bom-code '((-4 . "<OR") (0 . "POLYLINE") (0 . "LWPOLYLINE") (-4 . "OR>") ) ) (princ))

(defun c:bom_splines () (bom-code '((0 . "SPLINE"))) (princ))

(defun c:CreateLT() (vl-load-com) (setq pDoc (vla-get-ActiveDocument (vlax-get-acad-object)))

Page 25: Lsp

;get the DBConnect(setq pDBObj (vla-GetInterfaceObject (vlax-get-acad-object) "CAO.dbConnect"))

(if (null pDBObj) (progn (alert "Cannot create CAO Automation server.") (exit)))

;get the linktemplates (setq pLTs(vlax-invoke-method pDBObj "GetLinkTemplates" pDoc))

;prepare the keydescriptions (setq pKeyDescs (vla-GetInterfaceObject (vlax-get-acad-object) "CAO.KeyDescriptions")) (vlax-invoke-method pKeyDescs "ADD" "TAG_NUMBER" 3 nil nil) (vlax-invoke-method pKeyDescs "ADD" "Manufacturer" 1 nil nil) ;create two link templates (vlax-invoke-method pLTs "ADD" "jet_dbsamples" nil nil "COMPUTER" "LTCreatedByVLispCAO" pKeyDescs) (vlax-invoke-method pLTs "ADD" "jet_dbsamples" nil nil "COMPUTER" "LTtobeDeleted" pKeyDescs)

;sample code to show how to delete the link template (vlax-invoke-method pLTs "delete" "LTtobeDeleted") );;; c:ChangeNoPlottableLayers;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

;;; 2000-03-13;;; 2003-01-08 - Handle frozen/off/locked defpoints layer by thawing/on/unlocking it;;; Tested on AutoCAD 2000, 2002;;;;;; This is useful when you want to save a file to;;; r14 or older.;;; It tries to move all entities from layers that;;; are not plottable to layer defpoints.;;;(vl-load-com)(defun c:ChangeNoPlotLayers (/ ad layer ss) (layer-set "defpoints") (setq ad (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vlax-for layer (vla-get-Layers ad) (cond ((eq (vla-get-plottable layer) :vlax-true)) ((/= (vla-get-name layer) "defpoints") (vla-put-Freeze layer :vlax-false) (vla-put-Lock layer :vlax-false) (GlobalChangeLayer (vla-get-name layer) "defpoints") ) ) ) (command "._regenall") (princ))

;;; By Tony Tanzillo ?

Page 26: Lsp

(defun GlobalChangeLayer (oldlayer newlayer / ent old new) (setq old (cons 8 (getLayerName oldlayer))) (setq new (cons 8 (getLayerName newlayer))) (BlockEntityIterator '(lambda (e) (changeLayer e old new) ) ) (setq ent (entnext)) (while ent (changeLayer ent old new) (setq ent (entnext ent)) ))

(defun getLayerName (name) (cdr (assoc 2 (tblsearch "layer" name))))

(defun BlockEntityIterator (bei_Func / bei_block bei_ent) (while (setq bei_block (tblnext "block" (not bei_block))) (setq bei_ent (cdr (assoc -2 bei_block))) (while bei_ent (apply bei_func (list bei_ent)) (setq bei_ent (entnext bei_ent)) ) ))

(defun ChangeLayer (ent old new / data) (setq data (entget ent)) (if (equal (assoc 8 data) old) (entmod (subst new old data)) ))

; Not by me(defun layer-set (layer / e d c f) (cond ; _________________ ; ; layer exists ; ensure "settable" ; set current ; _________________

( (setq e (tblobjname "layer" layer)) (setq d (entget e) ; data c (cdr (assoc 62 d)) ; color f (cdr (assoc 70 d)) ; flags ) (if (minusp c) ; layer is off, force abs of color (setq d (subst (cons 62 (abs c)) (assoc 62 d) d)) ) (if (eq 1 (logand 1 f)) ; layer is frozen, mask off 1 (setq f (boole 6 f 1)) ) (if (eq 4 (logand 4 f)) ; layer is locked, mask off 4 (setq f (boole 6 f 4))

Page 27: Lsp

) ; did we change the flag value? (if (not (eq f (cdr (assoc 70 d)))) (setq d (subst (cons 70 f) (assoc 70 d) d)) ) ; did we change the dxf data at all? (if (not (equal d (entget e))) (entmod d) ) ; set layer current, return ; layer name to calling function (setvar "clayer" layer) ) ; _____________________ ; ; layer doesn't exist, ; symbol name is valid, ; make it / set it ; _____________________

( (snvalid layer) (if (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 layer) '(70 . 0) '(62 . 7) '(6 . "CONTINUOUS") ) ) ; ______________________________ ; ; if entmake was successful ; set layer current, return ; layer name to calling function ; ______________________________

(setvar "clayer" layer) ) ) ; _____________________ ; ; layer doesn't exist ; symbol name invalid ; return nil to calling ; function ; _____________________

))

;;;;;; =========================================================================;;; DIMLINECHANGE.LSP;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

Page 28: Lsp

;;;;;; 2000-03-02;;;;;; Description: Changes selected line on a dimension to current layer.;;; This layer can be with another linetype.;;; So, it can be used for dimensioning to centerlines.;;;(defun C:DIMLINECHANGE (/ nents nlst ent nen lasten pen ent en oe tbl)

(defun *error* (MSG) (princ MSG) (princ) )

(if (setq nents (nentsel)) (progn (setq nen (car nents)) (if (setq nlst (cadddr nents))

(if (> (length nlst) 1) (*error* "Nested block!\n"))(*error* "\nNo dimension selected!")

) (setq pen (car nlst)) (if (= (cdr (assoc 0 (entget pen))) "DIMENSION")

(cond ((= (cdr (assoc 0 (setq ent (entget nen)))) "LINE") (if (setq

tbl (tblsearch "BLOCK" (cdr (assoc 2 (entget pen)))) ) (progn (entmake tbl) (setq en (cdr (assoc -2 tbl))) (while (not lasten)

(setq ent (entget en)) (if (equal nen (cdr (assoc -1 ent))) (progn (setq ent (subst (cons 8 (getvar "clayer"))

(assoc 8 ent) ent

) ) (entmake ent) ) (entmake ent) ) (if (= (cdr (assoc 0 ent)) "ENDBLK") (setq lasten T) (setq lasten (not (setq en (entnext en)))) )

) (if (entmake (list (cons 0 "ENDBLK")))

(entupd pen) ) ) ) ) (T (prompt "\nSelect a dimensionline.")))(prompt "\nNo dimension selected!")

) ) )

Page 29: Lsp

(princ))

(defun C:DLC () (C:DIMLINECHANGE))(princ "\nLoaded command DIMLINECHANGE (or short DLC)")(princ "\n(c) Jimmy Bergmark - 2000.")(princ)

;;; DisplayColorProperties.LSP;;; Miscellaneous commands related to Colors on the Display tab on the Options dialog;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-03-29 - First release;;; 2003-03-07 - Now for AutoCAD 2004;;; Tested on AutoCAD 2000, 2000i, 2002 and 2004

(vl-load-com)

(setq pref (vla-get-preferences (vlax-get-acad-object)))

(setq display (vla-get-display pref))

;;; Set the ModelColor using the color dialog box(defun c:SetModelColor(/ col oldcol) (setq oldcol (getGraphicsWinModelBackgrndColor)) (if (= oldcol nil) (setq oldcol 0)) (if (= oldcol 0) (setq oldcol 1)) (setq col (acad_colordlg oldcol nil)) (if (and (= oldcol 7) (= col 7)) (setq col 0)) (if (/= col nil) (putGraphicsWinModelBackgrndColor col)) (princ))(defun c:SetModelColor2004(/ col oldcol) (setq oldcol (getGraphicsWinModelBackgrndColor2004)) (if (= oldcol nil) (setq oldcol 0)) (if (= oldcol 0) (setq oldcol 1)) (setq col (acad_colordlg oldcol nil)) (if (and (= oldcol 7) (= col 7)) (setq col 0)) (if (/= col nil) (putGraphicsWinModelBackgrndColor col)) (princ))

;;; Set the LayoutColor using the color dialog box(defun c:SetLayoutColor(/ col oldcol) (setq oldcol (getGraphicsWinLayoutBackgrndColor)) (if (= oldcol nil) (setq oldcol 0)) (if (= oldcol 0) (setq oldcol 1)) (setq col (acad_colordlg oldcol nil)) (if (and (= oldcol 7) (= col 7)) (setq col 0)) (if (/= col nil) (putGraphicsWinLayoutBackgrndColor col)) (princ))

(defun getGraphicsWinModelBackgrndColor() (OLE_color->ACI_color (vla-get-GraphicsWinModelBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun getGraphicsWinModelBackgrndColor2004 ()

Page 30: Lsp

(OLE_colorToACI (vlax-variant-value (vlax-variant-change-type

(vla-get-GraphicsWinModelBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object)) ))vlax-vbLong

) ) ))

(defun putGraphicsWinModelBackgrndColor(col) (vla-put-GraphicsWinModelBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getGraphicsWinLayoutBackgrndColor() (OLE_color->ACI_color (vla-get-GraphicsWinLayoutBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun putGraphicsWinLayoutBackgrndColor(col) (vla-put-GraphicsWinLayoutBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getModelCrosshairColor() (OLE_color->ACI_color (vla-get-ModelCrosshairColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun putModelCrosshairColor(col) (vla-put-ModelCrosshairColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getLayoutCrosshairColor() (OLE_color->ACI_color (vla-get-LayoutCrosshairColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun putLayoutCrosshairColor(col) (vla-put-LayoutCrosshairColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getTextWinBackgrndColor() (OLE_color->ACI_color (vla-get-TextWinBackgrndColor

Page 31: Lsp

(vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun putTextWinBackgrndColor(col) (vla-put-TextWinBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getTextWinTextColor() (OLE_color->ACI_color (vla-get-TextWinTextColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

(defun putTextWinTextColor(col) (vla-put-TextWinTextColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) (ACI_color->OLE_color col) ))

(defun getAutoTrackingVecColor() (OLE_color->ACI_color (vla-get-AutoTrackingVecColor display)))

(defun putAutoTrackingVecColor(col) (vla-put-AutoTrackingVecColor display (ACI_color->OLE_color col) ))

(defun OLE_color->ACI_color (olec) (vl-position (boole 1 (vlax-variant-value (vlax-variant-change-type olec vlax-vbLong) ) 16777215 ) OLE_COLOR_LIST ))

(defun ACI_color->OLE_color (aci) ; black is 0 ; white is 7 (if (and (>= aci 0) (<= 255)) (setq aci (nth aci OLE_COLOR_LIST) ) ))

(setq OLE_COLOR_LIST '(0 255 65535 65280 16776960 16711680 16711935 16777215 8421504 12632256 255 8421631 166 5460902 128

Page 32: Lsp

4210816 76 2500172 38 1250086 16639 8429567 10662 5466278 8320 4214912 4940 2502732 2598 1251366 33023 8437759 21414 5471398 16512 4219008 9804 2505036 4902 1252646 49151 8445951 31910 5476774 24704 4223104 14668 2507596 7462 1253670 65535 8454143 42662 5482150 32896 4227200 19532 2509900 9766 1254950 65471 8454111 42620 5482129 32864 4227184 19513 2509891 9757 1254945 65408 8454079 42579 5482108 32832 4227168 19494 2509881 9747 1254941 65344 8454047 42537 5482088 32800 4227152 19475 2509872 9738 1254936 65280 8454016 42496 5482067 32768 4227136 19456 2509862 9728 1254931 4259584 10485632 2729472 6858323 2129920 5275712 1264640 3165222 665088 1582611 8453888 12582784 5481984 8169043 4227072 6324288 2509824 3755046 1254912 1910291 12582656 14679936 8168960 9545299 6324224 7372864 3755008 4410406 1910272 2172435 16776960 16777088 10921472 10921555 8421376 8421440 5000192 5000230 2500096 2500115 16760576 16768896 10910720 10916179 8413184 8417344 4995328 4997926 2497792 2498835 16744448 16760704 10900224 10910803 8404992 8413248 4990464 4995366 2495232 2497811 16728064 16752512 10889472 10905683 8396800 8409152 4985600 4993062 2492928 2496531 16711680 16744576 10878976 10900307 8388608 8405056 4980736 4990502 2490368 2495251 16711744 16744607 10879017 10900328 8388640 8405072 4980755 4990512 2490378 2495256 16711808 16744639 10879059 10900348 8388672 8405088 4980774 4990521 2490387 2495261 16711871 16744671 10879100 10900369 8388704 8405104 4980793 4990531 2490397 2495265 16711935 16744703 10879142 10900390 8388736 8405120 4980812 4990540 2490406 2495270 12517631 14647551 8126630 9524134 6291584 7356544 3735628 4400716 1900582 2167590 8388863 12550399 5439654 8147878 4194432 6307968 2490444 3745356 1245222 1905446 4194559 10453247 2687142 6837158 2097280 5259392 1245260 3155532 655398 1577766 5526612 5987163 10000536 12303291 14540253 16777215 ))

;;; Only for AutoCAD 2004 (defun RGBtoACI (RGB-codes) (vl-load-com) (setq ColorObj (vla-GetInterfaceObject (vlax-get-acad-object) "AutoCAD.AcCmColor.16" ) ) (vla-setRGB ColorObj (car RGB-codes) (cadr RGB-codes) (caddr RGB-codes)) ; alternatively done as below ; (vlax-invoke-method ColorObj 'setRGB (car RGB-codes) (cadr RGB-codes) (caddr RGB-codes))

Page 33: Lsp

(vla-get-ColorIndex ColorObj) )

(defun RGBtoOLE_color2 (RGB-codes) (+ (* (car RGB-codes) 65536) (* (cadr RGB-codes) 256) (caddr RGB-codes) ) )

(defun OLEtoRGB_color2 (OLE_color / a b c) (setq a (fix (/ OLE_color 65536.0))) (setq b (fix (/ (- OLE_color (* a 65536)) 256.0))) (setq c (- OLE_color (* a 65536) (* b 256))) (list a b c) )

;; Convert TrueColor into a list of RGB(defun OLEtoRGB_color (OLE_color / r g b) (setq r (lsh OLE_color -16)) (setq g (lsh (lsh OLE_color 16) -24)) (setq b (lsh (lsh OLE_color 24) -24)) (list r g b))

;; Convert a list of RGB to TrueColor;;; (RGBtoOLE_color '(118 118 118))(defun RGBtoOLE_color (RGB-codes) (setq r (lsh (car RGB-codes) 16)) (setq g (lsh (cadr RGB-codes) 8)) (setq b (caddr RGB-codes)) (+ (+ r g) b))

; For AutoCAD 2004; (OLE_colorToACI 5987163) returns 251(defun OLE_colorToACI (OLE_color) (RGBtoACI (OLEtoRGB_color OLE_color)))

(defun C:getColor(/) (setq ename (car (entsel "\nPick an object with true color:"))) (setq edata (entget ename)) ;; we have a true color. (setq tcol (cdr (assoc 420 edata))) (princ "\n true color = ")(princ tcol) ;; convert it to a list of RGB. (setq rgb (OLEtoRGB_color tcol)) (princ "\n rgb = ")(princ rgb) (princ)) (defun C:setColor(/) (setq ename (car (entsel "\nPick an object to set a true color:"))) (setq edata (entget ename)) ;; set a true color from a list of rgb values.(R=10 G=100 B=200) (setq rgb (list 10 100 200)) (setq tcol (RGBtoOLE_color rgb)) ;; and set it. (setq edata (subst (cons 420 tcol) (assoc 420 edata) edata)) (entmod edata) (princ "\n rgb = ")(princ rgb) (princ "\n true color = ")(princ tcol)

Page 34: Lsp

(princ))

;;; (ACItoRGB 123)(defun ACItoRGB (aci) (if (and (>= aci 0) (<= 255)) (nth aci RGB_list) ))

(setq RGB_list '( (0 0 0) (255 0 0) (255 255 0) (0 255 0) (0 255 255) (0 0 255) (255 0 255) (255 255 255) (128 128 128) (192 192 192) (255 0 0) (255 127 127) (165 0 0) (165 82 82) (127 0 0) (127 63 63) (76 0 0) (76 38 38) (38 0 0) (38 19 19) (255 63 0) (255 159 127) (165 41 0) (165 103 82) (127 31 0) (127 79 63) (76 19 0) (76 47 38) (38 9 0) (38 23 19) (255 127 0) (255 191 127) (165 82 0) (165 124 82) (127 63 0) (127 95 63) (76 38 0) (76 57 38) (38 19 0) (38 28 19) (255 191 0) (255 223 127) (165 124 0) (165 145 82) (127 95 0) (127 111 63) (76 57 0) (76 66 38) (38 28 0) (38 33 19) (255 255 0)

Page 35: Lsp

(255 255 127) (165 165 0) (165 165 82) (127 127 0) (127 127 63) (76 76 0) (76 76 38) (38 38 0) (38 38 19) (191 255 0) (223 255 127) (124 165 0) (145 165 82) (95 127 0) (111 127 63) (57 76 0) (66 76 38) (28 38 0) (33 38 19) (127 255 0) (191 255 127) (82 165 0) (124 165 82) (63 127 0) (95 127 63) (38 76 0) (57 76 38) (19 38 0) (28 38 19) (63 255 0) (159 255 127) (41 165 0) (103 165 82) (31 127 0) (79 127 63) (19 76 0) (47 76 38) (9 38 0) (23 38 19) (0 255 0) (127 255 127) (0 165 0) (82 165 82) (0 127 0) (63 127 63) (0 76 0) (38 76 38) (0 38 0) (19 38 19) (0 255 63) (127 255 159) (0 165 41) (82 165 103) (0 127 31) (63 127 79) (0 76 19) (38 76 47) (0 38 9) (19 38 23) (0 255 127) (127 255 191) (0 165 82) (82 165 124)

Page 36: Lsp

(0 127 63) (63 127 95) (0 76 38) (38 76 57) (0 38 19) (19 38 28) (0 255 191) (127 255 223) (0 165 124) (82 165 145) (0 127 95) (63 127 111) (0 76 57) (38 76 66) (0 38 28) (19 38 33) (0 255 255) (127 255 255) (0 165 165) (82 165 165) (0 127 127) (63 127 127) (0 76 76) (38 76 76) (0 38 38) (19 38 38) (0 191 255) (127 223 255) (0 124 165) (82 145 165) (0 95 127) (63 111 127) (0 57 76) (38 66 76) (0 28 38) (19 33 38) (0 127 255) (127 191 255) (0 82 165) (82 124 165) (0 63 127) (63 95 127) (0 38 76) (38 57 76) (0 19 38) (19 28 38) (0 63 255) (127 159 255) (0 41 165) (82 103 165) (0 31 127) (63 79 127) (0 19 76) (38 47 76) (0 9 38) (19 23 38) (0 0 255) (127 127 255) (0 0 165) (82 82 165) (0 0 127) (63 63 127) (0 0 76)

Page 37: Lsp

(38 38 76) (0 0 38) (19 19 38) (63 0 255) (159 127 255) (41 0 165) (103 82 165) (31 0 127) (79 63 127) (19 0 76) (47 38 76) (9 0 38) (23 19 38) (127 0 255) (191 127 255) (82 0 165) (124 82 165) (63 0 127) (95 63 127) (38 0 76) (57 38 76) (19 0 38) (28 19 38) (191 0 255) (223 127 255) (124 0 165) (145 82 165) (95 0 127) (111 63 127) (57 0 76) (66 38 76) (28 0 38) (33 19 38) (255 0 255) (255 127 255) (165 0 165) (165 82 165) (127 0 127) (127 63 127) (76 0 76) (76 38 76) (38 0 38) (38 19 38) (255 0 191) (255 127 223) (165 0 124) (165 82 145) (127 0 95) (127 63 111) (76 0 57) (76 38 66) (38 0 28) (38 19 33) (255 0 127) (255 127 191) (165 0 82) (165 82 124) (127 0 63) (127 63 95) (76 0 38) (76 38 57) (38 0 19) (38 19 28)

Page 38: Lsp

(255 0 63) (255 127 159) (165 0 41) (165 82 103) (127 0 31) (127 63 79) (76 0 19) (76 38 47) (38 0 9) (38 19 23) (0 0 0) (51 51 51) (102 102 102) (153 153 153) (204 204 204) (255 255 255))

)

;;; Examples;;; ;;; (RGBtoACI '(91 91 91)) returns 251;;; (RGBtoACI '(118 118 118)) returns 8;;; (RGBtoOLE_color '(118 118 118)) gives OLE_color=7763574;;; (OLEtoRGB_color 7763574) gives (118 118 118);;; (RGBtoOLE_color '(91 91 91)) gives OLE_color=5987163;;; (OLEtoRGB_color 5987163) gives (91 91 91);;; (RGBtoACI '(101 101 101)) returns 8;;; (OLEtoRGB_color 6645093) returns (101 101 101);;; (ACItoRGB 123)

;;; Missing is conversion from ACI to RGB or ACI to OLE_color;;; DisplayProperties.LSP;;; Miscellaneous commands related to the Display tab on the Options dialog;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-03-29 - First release;;; Tested on AutoCAD 2000

(vl-load-com)

; Get Model Space Background Color(defun getMoBgColor() (ole_color (vla-get-GraphicsWinModelBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

; Get Layout Space Background Color(defun getLaBgColor() (ole_color (vla-get-GraphicsWinLayoutBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))))))

; Put Model Space Background Color(defun putMoBgColor(bgc) (vla-put-GraphicsWinModelBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) bgc )

Page 39: Lsp

)

; Put Layout Space Background Color(defun putLaBgColor(bgc) (vla-put-GraphicsWinLayoutBackgrndColor (vla-get-display (vla-get-preferences (vlax-get-acad-object))) bgc ))

(defun ole_color(olec) (vlax-variant-value (vlax-variant-change-type olec vlax-vbDouble) ))

; Get the display of the Plot Setup dialog when a new layout is created. (defun getLayoutShowPlotSetup() (vla-get-LayoutShowPlotSetup (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))

; Put the display of the Plot Setup dialog when a new layout is created. (defun putLayoutShowPlotSetup(state) (vla-put-LayoutShowPlotSetup (vla-get-display (vla-get-preferences (vlax-get-acad-object))) state))

; Toggles the display of the Plot Setup dialog when a new layout is created. (defun toggleLayoutShowPlotSetup() (if (= (getLayoutShowPlotSetup) :vlax-true) (putLayoutShowPlotSetup :vlax-false) (putLayoutShowPlotSetup :vlax-true) ))

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected](vl-load-com); (setq ad (vla-get-activedocument (vlax-get-acad-object)))

(defun GetCanonicalMediaNames (ad) (vla-RefreshPlotDeviceInfo (vla-get-activelayout ad)) (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames (vla-item (vla-get-layouts ad) "Model")))))

(defun GetLocaleMediaNames (ad / mn mnl) (setq la (vla-item (vla-get-layouts ad) "Model")) (foreach mn (GetCanonicalMediaNames ad) (setq mnl (cons (vla-GetLocaleMediaName la mn) mnl)) ) (reverse mnl))

(defun GetPlotDevices (ad) (vla-RefreshPlotDeviceInfo

Page 40: Lsp

(vla-get-activelayout ad)) (vlax-safearray->list (vlax-variant-value (vla-getplotdevicenames (vla-item (vla-get-layouts ad) "Model")))))

; Plot Device in active Layout(defun GetActivePlotDevice (ad) (vla-get-ConfigName (vla-get-ActiveLayout ad)))

(defun GetPlotStyleTableNames (ad) (vla-RefreshPlotDeviceInfo (vla-get-activelayout ad)) (vlax-safearray->list (vlax-variant-value (vla-getplotstyletablenames (vla-item (vla-get-layouts ad) "Model")))))

(defun ListAllMediaNames(ad / al cn pd apmn) (setq al (vla-get-activelayout ad)) (setq cn (vla-get-configname al)) (foreach pd (GetPlotDevices ad) (if (/= pd "None") (progn (vla-put-configname al pd) (setq apmn (cons pd apmn)) (setq apmn (cons (GetCanonicalMediaNames ad) apmn)) ) ) ) (if (/= cn "None") (vla-put-configname al cn)) (reverse apmn))

; (ListAllLocalMediaNames (vla-get-activedocument (vlax-get-acad-object)))(defun ListAllLocalMediaNames(ad / al cn pd apmn) (setq al (vla-get-activelayout ad)) (setq cn (vla-get-configname al)) (foreach pd (GetPlotDevices ad) (if (/= pd "None") (progn (vla-put-configname al pd) (setq apmn (cons pd apmn)) (setq apmn (cons (GetLocaleMediaNames ad) apmn)) ) ) ) (if (/= cn "None") (vla-put-configname al cn)) (reverse apmn))

; (GetCanonicalMediaNamesOfConfigname ad "Acrobat PDFWriter")(defun GetCanonicalMediaNamesOfConfigname(ad cn / oldcn al cmn) (setq al (vla-get-ActiveLayout ad)) (setq oldcn (vla-get-configname al)) (vla-put-configname al cn) (vla-RefreshPlotDeviceInfo al) (setq cmn (GetCanonicalMediaNames ad)) (if (/= oldcn "None") (vla-put-configname al oldcn))

Page 41: Lsp

cmn)

; (GetLocalMediaNamesOfConfigname ad "Acrobat PDFWriter")(defun GetLocalMediaNamesOfConfigname(ad cn / oldcn al cmn) (setq al (vla-get-ActiveLayout ad)) (setq oldcn (vla-get-configname al)) (vla-put-configname al cn) (vla-RefreshPlotDeviceInfo al) (setq cmn (GetLocaleMediaNames ad)) (if (/= oldcn "None") (vla-put-configname al oldcn)) cmn)

;;; getvpscale.lsp;;;;;; Get Viewport Scale in active viewport or in selected;;; Supports viewports with clipping boundary;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-05-03 - First release;;; 2000-05-09 - Detects perspective view;;; Tested on AutoCAD 2000(defun c:getvpscale (/ ss ent)(defun printscale (/ data cvsize cvhgt) (setq cvscale (vla-get-customscale (vlax-ename->vla-object ent))) (princ "\nPS:MS == ") (cond ((> cvscale 1) (princ (rtos cvscale 2)) (princ ":1") ) (T (princ "1:") (princ (rtos (/ 1 cvscale) 2)) ) )) (vl-load-com) (if (= (getvar "tilemode") 0) (if (= (getvar "cvport") 1) (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil) (if (/= 1 (logand 1 (cdr (assoc 90 (entget (setq ent (ssname ss 0))))))) (printscale) (princ "\n Command not allowed in perspective view.") ) (princ " No viewport found.") ) (progn (setq ent (vlax-vla-object->ename (vla-get-activepviewport (vla-get-activedocument (vlax-get-acad-object))))) (if (/= 1 (logand 1 (cdr (assoc 90 (entget ent))))) (printscale) (princ "\n Command not allowed in perspective view.") ) ) ) (princ "\n Command not allowed unless TILEMODE is set to 0.") )

Page 42: Lsp

(setq ss nil) (princ))

;;; return viewport scale if allowed else nil(defun getvpscale1 (/ ss ent) (vl-load-com) (if (= (getvar "tilemode") 0) (if (= (getvar "cvport") 1) (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil) (if (/= 1 (logand 1 (cdr (assoc 90 (entget (setq ent (ssname ss 0))))))) (vla-get-customscale (vlax-ename->vla-object ent)) ) ) (progn (setq ent (vlax-vla-object->ename (vla-get-activepviewport (vla-get-activedocument (vlax-get-acad-object))))) (if (/= 1 (logand 1 (cdr (assoc 90 (entget ent))))) (vla-get-customscale (vlax-ename->vla-object ent)) ) ) ) ))

;;; return viewport scale if allowed else nil;;; no support for perspective view(defun getvpscale2 (/ ss vpno vpsc) (if (= (getvar "tilemode") 0) (if (= (getvar "cvport") 1) (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil) (progn (setq vpno (cdr (assoc 69 (entget (ssname ss 0))))) (command "_.mspace") (setvar "cvport" vpno) (setq vpsc (caddr (trans '(0 0 1) 2 3))) (command "_.pspace") vpsc ) ) (caddr (trans '(0 0 1) 2 3)) ) ))

;;; return viewport scale;;; no support for viewports with clipping boundary;;; no support for perspective view(defun getvpscale3(/ vpno vpsc) (setq vpno (cdr (assoc 69 (entget (car (entsel)))))) (command "mspace") (setvar "cvport" vpno) (setq vpsc (caddr (trans '(0 0 1) 2 3))) (command "pspace") vpsc)

;;; return scale in active viewport;|(caddr (trans '(0 0 1) 2 3))|;

Page 43: Lsp

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected] ; ; 1999-12-22 First release ; 2000-03-02 Simplified command entry and code ; ; This program moves the startpoint/snapbase for ; selected hatches base points independently. ; Or it can be used to set the base point same for all selected hatches. ; The program stops when pressing Enter/Rightclick at any point. ; ; Tested for AutoCAD 2000

(defun c:hm () (c:hatch_move))(defun c:hatch_move (/ ss1 fp tp loop ent oldsnapbase oldosmode oldsp newsp contin oldgrips oldcmdecho errexit restx restore ) (defun errexit (msg) (restore) ) ;_ end of defun (defun restx () (setvar "snapbase" oldsnapbase) (setvar "osmode" oldosmode) (setvar "grips" oldgrips) (command "_.UNDO" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) ) ;_ end of defun (setq olderr *error* restore restx *error* errexit ) ;_ end of setq (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (setq oldgrips (getvar "grips")) (setvar "grips" 0) (setq oldsnapbase (getvar "snapbase")) (setq oldosmode (getvar "osmode")) (setq ss1 (cadr (sssetfirst nil (cadr (ssgetfirst))))) ; get ssgetfirst before UNDO (command "_.UNDO" "_BE") (graphscr) (if (setq ss1 (if ss1 (if (setq ss1 (ssget "P" '((0 . "HATCH")))) ss1 ; hatches found in previous sel set (ssget '((0 . "HATCH"))) ; no hatches previously selected ) ;_ end of if (ssget '((0 . "HATCH"))) ; no previous sel set ) ;_ end of if ) ;_ end of setq (while (and (not (initget 228 "Set")) (if ss1 (sssetfirst nil ss1)

Page 44: Lsp

t ) ; show what is selected (setq fp (getpoint "\nBase point for displacement or set same base point for all [Set] <exit>: " ) ;_ end of getpoint ) ;_ end of setq (progn (if (= fp "Set") (progn (initget 98) (setq fp (getpoint "\nSet same base point for all <exit>: ") ) ;_ end of setq (setq contin nil) ) ;_ end of progn (progn (initget 98) (setq tp (getpoint fp "\nSecond point for displacement <exit>: " ) ;_ end of getpoint ) ;_ end of setq (setq contin t) ) ;_ end of progn ) ; end if fp ) ; end progn ) ; end and (setvar "osmode" 0) (setq loop 0) (while (setq ent (ssname ss1 loop)) (if contin (progn (setq oldsp (list (cdr (assoc 43 (entget ent))) (cdr (assoc 44 (entget ent))) ) ;_ end of list ) ;_ end of setq (setq newsp (list (- (+ (car oldsp) (car tp)) (car fp)) (- (+ (cadr oldsp) (cadr tp)) (cadr fp)) ) ;_ end of list ) ;_ end of setq ) ;_ end of progn (setq newsp (list (car fp) (cadr fp))) ) ; end if (setvar "snapbase" newsp) (setvar "osmode" oldosmode) (sssetfirst nil) (command ".hatchedit" ent "" "" "" "") (setq loop (1+ loop)) ) ; end while ) ; end while ) ; end if (setq ss1 nil) (restore)) ;_ end of defun

;;; HATCHB.LSP ver 2.5;;; Recreates hatch boundary by selecting a hatch;;; Known problem with some elipses and splines;;; By Jimmy Bergmark;;; Copyright (C) 1997-2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

Page 45: Lsp

;;; 2000-02-12 - First release;;; 2000-03-27 - Counterclockwise arc's and ellipse's fixed;;; Objects created joined to lwpolyline if possible;;; Error-handling, undo of command;;; Can handle PLINETYPE = 0,1,2;;; 2000-03-30 - Integrating hatchb and hatchb14;;; Selection of many hatches;;; Splines supported if closed.;;; 2001-04-02 - Fixed bug with entmake of line with no Z for r14;;; 2001-07-31 - Removed an irritating semicolon to enable polylines to be created.;;; 2001-10-04 - Changed mail and homepage so it's easy to find when new versions comes up.;;; 2003-02-06 - Minor fix;;; 2003-02-17 - Area returned if no islands is found since it's not consistant;;; 2003-05-19 - Fix to take PEDITACCEPT variable used in AutoCAD 2004 into account;;; 2004-11-05 - Minor bugs fixed;;; 2006-03-18 - Nothing changed from 2.1 other that it's been confirmed to work with AutoCAD 2007;;; 2006-05-13 - Create the boundary on the same layer as the hatch using the hbl command and;;; on current layer/color/linetype using the hb or hatchb command;;; 2007-02-08 - Fixed a bug with the hbl command;;; 2008-02-29 - Support for hatches in non WCS thanks to xiaocai;;; Tested on AutoCAD r14, 2000, 2000i, 2002, 2004, 2005, 2006, 2007, 2008, 2009;;; should be working on older versions too.

(defun c:hb () (hatchb nil)) ; this line can be commented out if there is an existing command called hb(defun c:hbl () (hatchb T)) ; this line can be commented out if there is an existing command called hbl(defun c:hatchb () (hatchb nil))(defun hatchb (hl / es blay ed1 ed2 loops1 bptf part et noe plist ic bul nr ang1 ang2 obj *ModelSpace* *PaperSpace* space cw errexit undox olderr oldcmdecho ss1 lastent en1 en2 ss lwp list->variantArray 3dPoint->2dPoint A2k ent i ss2 knot-list controlpoint-list kn cn pos xv bot area hst noarea ) (setq A2k (>= (substr (getvar "ACADVER") 1 2) "15")) (if A2k (progn (defun list->variantArray (ptsList / arraySpace sArray) (setq arraySpace

(vlax-make-safearrayvlax-vbdouble(cons 0 (- (length ptsList) 1))

) ) (setq sArray (vlax-safearray-fill arraySpace ptsList)) (vlax-make-variant sArray) ) (defun areaOfObject (en / curve area) (if en

(if A2k (progn (setq curve (vlax-ename->vla-object en)) (if (vl-catch-all-error-p

(setq area (vl-catch-all-apply 'vlax-curve-getArea (list curve)) )

)nilarea

) ) (progn (command "._area" "_O" en)

Page 46: Lsp

(getvar "area") ) )

) ) ) ) (if A2k (defun 3dPoint->2dPoint (3dpt) (list (float (car 3dpt)) (float (cadr 3dpt))) ) )

(defun errexit (s) (princ "\nError: ") (princ s) (restore) )

(defun undox () (command "._ucs" "_p") (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (if A2k (progn (vl-load-com) (setq *ModelSpace* (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)) ) *PaperSpace* (vla-get-PaperSpace (vla-get-ActiveDocument (vlax-get-acad-object)) ) )) )

; Remove for testing purpose; (setq A2k nil) (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil) (progn (setq i 0) (setq area 0) (setq bMoreLoops nil) (while (setq ent (ssname ss2 i)) (setq noarea nil) (setq ed1 (entget ent)) (setq layer (cdr (assoc 8 ed1))) ; (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0))) (princ "\nHatch not in WCS!")) ;modified by xiaocai ; (setq xv (cdr (assoc 210 ed1))) ;modified by xiaocai (command "._ucs" "_w") (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops) (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL"))

Page 47: Lsp

(setq space *ModelSpace*) (setq space *PaperSpace*) ) (repeat loops1 (setq ed1 (member (assoc 92 ed1) ed1)) (setq bptf (cdr (car ed1))) ; boundary path type flag (setq ic (cdr (assoc 73 ed1))) ; is closed (setq noe (cdr (assoc 93 ed1))) ; number of edges

(setq bot (cdr (assoc 92 ed1))) ; boundary type(setq hst (cdr (assoc 75 ed1))) ; hatch style

(setq ed1 (member (assoc 72 ed1) ed1)) (setq bul (cdr (car ed1))) ; bulge (setq plist nil) (setq blist nil) (cond ((> (boole 1 bptf 2) 0) ; polyline (repeat noe (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) (setq plist (append plist (list (trans (cdr (assoc 10 ed1)) ent 0) ))) ;;add trans by xiaocai (setq blist (append blist (if (> bul 0) (list (cdr (assoc 42 ed1))) nil ) ) ) ) (if A2k (progn (setq polypoints (apply 'append (mapcar '3dPoint->2dPoint plist) ) ) (setq VLADataPts (list->variantArray polypoints)) (setq obj (vla-addLightweightPolyline space VLADataPts)) (setq nr 0) (repeat (length blist) (if (/= (nth nr blist) 0) (vla-setBulge obj nr (nth nr blist)) ) (setq nr (1+ nr)) ) (if (= ic 1) (vla-put-closed obj T) )

(if hl (vla-put-layer obj layer)) ) (progn

(setq ne (append (list '(0 . "POLYLINE")) (list (cons 66 1)))) (if (= ic 1) (setq ne (append ne (list (cons 70 1))))) (if hl (setq ne (append ne (list (cons 8 layer)))))

(entmake ne) (setq nr 0) (repeat (length plist) (if (= bul 0) (entmake (list (cons 0 "VERTEX") (cons 10 (trans (nth nr plist) ent 0) );;add trans by xiaocai ) ) (entmake (list (cons 0 "VERTEX") (cons 10 (trans (nth nr plist) ent 0) );;add trans by xiaocai (cons 42 (nth nr blist)) )

Page 48: Lsp

) ) (setq nr (1+ nr)) ) (entmake '((0 . "SEQEND"))) ) ) ) (t ; not polyline (setq lastent (entlast)) (setq lwp T) (repeat noe (setq et (cdr (assoc 72 ed1))) (cond ((= et 1) ; line (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) (if A2k

(progn (setq obj (vla-AddLine space (vlax-3d-point (trans (cdr (assoc 10 ed1)) ent 0) ) ;;add trans by xiaocai (vlax-3d-point (trans (cdr (assoc 11 ed1)) ent 0) ) ;;add trans by xiaocai ))

(if hl (vla-put-layer obj layer)) ) (progn (setq ne (append (list (cons 0 "LINE"))

(list (list 10 (car (trans (cdr (assoc 10 ed1)) ent 0) ) (cadr (trans (cdr (assoc 10 ed1)) ent 0)) 0)) ;;add trans by xiaocai (list (list 11 (car (trans (cdr (assoc 11 ed1)) ent 0) ) (cadr (trans (cdr (assoc 11 ed1)) ent 0)) 0)) ;;add trans by xiaocai

;(cons 210 xv) ) )

(if hl (setq ne (append ne (list (cons 8 layer))))) (entmake ne)

) ) (setq ed1 (cddr ed1)) ) ((= et 2) ; circular arc (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) (setq ang1 (cdr (assoc 50 ed1))) (setq ang2 (cdr (assoc 51 ed1))) (setq cw (cdr (assoc 73 ed1))) (if (and (equal ang1 0 0.00001) (equal ang2 6.28319 0.00001)) (progn (if A2k

(progn (setq obj (vla-AddCircle space (vlax-3d-point (trans (cdr (assoc 10 ed1)) ent 0) ) (cdr (assoc 40 ed1)) ))

(if hl (vla-put-layer obj layer)) ) (progn

(setq ne (append (list (cons 0 "CIRCLE")) (list (cons 8 layer))

(list (cons 10 (trans (cdr (assoc 10 ed1)) ent 0)));;;add trans by xiaocai (list (assoc 40 ed1)) ) )

(if hl (setq ne (append ne (list (cons 8 layer)))))

Page 49: Lsp

(entmake ne) )

) (setq lwp nil) ) (if A2k

(progn (setq obj (vla-AddArc space (vlax-3d-point (trans (cdr (assoc 10 ed1)) ent 0) );;;add trans by xiaocai (cdr (assoc 40 ed1)) (if (= cw 0) (- 0 ang2) ang1 ) (if (= cw 0) (- 0 ang1) ang2 )

)) (if hl (vla-put-layer obj layer))

) (progn (setq ne (append (list (cons 0 "ARC"))

(list (cons 10 (trans (cdr (assoc 10 ed1)) ent 0) ));;add trans by xiaocai (list (assoc 40 ed1)) (list (cons 50 (if (= cw 0) (- 0 ang2) ang1 ) )) (list (cons 51 (if (= cw 0) (- 0 ang1) ang2 ) )) )

) (if hl (setq ne (append ne (list (cons 8 layer)))))

(entmake ne) )

) ) (setq ed1 (cddddr ed1)) ) ((= et 3) ; elliptic arc (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) (setq ang1 (cdr (assoc 50 ed1))) (setq ang2 (cdr (assoc 51 ed1))) (setq cw (cdr (assoc 73 ed1))) (if A2k (progn (setq obj (vla-AddEllipse space (vlax-3d-point (trans (cdr (assoc 10 ed1)) ent 0) ) (vlax-3d-point (trans (cdr (assoc 11 ed1)) ent 0) );;add trans by xiaocai (cdr (assoc 40 ed1)) ) ) (vla-put-startangle obj (if (= cw 0) (- 0 ang2) ang1)) (vla-put-endangle obj (if (= cw 0) (- 0 ang1) ang2))

(if hl (vla-put-layer obj layer))

Page 50: Lsp

) (progn

(princ "\nElliptic arc not supported!") (setq noarea T) )

) (setq lwp nil) ) ((= et 4) ; spline (setq ed1 (member (assoc 94 (cdr ed1)) ed1)) (setq knot-list nil) (setq controlpoint-list nil)

(setq kn (cdr (assoc 95 ed1))) (setq cn (cdr (assoc 96 ed1))) (setq pos (vl-position (assoc 40 ed1) ed1)) (repeat kn (setq knot-list (cons (cons 40 (cdr (nth pos ed1))) knot-list)) (setq pos (1+ pos)) ) (setq pos (vl-position (assoc 10 ed1) ed1)) (repeat cn (setq controlpoint-list (cons (cons 10 (trans (cdr (nth pos ed1)) ent 0) ) controlpoint-list));;add trans by xiaocai (setq pos (1+ pos)) ) (setq knot-list (reverse knot-list)) (setq controlpoint-list (reverse controlpoint-list))

(setq ne (append (list '(0 . "SPLINE"))

(list (cons 100 "AcDbEntity")) (list (cons 100 "AcDbSpline")) (list (cons 70 (+ 1 8 (* 2 (cdr (assoc 74 ed1))) (* 4 (cdr (assoc 73 ed1)))))) (list (cons 71 (cdr (assoc 94 ed1)))) (list (cons 72 kn)) (list (cons 73 cn)) knot-list controlpoint-list )

)(if hl (setq ne (append ne (cons 8 layer))))

(entmake ne)(setq ed1 (member (assoc 10 ed1) ed1))

(setq lwp nil) ) ) ; end cond ) ; end repeat noe (if lwp (progn (setq en1 (entnext lastent)) (setq ss (ssadd)) (ssadd en1 ss) (while (setq en2 (entnext en1)) (ssadd en2 ss) (setq en1 en2) )

(if (= (getvar "peditaccept") 1) (command "_.pedit" (entlast) "_J" ss "" "")

(command "_.pedit" (entlast) "_Y" "_J" ss "" "") )

))

) ; end t ) ; end cond; Tries to get the area on islands but it's not clear how to know if an island is filled or not; and if it should be substracted or added to the total area.

Page 51: Lsp

; (if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast))))); (if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast))))); (princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n"); (princ (areaOfObject (entlast))) ) ; end repeat loops1 (if (and (= noarea nil) (= loops1 1)) (setq area (+ area (areaOfObject (entlast)))) (setq bMoreLoops T)) (setq i (1+ i)) ) ) ) (setq ss2 nil) (if (and area (not bMoreLoops)) (progn (princ "\nTotal Area = ") (princ area) )) (restore) (princ));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; Change the hatch base point on one or many hatches;;;(defun c:hatchbase (/ oldos oldsn oldcmdecho i ent ss) (setq oldos (getvar "osmode")) (setq oldsn (getvar "snapbase")) (setq oldcmdecho (getvar "cmdecho")) (setvar "osmode" 47) (princ "\nSelect point you wish Hatch(s) to start from...") (command "._snapbase" pause) (princ "\nSelect Hatch(s) to adjust snapbase") (if (not (setq ss (ssget))) (alert "\n No Entities selected..... Please try again.") (progn (setq i 0) (while (setq ent (ssname ss i))

(command "._hatchedit" ent "" "" "" "") (setq i (1+ i))

) ) ) (setq ss nil) (setvar "snapbase" oldsn) (setvar "osmode" oldos) (setvar "cmdecho" oldcmdecho) (princ))

;;; HISTORYLINES.LSP;;; Change the number of command history lines.;;; Saves into profile.;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 1999-09-25 - First release;;; To be run on AutoCAD 2000

(defun c:PutHistoryLines (/ hl) (vl-load-com)

Page 52: Lsp

(if (setq hl (getint (strcat "\nNumber of History Lines <" (itoa (vla-get-HistoryLines (vla-get-display (vla-get-preferences (vlax-get-acad-object))))) ">: "))) (if (or (< hl 25) (> hl 2048)) (prompt "\nOnly between 25 and 2048.") (vla-put-HistoryLines (vla-get-display (vla-get-preferences (vlax-get-acad-object))) hl) ) ) (princ))

;;; another way to do it by someone else(defun c:cmdhistlines ( / chl) (if (setq chl (getint (strcat "\nNew value for CMDHISTLINES <" (getenv"CmdHistLines") ">: "))) (if (or (< chl 25) (> chl 2048)) (progn (prompt "\nRequires and integer between 25 and 2048.") (c:cmdhistlines) ) (setenv "CmdHistLines" (itoa chl)) ) ) (princ))

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; Tested on AutoCAD 2000;;;;;; 2 versions of Insert block with attribute with ActiveX;;; attributes are rotated to specified angle(vl-load-com)(defun c:ax-insrot (/ doc blk_name ins x y z rt rot blk atts ent ent2 promptStr i default txt ) (defun list->variantArray (ptsList / arraySpace sArray) (setq arraySpace (vlax-make-safearray vlax-vbdouble (cons 0 (- (length ptsList) 1)) ) ) (setq sArray (vlax-safearray-fill arraySpace ptsList)) (vlax-make-variant sArray) ) (initget 1) (setq blk_name (getstring T "\nEnter block name: ")) (initget 1) (setq ins (list->variantArray (getpoint "\nSpecify insertion point: ") ) x (getdist "\nEnter X scale factor <1>: ")

Page 53: Lsp

y (getdist "\nEnter Y scale factor <use X scale factor>: ") z (getdist "\nEnter Z scale factor <use Y scale factor>: ") rt (getangle "\nSpecify rotation angle <0.0>: ") rot (getangle "\nSpecify rotation angle for attributes <0.0>: ") ) (if (= x nil) (setq x 1) ) (if (= y nil) (setq y x) ) (if (= z nil) (setq z y) ) (if (= rt nil) (setq rt 0) ) (if (= rot nil) (setq rot 0) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq blk (vla-insertblock (vla-get-paperspace doc) ins blk_name x y z rt ) )

(if (and (= (vla-get-hasattributes blk) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk) ) ) ) ) (progn (vlax-for ent (vla-get-blocks doc) (if (= (vla-get-name ent) (vla-get-name blk)) (vlax-for ent2 ent (if (= (vla-get-objectname ent2) "AcDbAttributeDefinition") (setq promptStr (cons (list (vla-get-PromptString ent2) (vla-get-TextString ent2) (vla-get-TagString ent2) ) promptStr ) ) ) ) ) ) (setq i (1- (length promptStr))) (princ "\nEnter attribute values\n") (foreach tag (vlax-safearray->list atts)

Page 54: Lsp

(vla-put-TextString tag (if (= (setq txt (getstring T (strcat (if (= (setq default (car (nth i promptStr))) "") (setq default (caddr (nth i promptStr))) default ) " <" (setq default (cadr (nth i promptStr))) ">: " ) ) ) "" ) default txt ) ) (vla-put-Rotation tag rot) (setq i (1- i)) ) ) ) (princ))

(defun c:insrot (/ cmdecho attdia insblk ent rt tag atts blk) (setq cmdecho (getvar "CMDECHO")) (setq attdia (getvar "ATTDIA")) (setvar "ATTDIA" 1) (setvar "CMDECHO" 1) (initdia) (command "_.-INSERT" "~") (while (eq 1 (logand 1 (getvar "CMDACTIVE"))) (command pause) ) (setq insblk (entlast)) (setq ent (cdar (entget insblk))) (setq blk (vlax-ename->vla-object ent)) (if (and (= (vla-get-hasattributes blk) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk) ) ) ) ) (progn (setq rt (getangle "\nSpecify rotation angle for attributes <0.0>: ") ) (if (= rt nil) (setq rt 0) ) (foreach tag (vlax-safearray->list atts) (vla-put-Rotation tag rt) ) )

Page 55: Lsp

) (setvar "ATTDIA" attdia) (setvar "CMDECHO" cmdecho) (princ))

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2007 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; Tested on AutoCAD 2005 and ADT 2005 up to AutoCAD 2008;;;;;; Q: How can I change the title bar to say AutoCAD instead of Architectural Desktop?;;; A: Download JTB_TitleBar 2005.dvb and you can call it like the example below.;;; Change the path as where JTB_TitleBar.dvb is placed.;;; To make it fun you might even make it AutoCAD 2003 or whatever you want.

(defun c:JTB_SetTitleBarAutoCAD2005() (vl-load-com) (setq JTB_TitleBar "AutoCAD 2005") (vl-vbarun "C:/Program Files/jtbworld/JTB_TitleBar2005.dvb!JTB_TitleBar") (princ))

(defun c:JTB_SetTitleBarRevitADT2005() (vl-load-com) (setq JTB_TitleBar "Revit-ADT 2005") (vl-vbarun "C:/Program Files/jtbworld/JTB_TitleBar2005.dvb!JTB_TitleBar") (princ));;; Layer and lineweight list to drawing;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-06-27;;;(vl-load-com)(defun ax:layer-lw-list (/ layer lw lst) (vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ) (setq lw (vla-get-lineweight layer)) (if (= lw -3) (setq lw 0.25 lwt "Default") (setq lw (/ lw 100.0) lwt (strcat (rtos lw 2 2) " mm")) ) (setq lst (cons (list (vla-get-name layer) lw lwt ) lst)) ) (vl-sort lst (function (lambda (e1 e2) (< (strcase (car e1)) (strcase (car e2))) )

Page 56: Lsp

) ) )

(defun c:layer-lw-list (/ p row y ts xd plinewidold) (setq p (getpoint "Specify top left point of list: ")) (setq ts (getvar "textsize")) (setq y (cadr p)) (setq xd (* ts 15)) ; dist between columns (setq plinewidold (getvar "PLINEWID")) (if p (foreach row (ax:layer-lw-list) (command "text" p "" "" (car row)) (setvar "PLINEWID" (* (/ ts 2.11) (cadr row))) (command "pline" (list (+ (car p) (* 0.9 xd)) (+ (cadr p) (/ ts 2.0)) (caddr p)) (list (+ (car p) (* 0.98 xd)) (+ (cadr p) (/ ts 2.0)) (caddr p)) "" ) (command "text" (list (+ (car p) xd) (cadr p) (caddr p)) "" "" (caddr row)) (setq y (- y (* ts 1.66667))) (setq p (list (car p) y (caddr p))) ) ) (setvar "PLINEWID" plinewidold) (princ))

;;;---------------------------------------------------------------------------;;;;;;; layers-erase.lsp;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2000-05-25 - First release;;; Tested on AutoCAD 2000;;;;;;---------------------------------------------------------------------------;;;; DESCRIPTION;;;;;; c:layers-erase - Erase all layers that are frozen or off;;;---------------------------------------------------------------------------;(vl-load-com)(defun c:layers-erase () (defun layer-del (layer / ss e d c f doc la) (if (setq e (tblobjname "layer" layer)) (progn (setq d (entget e) c (cdr (assoc 62 d)) f (cdr (assoc 70 d)) del nil ) (if (minusp c) ; layer is off, force abs of color (progn (setq del T) (setq d (subst (cons 62 (abs c)) (assoc 62 d) d)) )

Page 57: Lsp

) (if (eq 1 (logand 1 f)) ; layer is frozen, mask off 1 (progn (setq del T) (setq f (boole 6 f 1)) ) ) (if (eq 4 (logand 4 f)) ; layer is locked, mask off 4 (setq f (boole 6 f 4)) ) ; did we change the flag value? (if (not (eq f (cdr (assoc 70 d)))) (setq d (subst (cons 70 f) (assoc 70 d) d)) ) ; did we change the dxf data at all? (if (not (equal d (entget e))) (entmod d) ) (if del (progn (setq ss (ssget "X" (list (cons 8 layer))) doc (vla-get-activedocument (vlax-get-acad-object)) c -1 ) (vla-put-activeLayer doc (vla-item (vla-get-layers doc) "0") ) (if ss (repeat (sslength ss) (vla-erase (vlax-ename->vla-object (ssname ss (setq c (1+ c)))) ) ) );;; purge the layer (vl-catch-all-apply 'vla-delete (list (vla-item (vla-get-layers doc) layer)) );;; if not purged freeze it again (if (setq e (tblobjname "layer" layer)) (command "._layer" "_f" layer "") ) ) ) ) ) ) (setq ss nil) (vlax-for la (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) (layer-del (vla-get-name la)) )) ;;; List layers according to state;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-05-15

Page 58: Lsp

;;;;;; Argument: state;;; 1 frozen;;; 2 thawed;;; 3 on;;; 4 off;;; 5 lock;;; 6 not locked;;; 7 plottable;;; 8 not plottable;;; Example: (layer-state 1);;; Return values: list of layers(vl-load-com)(defun layer-state (state / typ names tf skip) (setq names nil) (vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ) (setq skip nil) (cond ((= 1 state) (setq typ (vla-get-freeze layer) tf :vlax-true)) ((= 2 state) (setq typ (vla-get-freeze layer) tf :vlax-false)) ((= 3 state) (setq typ (vla-get-layeron layer) tf :vlax-true)) ((= 4 state) (setq typ (vla-get-layeron layer) tf :vlax-false)) ((= 5 state) (setq typ (vla-get-lock layer) tf :vlax-true)) ((= 6 state) (setq typ (vla-get-lock layer) tf :vlax-false)) ((= 7 state) (setq typ (vla-get-plottable layer) tf :vlax-true)) ((= 8 state) (setq typ (vla-get-plottable layer) tf :vlax-false)) (t (setq skip T)) ) (if (and (null skip) (eq typ tf)) (setq names (cons (vla-get-name layer) names)) ) ) (reverse names))

;;; toggle the freeze state of layer;;; and regens only the objects on the layer;;; but if layer is xref dependant it regens;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-03-05 - First release;;;;;; Tested on AutoCAD 2000;;; Argument: layer {list of layers};;; Example: (layer-toggle-freeze '("Layer1" "Layer2"))

(defun layer-toggle-freeze (layer / en f ss ent i fg) (foreach la layer (setq en (entget (tblobjname "layer" la))) (setq f (cdr (assoc 70 en))) (setq f (boole 6 f 1)) (if (and (wcmatch la "*|*") (eq 0 (logand 1 f))) (setq rg T)) (setq en (subst (cons 70 f) (assoc 70 en) en)) (entmod en)

Page 59: Lsp

(setq ss (ssget "X" (list (cons 8 la)))) (setq i 0) (if ss (while (setq ent (ssname ss i)) (entupd ent) (setq i (1+ i)) ) ) ) (setq sset nil) (if rg (command "._regenall")) (princ)) ;;;;;; LayoutsToDwgs.lsp;;; Created 2000-03-27

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2012 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2003-12-12 Sets UCS to world in model space;;; to avoid problem with wblock;;; 2011-06-06 Excludes empty layouts;;; 2012-06-01 Handle Map prompt with WBLOCK;;; Include AutoCAD Map information in the export? [Yes/No] <Y>:;;; 2013-03-04 Added _ on some commands to internationalize it;;;;;; For AutoCAD 2000, 2000i, 2002, 2004, 2005, ;;; 2006, 2007, 2008, 2009, 2011, 2012, 2013 and newer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Creates separate drawings of all layouts.;;; The new drawings are saved to the current drawings path;;; and overwrites existing drawings.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun c:LayoutsToDwgs (/ errexit undox olderr oldcmdecho fn path msg msg2 fileprefix i j)

(defun errexit (s) (princ "\nError: ") (princ s) (restore) )

(defun undox () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr) (princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (defun DelAllLayouts (Keeper / TabName) (vlax-for Layout (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)) )

Page 60: Lsp

(if (and (/= (setq TabName (strcase (vla-get-name layout))) "MODEL") (/= TabName (strcase Keeper)) ) (vla-delete layout) ) ) )

(vl-load-com) (setq msg "" msg2 "" i 0 j 0) (command "._undo" "_BE") (setq fileprefix (getstring "Enter filename prefix: ")) (foreach lay (layoutlist) (if (and (/= lay "Model") (> (vla-get-count (vla-get-block (vla-Item (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) lay))) 1)) (progn (command "_.undo" "_M") (DelAllLayouts lay) (setvar "tilemode" 1) (command "_.ucs" "_w") (setvar "tilemode" 0) (setq path (getvar "DWGPREFIX")) (setq fn (strcat path fileprefix lay ".dwg")) (if (findfile fn) (progn (command "_.-wblock" fn "_Y") (if (equal 1 (logand 1 (getvar "cmdactive"))) (progn (setq i (1+ i) msg (strcat msg "\n" fn)) (command "*") ) (setq j (1+ j) msg2 (strcat msg2 "\n" fn)) ) ) (progn (command "_.-wblock" fn "*") (setq i (1+ i) msg (strcat msg "\n" fn)) ) ) (if (equal 1 (logand 1 (getvar "cmdactive"))) (command "_N") ) (command "_.undo" "_B") ) ) ) (if (/= msg "") (progn (if (= i 1) (prompt "\nFollowing drawing was created:") (prompt "\nFollowing drawings were created:") ) (prompt msg) ) ) (if (/= msg2 "") (progn (if (= j 1) (prompt "\nFollowing drawing was NOT created:") (prompt "\nFollowing drawings were NOT created:") ) (prompt msg2)

Page 61: Lsp

) ) (command "._undo" "_E") (textscr) (restore) (princ))(princ);;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected](vl-load-com);;; (loadLinetype (vla-get-activedocument (vlax-get-acad-object)) "Divide" "acadiso.lin");;; returns: T if loaded else nil(defun loadLinetype (doc LineTypeName FileName) (if (and (not (existLinetype doc LineTypeName)) (vl-catch-all-error-p (vl-catch-all-apply 'vla-load (list (vla-get-Linetypes doc) LineTypeName FileName ) ) ) ) nil T ))

;;; (existLinetype (vla-get-activedocument (vlax-get-acad-object)) "Divide")(defun existLinetype (doc LineTypeName / item loaded) (vlax-for item (vla-get-linetypes doc) (if (= (strcase (vla-get-name item)) (strcase LineTypeName)) (setq loaded T) ) ))

;;; (purgeAllLinetypes (vla-get-activedocument (vlax-get-acad-object)))(defun purgeAllLinetypes (doc / item) (vlax-for item (vla-get-linetypes doc) (vl-catch-all-apply 'vla-delete (list item)) ))

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

;;; Midpoint of 2 points(defun c:mpt (/ pt1 pt2) (if (and (= (getvar "cmdactive") 1) (setq pt1 (getpoint "\nFirst point: ")) (setq pt2 (getpoint pt1 "\nSecond point: ")) )

Page 62: Lsp

(command "_non" (list (/ (+ (car pt1) (car pt2)) 2) (/ (+ (cadr pt1) (cadr pt2)) 2) (/ (+ (caddr pt1) (caddr pt2)) 2) ) ) ) (princ))

;;; 1/3:rd point of 2 points(defun c:3pt (/ pt1 pt2) (if (and (= (getvar "cmdactive") 1) (setq pt1 (getpoint "\nFirst point: ")) (setq pt2 (getpoint pt1 "\nSecond point: ")) ) (command "_non" (list (+ (/ (- (car pt2) (car pt1)) 3) (car pt1)) (+ (/ (- (cadr pt2) (cadr pt1)) 3) (cadr pt1)) (+ (/ (- (caddr pt2) (caddr pt1)) 3) (caddr pt1)) ) ) ) (princ))

;;; 1/4:th point of 2 points(defun c:4pt (/ pt1 pt2) (if (and (= (getvar "cmdactive") 1) (setq pt1 (getpoint "\nFirst point: ")) (setq pt2 (getpoint pt1 "\nSecond point: ")) ) (command "_non" (list (+ (/ (- (car pt2) (car pt1)) 4) (car pt1)) (+ (/ (- (cadr pt2) (cadr pt1)) 4) (cadr pt1)) (+ (/ (- (caddr pt2) (caddr pt1)) 4) (caddr pt1)) ) ) ) (princ))

;;; Midpoint of 3 points(defun c:mpt3 (/ pt1 pt2 pt3) (if (and (= (getvar "cmdactive") 1) (setq pt1 (getpoint "\nFirst point: ")) (setq pt2 (getpoint pt1 "\nSecond point: ")) (setq pt3 (getpoint pt2 "\nThird point: ")) ) (command "_non" (list (/ (+ (car pt1) (car pt2) (car pt3)) 3) (/ (+ (cadr pt1) (cadr pt2) (cadr pt3)) 3)

Page 63: Lsp

(/ (+ (caddr pt1) (caddr pt2) (caddr pt3)) 3) ) ) ) (princ))

;;; PageSetup.LSP;;; Miscellaneous routines related to Page Setup;;; By Jimmy Bergmark;;; Copyright (C) 1997-2011 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-04-05 - First release;;; 2011-02-10 - Second release;;; Tested on AutoCAD 2000 and AutoCAD 2011(vl-load-com);;; (listPageSetups <AcadDocument>);;; (listPageSetups (vla-get-activedocument (vlax-get-acad-object)))(defun listPageSetups (doc / pc) (vlax-for pc (vla-get-plotconfigurations doc) (princ (strcat (vla-get-name pc) "\n")) ) (princ))

;;; (allPageSetups <AcadDocument>);;; (allPageSetups (vla-get-activedocument (vlax-get-acad-object)))(defun allPageSetups (doc / aps pc) (vlax-for pc (vla-get-plotconfigurations doc) (setq aps (cons (vla-get-name pc) aps)) ) (reverse aps))

;;; (allPageSetupsAndModelType <AcadDocument>);;; (allPageSetupsAndModelType (vla-get-activedocument (vlax-get-acad-object)))(defun allPageSetupsAndModelType (doc / aps pc) (vlax-for pc (vla-get-plotconfigurations doc) (setq aps (cons (cons (vla-get-name pc)

(if (= (vla-get-ModelType pc) :vlax-true) "Model" "Layout" )

) aps

) ) ) (reverse aps))

;;; (allPageSetupsOfModelType <AcadDocument>);;; (allPageSetupsOfModelType (vla-get-activedocument (vlax-get-acad-object)))(defun allPageSetupsOfModelType (doc / aps) (vlax-for pc (vla-get-plotconfigurations doc) (if (= (vla-get-ModelType pc) :vlax-true) (setq aps (cons (vla-get-name pc) aps)) ) ) (vl-sort aps '<)

Page 64: Lsp

)

;;; (allPageSetupsOfLayoutType <AcadDocument>);;; (allPageSetupsOfLayoutType (vla-get-activedocument (vlax-get-acad-object)))(defun allPageSetupsOfLayoutType (doc / aps) (vlax-for pc (vla-get-plotconfigurations doc) (if (= (vla-get-ModelType pc) :vlax-false) (setq aps (cons (vla-get-name pc) aps)) ) ) (vl-sort aps '<))

;;; (deleteAllPageSetups <AcadDocument>);;; (deleteAllPageSetups (vla-get-activedocument (vlax-get-acad-object)))(defun deleteAllPageSetups (doc) (vlax-for pc (vla-get-plotconfigurations doc) (vla-delete pc) ))

;;; (deletePageSetup <AcadDocument> <PageSetupName>);;; (deletePageSetup (vla-get-activedocument (vlax-get-acad-object)) "PageSetupName")(defun deletePageSetup (doc name) (vlax-for pc (vla-get-plotconfigurations doc) (if (= (strcase (vla-get-name pc)) (strcase name)) (vla-delete pc) ) ))

;;; add a new page setup name to current layout-type based on current plot configuration;;; (addPageSetup <AcadDocument> <PageSetupName>);;; (addPageSetup (vla-get-activedocument (vlax-get-acad-object)) "PageSetupName")(defun addPageSetup (doc name / space pc lay) (deletePageSetup doc name) (if (= (getvar "ctab") "Model") (setq space :vlax-true lay (vla-get-Layout (vla-get-ModelSpace (vla-get-activedocument (vlax-get-acad-object))))) (setq space :vlax-false lay (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)))) ) (setq pc (vla-add (vla-get-plotconfigurations doc) name space)) (vla-CopyFrom pc lay) (vla-put-name pc name))

;;; (getPageSetupName "Model");;; (getPageSetupName "Layout1");;; (getPageSetupName (getvar "ctab"));;; return value: PageSetupName or nil if Page Setup Name doesn't exist(defun getPageSetupName (layout / laydict psn) (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))) (setq laydict (dictsearch dn layout)) (setq psn (member '(100 . "AcDbPlotSettings") laydict)) (if (= (caadr psn) 1) ; Page Setup Name exist (setq psn (cdadr psn)) )

Page 65: Lsp

)

;;; (getAllPageSetupName <AcadDocument>);;; (getAllPageSetupName (vla-get-activedocument (vlax-get-acad-object)));;; Example return: (("Model" . "PageSetupName") ("Layout1" . "PPA") ("Layout2"));;; Layout2 has no page setup name(defun getAllPageSetupName (doc / layoutitem lst) (foreach layoutitem (layout-tab-list doc) (setq lst (cons (cons layoutitem (getPageSetupName layoutitem)) lst)) ) (reverse lst))

;; (layout-tab-list <AcadDocument> );;;; Returns a list of tne names of all;; layouts in the specified document,;; in ascending tab-order.;; TonyT;; (layout-tab-list (vla-get-activedocument (vlax-get-acad-object)))(defun layout-tab-list (doc / layouts) (mapcar 'vla-get-name (vl-sort (vlax-for layout (vla-get-layouts doc) (setq layouts (cons layout layouts)) ) '(lambda (a b) (< (vla-get-taborder a) (vla-get-taborder b) ) ) ) ))

;;; Set a named page setup as current;;; (setPageSetupName <AcadDocument> <Layout> <PageSetupName>);;; (setPageSetupName (vla-get-activedocument (vlax-get-acad-object)) "Model" "PageSetupName")(defun setPageSetupName (doc layout newpsn / pc layoutitem exist1 exist2) (vlax-for layoutitem (vla-get-Layouts doc) (if (= (strcase (vla-get-name layoutitem)) (strcase layout)) (setq exist1 T) ) ) (if exist1 ; layout exist (vlax-for pc (vla-get-plotconfigurations doc) (if (and

(= (strcase (vla-get-name pc)) (strcase newpsn)) (if (= (strcase layout) "MODEL") (= (vla-get-ModelType pc) :vlax-true) (= (vla-get-ModelType pc) :vlax-false) ) )(setq exist2 T)

) ) ) (if exist2 ; page setup name exist for selected model type (command "._plot" "_n" layout newpsn "" "" "_y" "_n") ))

;;; Set a named page setup as current on current layout by avoiding command usage

Page 66: Lsp

;;; (SetCurrentPageSetup <AcadDocument> <PageSetupName>);;; (SetCurrentPageSetup (vla-get-activedocument (vlax-get-acad-object)) "Setup2")(defun SetCurrentPageSetup (doc pcname / layout PlotConfig) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq layout (vla-get-activelayout doc)) (setq PlotConfig (vl-catch-all-apply

'vla-item (list (vla-get-PlotConfigurations

doc ) pcname ) )

) (if (not (vl-catch-all-error-p PlotConfig)) (vla-copyfrom layout PlotConfig) ))

;;; PersonalMtextSymbols.LSP ver 1.1;;; Add personal mtext symbols in the right click menu in the mtext editor;;; By Jimmy Bergmark;;; Copyright (C) 1997-2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; Tested on AutoCAD 2002, 2004, 2005, 2008, 2009. Not sure about 2006. 2007 does not support this.;;;;;; Remember that you can change the contents to whatever you would like;;; The syntax is:;;; (vl-registry-write key "Name <1,2,3...n>" "<Description>");;; (vl-registry-write key "Contents <1,2,3...n>" "<Value>")

(defun PersonalMtextSymbols () (vl-load-com) (setq key (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT\\Symbols")) (vl-registry-write key "Name 1" "Name") (vl-registry-write key "Name 2" "Company") (vl-registry-write key "Contents 1" "Jimmy Bergmark") (vl-registry-write key "Contents 2" "JTB World"))

(defun c:PM () (PersonalMtextSymbols) (princ));;; PLJOINFUZZ.LSP;;; Joins lines, arcs and polylines using a fuzz distance;;; If only one object is selected it tries to join to all objects that are possible;;; By Jimmy Bergmark;;; Copyright (C) 2003-2004 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; Tested on AutoCAD 2002,2004 and 2005;;; Latest revision made 2004-11-11;;; Minor code cosmetic change made 2004-11-13;;; Bug corrected 2004-12-23

(defun c:jf () (c:pljoinfuzz)) ; this line can be commented out if there is an existing command called jf(defun c:pljoinfuzz (/ ss1 entLine objType oldcmdecho oldpeditaccept fuzz okObjects) (setq oldcmdecho (getvar "cmdecho")) (setq oldpeditaccept (getvar "PEDITACCEPT")) (setvar "cmdecho" 0)

Page 67: Lsp

(setq A2k4 (>= (substr (getvar "ACADVER") 1 2) "16")) (if A2k4 (setvar "PEDITACCEPT" 0)) (setq okObjects '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE"))) (princ "\nSelect object to join: ") (setq ss1 (ssget okObjects)) (setq fuzz (getdist "\nFuzz distance <0>: ")) (if (= fuzz nil) (setq fuzz 0)) (if (/= ss1 nil) (progn

(setq objType (cdr (assoc 0 (entget (setq entLine (ssname ss1 0))))))(if (= (sslength ss1) 1) (setq ss1 (ssget "X" okObjects)))(if (member objType '("LINE" "ARC")) (command "_.pedit" "_M" ss1 "" "_Y" "_J" "_J" "_B" fuzz "") (command "_.pedit" "_M" ss1 "" "_J" "_J" "_B" fuzz ""))

) ) (setq ss1 nil) (setvar "cmdecho" oldcmdecho) (if A2k4 (setvar "PEDITACCEPT" oldpeditaccept)) (princ));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; PlotDevicesFunctions.lsp;;;;;; 2003-01-09 More functions added;;; 2006-07-30 Make it possible to add this lisp into your acaddoc.lsp;;; 2006-12-15 Corrected a minor bug;;;

(vl-load-com)

(defun ActLay () (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object) ) ))

; Return the Plotter configuration name(defun GetActivePlotDevice () (vla-get-ConfigName (ActLay) ))

; Return the Plot style table name(defun GetActiveStyleSheet () (vla-get-StyleSheet (ActLay) ))

; Force the Plotter configuration to something(defun PutActivePlotDevice (PlotDeviceName) (vla-put-ConfigName (ActLay) PlotDeviceName

Page 68: Lsp

))

; Force the Plot style table to something(defun PutActiveStyleSheet (StyleSheetName) (vla-put-StyleSheet (ActLay) StyleSheetName ))

; Return a list of all Plotter configurations(defun PlotDeviceNamesList () (vla-RefreshPlotDeviceInfo (ActLay)) (vlax-safearray->list (vlax-variant-value (vla-GetPlotDeviceNames (ActLay) ) ) ))

; Return a list of all Plot style tables(defun PlotStyleTableNamesList () (vla-RefreshPlotDeviceInfo (ActLay)) (vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (ActLay) ) ) ))

; If the saved Plotter configuration doesn't exist set it to None(defun PutActivePlotDeviceToNoneIfNotExist () (if (not (member (GetActivePlotDevice) (PlotDeviceNamesList))) (PutActivePlotDevice "None") ))

; If the saved Plot style table doesn't exist set it to None(defun PutActiveStyleSheetToNoneIfNotExist () (if (not (member (GetActiveStyleSheet) (PlotStyleTableNamesList)) ) (PutActiveStyleSheet "") ))

; Change the Plotter configuration "CompanyStandard.pc3" to your need(defun PutActivePlotDeviceToCompanyStandardIfNotExist () (if (not (member (GetActivePlotDevice) (PlotDeviceNamesList))) (PutActivePlotDevice "CompanyStandard.pc3") ))

; Change the Plot style table "CompanyStandard-A3-BW.ctb" to your need(defun PutActiveStyleSheetToCompanyStandardIfNotExist () (if (not (member (GetActiveStyleSheet) (PlotStyleTableNamesList)) )

Page 69: Lsp

(PutActiveStyleSheet "CompanyStandard-A3-BW.ctb") ))

; Change the Plotter configuration to the default one set in the options ; if the active plot device does not exist(defun PutActivePlotDeviceToDefaultIfNotExistOrNone () (if (or (not (member (GetActivePlotDevice) (PlotDeviceNamesList))) (= (GetActivePlotDevice) "None") ) (if (= (vla-get-UseLastPlotSettings (vla-get-output (vla-get-preferences (vlax-get-acad-object)) ) ) :vlax-true ) (PutActivePlotDevice (getenv "General\\MRUConfig") ) (PutActivePlotDevice (vla-get-DefaultOutputDevice (vla-get-output (vla-get-preferences (vlax-get-acad-object)) ) ) ) ) ))

; Change the Plot style table to the default one set in the options ; if the active Plot style table does not exist(defun PutActiveStyleSheetToDefaultIfNotExistOrNone () (if (or (not (member (GetActiveStyleSheet) (PlotStyleTableNamesList)) ) (= (GetActiveStyleSheet) "") ) (PutActiveStyleSheet (vla-get-DefaultPlotStyleTable (vla-get-output (vla-get-preferences (vlax-get-acad-object)) ) ) ) ))

; Customize this as you want ; Either force the Plot Device and/or the Style Sheet to something ; or only if the saved setting doesn't exist.

; If the Plot Device (printer, plotter or PC3 file) saved in the drawing ; and that will be used when printing does not exist or is set to None ; set it instead to your default plotter/printer(PutActivePlotDeviceToDefaultIfNotExistOrNone)

; If the Plot Style Table saved in the drawing ; and that will be used when printing does not exist or is set to None ; set it instead to your default plot style table(PutActiveStyleSheetToDefaultIfNotExistOrNone)

Page 70: Lsp

; These below can be used if you want them set to None if they don't exists ;(PutActivePlotDeviceToNoneIfNotExist) ;(PutActiveStyleSheetToNoneIfNotExist)

; If you want to enforce another company standard you can ; activate and change in these functions ;(PutActivePlotDeviceToCompanyStandardIfNotExist) ;(PutActiveStyleSheetToCompanyStandardIfNotExist)

(princ);;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected]

;;; Plot dialog by lisp(defun c:plotdialog() (initdia) (command "._plot"))

;;; profiles.lsp;;; miscellaneous profile commands;;; By Jimmy Bergmark;;; Copyright (C) 1997-2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-01-25;;; 2003-01-23 Added functions;;; 2008-08-08 Added forceImport

(vl-load-com)

; Brute force a profile to be imported; (forceImport "profilename" "C:\\temp\\testprof.arg" 1); inclpathinfo=1 The path information in the registry file will be preserved.; inclpathinfo=0 The path information in the registry file will not be preserved.; return T if profile is imported(defun forceImport (profilename argname inclpathinfo / tmp1 tmp2) (setq tmp1 "<<most-temporary1>>") (deleteProfile tmp1) (if (importProfile tmp1 argname inclpathinfo) (progn (putActiveProfile tmp1) (deleteProfile profilename) (renameProfile tmp1 profilename) (putActiveProfile profilename) T ) nil ))

(defun getActiveProfile () (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) ))

(defun putActiveProfile (profilename) (vla-put-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))

Page 71: Lsp

profilename ))

(defun getAllProfileNames(/ allprofiles) (vla-getallprofilenames (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) 'allprofiles ) (vlax-safearray->list allprofiles))

(defun existProfile (profilename) (not (not (member (strcase profilename) (mapcar '(lambda (x) (strcase x)) (getallprofilenames)) ))))

(defun c:listProfileNames(/ nr profnames) (setq nr 0) (setq profnames (getAllProfileNames)) (repeat (length profnames) (princ (nth nr profnames)) (print) (setq nr (1+ nr)) ) (princ))

; return T if profile is deleted and nil if not(defun deleteProfile (profilename) (if (and (/= (strcase profilename) (strcase (getActiveProfile))) (existProfile profilename)) (not (vla-deleteprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilename )) ))

; Delete all profiles except the current profile(defun deleteAllProfilesExceptCurrent (/ item) (foreach item (getAllProfileNames) (vl-catch-all-apply 'vla-deleteprofile (list (vla-get-profiles

(vla-get-preferences (vlax-get-acad-object)) ) item

) ) ))

; return T if profile is reseted and nil if not(defun resetProfile (profilename) (if (existProfile profilename) (not (vla-resetprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilename ))

Page 72: Lsp

))

; return T if profile is renamed and nil if not; if profilenameNew exist it's substituded with profilenameOld(defun renameProfile (profilenameOld profilenameNew) (if (existProfile profilenameOld) (not (vla-renameprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilenameOld profilenameNew )) ))

; return T if profile is copied and nil if not; if profilename2 exists it's copied(defun copyProfile (profilename1 profilename2) (if (existProfile profilename1) (not (vla-copyprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilename1 profilename2 )) ))

; (exportProfile "profilename" "C:\\TEMP\\profilename.arg"); if path is omitted profile is saved in active directory; overwrites argname if it exists; return T if profile is exported(defun exportProfile (profilename argname) (if (existProfile profilename) (not (vla-exportprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilename argname )) ))

; (importProfile "profilename" "C:\\TEMP\\profilename.arg" 1); overwrites profilename if it exists; if path is omitted profile is imported from active directory; inclpathinfo=1 The path information in the registry file will be preserved.; inclpathinfo=0 The path information in the registry file will not be preserved.; return T if profile is imported(defun importProfile (profilename argname inclpathinfo) (not (vl-catch-all-apply 'vla-importprofile (list (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) profilename argname inclpathinfo )) ))

; Brute force a profile to be imported and all the resting to be deleted; (forceImportAndDeleteTheRest "profilename" "C:\\temp\\testprof.arg" 1); inclpathinfo=1 The path information in the registry file will be preserved.; inclpathinfo=0 The path information in the registry file will not be preserved.; return T if profile is imported(defun forceImportAndDeleteTheRest (profilename argname inclpathinfo / tmp1 tmp2)

Page 73: Lsp

(setq tmp1 "<<most-temporary1>>") (deleteProfile tmp1) (if (importProfile tmp1 argname inclpathinfo) (progn (putActiveProfile tmp1) (deleteProfile profilename) (renameProfile tmp1 profilename) (putActiveProfile profilename) (deleteAllProfilesExceptCurrent) T ) nil ))

;;; ProjectPaths.LSP;;; Among other things it can save the paths ;;; to a file that can be imported on another PC.;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; Tested on AutoCAD 2000, 2006

(vl-load-com)

(defun ReadProject-Settings (cprof) (vl-registry-descendents (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" cprof "\\Project Settings" ) ))

(defun ReadRefSearchPath (cprof ProjSet) (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" cprof "\\Project Settings\\" ProjSet ) "RefSearchPath" ))

;;; Ex: (AllProjPath (getvar "CPROFILE"))(defun AllProjPath (cprof / lst ProjSet) (foreach ProjSet (ReadProject-Settings cprof) (setq lst (cons (cons ProjSet (ReadRefSearchPath cprof ProjSet)) lst)) ))

;;; Ex: (WriteRefSearchPath (getvar "CPROFILE") "Project1" "c:\temp;c:\project")(defun WriteRefSearchPath (cprof ProjSet path)

Page 74: Lsp

(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" cprof "\\Project Settings\\" ProjSet ) "RefSearchPath" path ))

;;; Deletes all Project paths(defun DeleteRefSearchPath (cprof) (foreach ProjSet (ReadProject-Settings cprof) (vl-registry-delete (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" cprof "\\Project Settings\\" ProjSet ) ) ))

;;; Ex: (WriteAllProjPath (getvar "CPROFILE") (list (cons "Project1" "C:\\") (cons "Project2" "D:\\")));;; Deletes all old Paths first(defun WriteAllProjPath (cprof lst / ProjSet) (DeleteRefSearchPath cprof) (foreach ProjSet lst (WriteRefSearchPath cprof (car ProjSet) (cdr ProjSet)) ))

;;; Ex: (Print-AllProjPaths (getvar "CPROFILE"))(defun Print-AllProjPaths (cprof / ProjSet) (princ "Project Files Search Path:\n") (foreach ProjSet (ReadProject-Settings cprof) (princ ProjSet) (princ " = ") (princ (ReadRefSearchPath cprof ProjSet)) (terpri) ) (princ))

;;; Change "r:\\paths.txt" to a location on the server;;; (getProjectPaths "c:\\paths.txt")(defun getProjectPaths (fn / cprof paths f) (setq cprof (getvar "CPROFILE")) (setq paths (AllProjPath cprof)) (setq f (open fn "w")) (foreach ProjSet (ReadProject-Settings cprof) (write-line ProjSet f) (write-line (ReadRefSearchPath cprof ProjSet) f) ) (close f))

Page 75: Lsp

;;; Change "r:\\paths.txt" to a location on the server;;; (putProjectPaths "c:\\paths.txt")(defun putProjectPaths (fn / cprof line1 line2 paths f) (setq cprof (getvar "CPROFILE")) (setq f (open fn "r")) (while (and (setq line1 (read-line f)) (setq line2 (read-line f))) (setq paths (cons (cons line1 line2) paths)) ) (close f) (WriteAllProjPath cprof paths));;; purge-point.LSP;;;;;; These commands shall be used with caution since they destroys;;; the intelligence in the objects. But it can reduce the size very much;;; if that is what is needed.;;; A test with an Architectural drawing reduced the size from 1061kB to 172kB.;;;;;; c:purge-vent Kills all POINT 5 vent-objects and V50-dictionaries;;; c:purge-aec Kills all POINT 5 architect-objects and dictionaries;;; the above command (purge-aec) shall be run when POINT A is unloaded to work correct;;; c:purge-point5 Kills all POINT 5 general objects in a drawing;;; c:purge-point Kills all POINT general objects in a drawing;;; c:purge-all-point runs all of the above commands;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-04-05 - First release;;; 2000-06-05 - Strcase on wcmatch of dict. on entities;;; 2000-06-19 - Buggfix on strcase of nil;;; Tested on AutoCAD 2000 and POINT 5

(defun deldict (dictName) (dictremove (namedobjdict) dictName))

(defun listdictionaries () (massoc 3 (entget (namedobjdict))))

(defun massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist))

(defun kill-dict (typ / olderr oldcmdecho errexit undox restore en more ed no repl ed360 ed3) (defun errexit (s) (princ "\nError: ") (princ s) (restore) )

(defun undox () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) (setq *error* olderr)

Page 76: Lsp

(princ) )

(setq olderr *error* restore undox *error* errexit ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (initget 0 "Yes No") (setq repl (getkword "\nAre you sure? [Yes/No] <No>: ")) (if repl (progn (setq en (entnext)) (setq more (not (not en))) (setq no 0) (while more (setq ed (entget en)) (if (and (/= (member '(102 . "{ACAD_XDICTIONARY") ed) nil) (setq ed360 (assoc 360 ed)) (setq ed3 (assoc 3 (entget (cdr ed360)))) (wcmatch (strcase (cdr ed3)) (strcase typ)) ) (progn (entdel en) (setq ed (append (reverse (cdr (member '(102 . "{ACAD_XDICTIONARY") (reverse ed))) ) (cdr (member '(102 . "}") ed)) ) ) (if (not (entmake ed)) (progn (entdel en) (princ "\nError deleting: ") (princ en) ) (setq no (1+ no)) ) ) (if (= (setq en (entnext en)) nil) (setq more nil) ) ) ) (foreach dict (listdictionaries) (if (wcmatch (strcase dict) (strcase typ)) (deldict dict)) ) ) ) (princ "\nNumber of deleted objects: ") (princ no) (restore))

(defun c:purge-vent() (kill-dict "V50*"))(defun c:purge-point5() (kill-dict "Point5*"))(defun c:purge-point() (kill-dict "Point"))(defun c:purge-aec() (kill-dict "PointAec*"))

Page 77: Lsp

(defun c:purge-all-point() (kill-dict "Point*") (kill-dict "V50*"))(princ)

;;; PURGER.LSP;;;;;; Various purge functions with no command line echo;;; ;;; By Jimmy Bergmark;;; Copyright (C) 1997-2004 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-02-12 - First release;;; 2003-01-09 - More added;;; 2004-05-23 - Added support to delete filters in 2005;;; Written for AutoCAD 2000, 2000i, 2002, 2004, 2005;;;

;;; Purge named block;;; Example: (ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "testblock");;; Argument: doc {document};;; name {a block name};;; Return values: T if successful, nil if not successful(defun ax:purge-block (doc name) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list (vl-catch-all-apply 'vla-item (list (vla-get-blocks doc) name) ) ) ) ) nil ; name cannot be purged or doesn't exist T ; name purged ))

;;; Purge named layer;;; Example: (ax:purge-layer (vla-get-activedocument (vlax-get-acad-object)) "testlayer");;; Argument: doc {document};;; name {a layer name};;; Return values: T if successful, nil if not successful(defun ax:purge-layer (doc name) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list (vl-catch-all-apply 'vla-item (list (vla-get-layers doc) name) ) ) ) ) nil ; name cannot be purged or doesn't exist T ; name purged ))

;;; Purge all layers;;; Example: (ax:purge-all-layers (vla-get-activedocument (vlax-get-acad-object)))

Page 78: Lsp

;;; Argument: doc {document}(defun ax:purge-all-layers (doc) (vlax-for item (vla-get-layers doc) (purge-layer (vla-get-name item)) ))

;;; Purge all layers except those in list;;; Example: (ax:purge-layers (vla-get-activedocument (vlax-get-acad-object)) '("DIM" "LAYER1"));;; Argument: doc {document};;; name {a layer name list}(defun ax:purge-layers (doc except) (vlax-for item (vla-get-layers doc) (setq ln (vla-get-name item)) (if (not (member (strcase ln) except)) (purge-layer ln) ) ))

;;; Purge all with no echo to command window;;; Example: (ax:purge-no-echo (vla-get-activedocument (vlax-get-acad-object)));;; Argument: doc {document}(defun ax:purge-no-echo (doc)

;;; Returns a list of keynames from the specified dictionary(defun getkeys (dictName / tmp) (if (setq tmp (dictsearch (namedobjdict) dictName)) (massoc 3 tmp) ))

;;; Retrieves the entity name of the specified dictionary(defun getdictname (dictName) (if (setq tmp (dictsearch (namedobjdict) dictName)) (cdr (assoc -1 tmp)) )) ;;; Utility function to get multiple group code CDRs(defun massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist)) (vlax-for item (vla-get-blocks doc) (vl-catch-all-apply 'vla-delete (list item)) ) (vlax-for item (vla-get-dimstyles doc) (vl-catch-all-apply 'vla-delete (list item)) ) (vlax-for item (vla-get-linetypes doc) (vl-catch-all-apply 'vla-delete (list item)) ) (vlax-for item (vla-get-plotconfigurations doc) (vl-catch-all-apply 'vla-delete (list item)) ) ; textstyles (vlax-for item (vla-get-textstyles doc)

Page 79: Lsp

(if (= (cdr (assoc 70 (entget (vlax-vla-object->ename item)))) 0) (vl-catch-all-apply 'vla-delete (list item)) ) ) ; shapes (vlax-for item (vla-get-textstyles doc) (if (= (cdr (assoc 70 (entget (vlax-vla-object->ename item)))) 1) (vl-catch-all-apply 'vla-delete (list item)) ) ) (setq li (getkeys "ACAD_MLINESTYLE")) (setq len (length li)) ; one style has to be left (foreach na (cdr li) (delrecord "ACAD_MLINESTYLE" na) ) (setq li (getkeys "ACAD_MLINESTYLE")) (setq len (length li)) (if (> len 1) (delrecord "ACAD_MLINESTYLE" (car li)) ) (vlax-for item (vla-get-layers doc) (vl-catch-all-apply 'vla-delete 'item) ) nil)

;;; Purge/delete all layer filters;;; Example: (DeleteLayerFilters)(defun DeleteLayerFilters () (vl-Catch-All-Apply '(lambda () (vla-Remove

(vla-GetExtensionDictionary (vla-Get-Layers (vla-Get-ActiveDocument (vlax-Get-Acad-Object)) ) ) "ACAD_LAYERFILTERS"

) ) ) (princ))

;;; Purge/delete all layer filter or filters compatible with 2005 or later;;; Example: (DeleteLayerFilters2)(defun DeleteLayerFilters2 () (vl-Catch-All-Apply '(lambda () (vla-Remove

(vla-GetExtensionDictionary (vla-Get-Layers (vla-Get-ActiveDocument (vlax-Get-Acad-Object)) ) ) "AcLyDictionary"

) ) ) (princ))

Page 80: Lsp

;;; Purge/delete all layer states;;; Example: (DeleteLayerStates)(defun DeleteLayerStates () (vl-Catch-All-Apply '(lambda () (vla-Remove (vla-GetExtensionDictionary (vla-Get-Layers (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))) "ACAD_LAYERSTATES"))) (princ));;; Purge/delete all Express Tool layer states;;; Example: (LmanKill)(defun LmanKill (/ lyr ent cnt) (setq cnt 0) (while (setq lyr (tblnext "layer" (not lyr))) (setq ent (entget (tblobjname "layer" (cdr (assoc 2 lyr)))'("RAK"))) (if (and ent (assoc -3 ent)) (progn (setq ent (subst '(-3 ("RAK")) (assoc -3 ent) ent)) (entmod ent) (setq cnt (1+ cnt)) ) ) ) (princ));;; (deleteAllPageSetups)(defun deleteAllPageSetups (/ pc) (vlax-for pc (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object))) (vla-delete pc) ))

(defun PurgeAnonymGroups (/ grpList index grp) (setq grpList (dictsearch (namedobjdict) "ACAD_GROUP")) (setq index 1) (while (setq grp (nth index grplist)) (if (= (car grp) 3) (progn

(if (= (chr 42) (substr (cdr grp) 1 1)) (entdel (cdr (nth (+ index 1) grplist))))

) ) (setq index (+ 1 index)) ) (princ))(defun PurgeAllGroups (/ grpList index grp) (setq grpList (dictsearch (namedobjdict) "ACAD_GROUP")) (setq index 1) (while (setq grp (nth index grplist)) (if (= (car grp) 3) (entdel (cdr (nth (+ index 1) grplist))) ) (setq index (+ 1 index)) ) (princ))(defun DelACAD_VBA ()

Page 81: Lsp

(dictremove (namedobjdict) "ACAD_VBA") (princ))(defun PurgeAPPID (/ appid) (vl-load-com) (vlax-for appid (vla-get-registeredapplications

(vla-get-activedocument (vlax-get-acad-object) ) )

(vl-catch-all-apply 'vla-delete (list appid)) ) (princ))

(princ)

;;; PurgeReconciledLayers.LSP;;;;;; By Jimmy Bergmark;;; Copyright (C) 2007 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2007-04-05 - First release;;; Written for AutoCAD 2008

;;; Purge all information about reconciled layers in the drawing

(defun PurgeReconciledLayers () (vl-load-com) (vlax-for layer (vla-get-Layers

(vla-get-ActiveDocument (vlax-get-acad-object) ) )

(vl-Catch-All-Apply '(lambda ()

(vla-Remove (vla-GetExtensionDictionary layer ) "ADSK_XREC_LAYER_RECONCILED" )

) ) (vl-Catch-All-Apply '(lambda ()

(vla-delete (vla-GetExtensionDictionary layer ) )

) ) ) (setvar "LAYEREVAL" 0) (setvar "LAYERNOTIFY" 0) (princ))

; Remove the row below if you don't want to run the code automatically when the AutoLISP file is loaded.(PurgeReconciledLayers)

Page 82: Lsp

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2012 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; This program is created for AutoCAD 2002, AutoCAD 2004;;; AutoCAD 2005, AutoCAD 2006, AutoCAD 2007, AutoCAD 2008;;; AutoCAD 2009, AutoCAD 2010, AutoCAD 2011, AutoCAD 2012;;; AutoCAD 2013 and vertical products;;; Removes the icons Autodesk 360, Buzzsaw, RedSpark, Point A and FTP in Open dialog box;;;;;; To remove all of the Icons above for all profiles use (remicons T T T T T T);;; To remove only Buzzsaw in active profile use (remicons nil T nil nil nil nil);;; To restore all of the Icons to all profiles use (remicons nil nil nil nil nil T);;; (remicons <Autodesk 360> <Buzzsaw> <RedSpark> <Point A> <FTP> <All profiles=T, current profile=nil>)

(defun remicons (accloud ibuzz ired ipoint iftp allprof / prof profiles regkey) (vl-load-com) (defun getallprofilenames (/ allprofiles) (vla-getallprofilenames (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)) ) 'allprofiles ) (vlax-safearray->list allprofiles) ) (setq profiles (getallprofilenames)) (if (not allprof) (setq profiles (list (getvar "CPROFILE")))) (foreach prof profiles (setq regkey (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" prof "\\Dialogs\\AllAnavDialogs\\DeletedExtensions" ) ) (if accloud (vl-registry-write regkey "AcCloud" "" ) (vl-registry-delete regkey "AcCloud") ) (if ibuzz (vl-registry-write regkey "Buzzsaw" "" ) (vl-registry-delete regkey "Buzzsaw") ) (if ibuzz (vl-registry-write regkey "ACPROJECT" "" ) (vl-registry-delete regkey "ACPROJECT") ) (if ired (vl-registry-write regkey

Page 83: Lsp

"RedSpark" "" ) (vl-registry-delete regkey "RedSpark") ) (if ipoint (vl-registry-write regkey "SimpleStorageSites" "" ) (vl-registry-delete regkey "SimpleStorageSites") ) (if iftp (vl-registry-write regkey "FTPSites" "" ) (vl-registry-delete regkey "FTPSites") ) ) (princ))

(princ);;; SOPEN.LSP;;; Open command that works for all cases;;; Works for SDI=0 or SDI=1

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 1999-09-12 - First release;;; 2002-05-14 - Bug fixed;;; Written for AutoCAD 2000+;;; Ex: (sopen "c:\\drawing1.dwg");;; Note that QAFLAGS might not be restored to 0 so you might want to add (setvar "qaflags" 0) to acaddoc.lsp or any other startup lisp.(vl-load-com);;; opens and activates a file as Read-Only(defun openRO (fna) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fna :VLAX-TRUE)))

(defun sopen (fna / n) (if (= 0 (getvar "SDI")) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fna)) (progn (if (not (equal 2 (logand 2 (getvar "qaflags")))) (setvar "qaflags" (+ (getvar "qaflags") 2)) ) (if (not (equal 4 (logand 4 (getvar "qaflags")))) (setvar "qaflags" (+ (getvar "qaflags") 4)) ) (command "_.open") (if (not (equal 0 (getvar "dbmod"))) (command "_y") ) (command fna) (setq n 0) (while (and (< n 4) (wcmatch (getvar "cmdnames") "*OPEN*")

Page 84: Lsp

) (T (command "") ) (setq n (+ n 1)) ) (setvar "qaflags" 0) ) ))

;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; Save and loads support paths to a text file;;;;;; Change the path as wished

(defun C:saveSupportPaths (/ files paths f) (vl-load-com) (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) (setq paths (vla-get-supportpath files)) (setq f (open "r:\\paths.txt" "w")) (write-line paths f) (close f) (princ))

(defun C:loadSupportPaths (/ files paths f) (vl-load-com) (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) (setq f (open "r:\\paths.txt" "r")) (setq paths (read-line f)) (close f) (vla-put-supportpath files paths) (princ))

;;; Change all text styles on all objects to specified text style;;; (ax:ChangeTextStyleName "ISOCPEUR")(defun ax:ChangeTextStyleName (style / sset ename i) (vl-load-com) (setq i 0) (setq sset (ssget "X" '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>")))) (if sset (repeat (sslength sset) (setq ename (ssname sset i)) (setq i (1+ i)) (vla-put-stylename (vlax-ename->vla-object ename) style) ) ) (setq sset nil));;; th.LSP ver 1.0;;; Set selected text or mtext to specified height;;; Text is resized based on the justification point;;; By Jimmy Bergmark;;; Copyright (C) 2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com

Page 85: Lsp

;;; E-mail: [email protected];;; 2008-03-14 - First release;;; Tested on AutoCAD 2009;;; should be working on older and newer versions too.

(defun c:th (/ sset i txtheight textsize) (vl-load-com) (setq i 0) (setq sset (ssget '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>")))) (if sset (progn (setq textsize (getvar "textsize")) (setq txtheight (getdist (strcat "\nSpecify text height <" (rtos textsize) ">: "))) (if (= txtheight nil) (setq txtheight textsize)) (repeat (sslength sset) (vla-put-height (vlax-ename->vla-object (ssname sset i)) txtheight) (setq i (1+ i)) ) (setq sset nil) ) ) (princ))

(princ "\nRun with the TH command")(princ);;; tsh0.LSP ver 1.0;;; Set all text style's height to 0;;; By Jimmy Bergmark;;; Copyright (C) 2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2008-03-08 - First release;;; Tested on AutoCAD 2009;;; should be working on older versions too.

(defun C:TSH0 (/ ad style oldcmdecho) (vl-load-com) (setq ad (vla-get-ActiveDocument (vlax-get-Acad-Object))) (princ "Listed text style's height have been set to 0:") (vlax-for style (vla-get-TextStyles ad) (if (and (/= (wcmatch (vla-get-Name style) "*|*") T) (/= (vla-get-Height style) 0.0)) (progn (vla-put-Height style 0.0) (princ "\n") (princ (vla-get-Name style)) ) ) ) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._regenall") (setvar "cmdecho" oldcmdecho) (princ))

(princ "\nRun with the TSH0 command")(princ);;; By Jimmy Bergmark;;; Copyright (C) 1997-2012 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; rotate selected text objects to specified angle

Page 86: Lsp

(defun c:txtrot (/ sset i ed ang) (if (setq sset (ssget '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>") ) ) ) (progn (setq ang (getangle "Specify rotation angle <0>: ")) (if (null ang) (setq ang 0) ) (repeat (setq i (sslength sset)) (setq ed (entget (ssname sset (setq i (1- i))))) (entmod (subst (cons 50 ang) (assoc 50 ed) ed ) ) ) ) ) (setq sset nil) (princ));;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected](vl-load-com);;; get the viewportcenter(setq viewportcenter (vlax-safearray->list (vlax-variant-value (vla-get-center (vla-get-activepviewport (vla-get-activedocument (vlax-get-acad-object)))))))

;;; viewsIO.lsp;;;;;; Export and import views;;;;;; c:ExportViews;;; c:ImportViews;;; c:-ExportViews;;; c:-ImportViews;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2008 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2000-06-27;;;;;; Tested on AutoCAD 2000-2004;;;;;; Modified by Marko Ribar 2012-04-21;;;

Page 87: Lsp

;;; Tested on AutoCAD 2012

(vl-load-com)

(defun c:ExportViews (/ fn) (if (setq fn (getfiled "Export views to" (strcat (vl-filename-base (getvar "dwgname")) ".txt") "txt" 1 ) ) (ExportViews fn) ) (princ))

(defun c:ImportViews (/ fn) (if (setq fn (getfiled "Import views from" (strcat (vl-filename-base (getvar "dwgname")) ".txt") "txt" 16 ) ) (ImportViews fn) ) (princ))

(defun c:-ExportViews (/ fn x) (setq fn (strcat (vl-filename-base (getvar "dwgname")) ".txt")) (if (setq fn (findfile (if (= "" (setq nn (getstring T (strcat "Enter filename <" fn ">: " ) ) ) ) fn nn ) ) ) (progn (initget "Yes No") (setq x (getkword "\nFile exists. Overwrite? [Yes/No] <No>: ")) (if (= x "Yes") (ExportViews fn)) ) (princ "\nFile not found.") ) (princ))

(defun c:-ImportViews (/ fn) (setq fn (strcat (vl-filename-base (getvar "dwgname")) ".txt")) (if (setq fn (findfile

Page 88: Lsp

(if (= "" (setq nn (getstring T (strcat "Enter filename <" fn ">: " ) ) ) ) fn nn ) ) ) (ImportViews fn) (princ "\nFile not found.") ) (princ))

(defun ExportViews (fn / e tl f ed) (while (setq e (tblnext "VIEW" (null e))) (setq tl (cons (cdr (assoc 2 e)) tl)) ) (setq f (open fn "w")) (if f (progn (princ "Following views exported:\n") (foreach view tl (setq ed (entget (tblobjname "view" view))) (if (assoc 348 ed) (prin1 (cons (cons 0 "VISUALSTYLE") (member (assoc 100 (entget (cdr (assoc 348 ed)))) (entget (cdr (assoc 348 ed))))) f)) (if (assoc 348 ed) (princ "\n" f)) (prin1 (cons (cons 0 "VIEW") (if (assoc 348 ed) (reverse (cdr (reverse (member (assoc 100 ed) ed)))) (member (assoc 100 ed) ed))) f) (princ "\n" f) (prin1 view) (terpri) ) (close f) ) ))

(defun ImportViews (fn / tl assoc348 assoc330 en330 en348 f) (setq f (open fn "r")) (if f (progn (princ "Following views imported:\n") (while (setq tl (read-line f)) (setq tl (read tl)) (if (eq (cdr (assoc 0 tl)) "VIEW") (progn (entmake tl) (print (cdr (assoc 2 tl))) ) ) (if (eq (cdr (assoc 0 tl)) "VISUALSTYLE") (progn

(vlax-for di (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))) (if (eq (vl-catch-all-apply 'vla-get-name (list di)) "ACAD_VISUALSTYLE") (setq en330 (vlax-vla-object->ename di)))) (setq assoc330 (cons 330 en330)) (setq assoc348 (cons 348 (setq en348 (entmakex tl))))

(entmod (subst assoc330 (assoc 330 (entget en348)) (entget en348)))

Page 89: Lsp

(setq tl (read-line f)) (setq tl (read tl)) (setq tl (reverse (cons assoc348 (reverse tl)))) (entmake tl) (print (cdr (assoc 2 tl))) ) ) ) (close f) ) ))

(princ);;;---------------------------------------------------------------------------;;;;;;; VPlayers.lsp;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2000-09-07 - First release;;; Tested on AutoCAD 2000;;;;;;---------------------------------------------------------------------------;;;; DESCRIPTION;;;;;; c:SaveVPlayers - Save frozen viewport layers to file;;; c:LoadVPlayers - Load and restore frozen viewport layers from file;;; c:CopyVPlayers - Select one viewport and get the layersettings;;; then select the destination viewport(s) to inherit these;;;---------------------------------------------------------------------------;(vl-load-com)(defun dxf (n ed) (cdr (assoc n ed)))

;;; return a list of frozen layers in current viewport;;; ex. (viewport-frozen-layer-list) -> ("Layer3" "Layer4");;; alt. with Express Tools (ACET-VIEWPORT-FROZEN-LAYER-LIST (ACET-CURRENTVIEWPORT-ENAME))(defun viewport-frozen-layer-list (/ cvp) (if (= 0 (getvar "tilemode")) (if (/= 1 (setq cvp (getvar "cvport"))) (apply 'append (mapcar '(lambda (x) (if (= 1003 (car x)) (list (cdr x)) ) ) (cdadr (assoc -3 (entget (ssname (ssget "_X" (list (cons 69 cvp) (cons 410 (getvar "ctab"))) ) 0 ) '("acad") )

Page 90: Lsp

) ) ) ) ) ))

(defun GetVPlayers (/ ss ent vpno) (command "._pspace") (princ "\nSelect source viewport: ") (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) (if ss (progn (setq ent (ssname ss 0)) (setq ss nil) (setq vpno (dxf 69 (entget ent))) (command "._mspace") (setvar "cvport" vpno) (viewport-frozen-layer-list) ) ))

(defun c:SaveVPlayers (/ fn oldcmdecho VAL f *error* restore layers) (defun *error* (str) (restore) (if str (prompt (strcat "Error: " str)) ) (princ) ) (defun restore () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) )

(setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (cond ((not (equal 0 (getvar "tilemode"))) (princ "\n Command not allowed unless TILEMODE is set to 0 " ) ) ((> 2 (sslength (ssget "_x" (list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab"))) ) ) ) (princ "\n Command works with one or more viewports only " ) ) ((not (setq fn (getfiled "Save ViewPort layer list as" (vl-filename-base (getvar "dwgname")) "vpl" 1 )

Page 91: Lsp

) ) ) ((not (setq f (open fn "w"))) (princ "\n Cannot write to file!") ) (T (setq layers (GetVPlayers)) (if layers (prin1 layers f) (princ "\n There are no frozen VP layers.") ) (command "._pspace") (close f) ) ) (restore) (princ))

(defun PutVPlayers (layers / VAL ss) (if layers (progn (princ "\nSelect destination viewport: ") (command "._pspace") (setq ss (ssget ":E" '((0 . "VIEWPORT")))) (if ss (progn (command "_.vplayer" "_thaw" "*" "_select" ss "") (foreach VAL layers (command "_freeze" VAL "_select" ss "")) (setq ss nil) (command "") ) ) ) ))

(defun c:LoadVPlayers (/ oldcmdecho fn tl lst *error* restore) (defun *error* (str) (restore) (if str (prompt (strcat "Error: " str)) ) (princ) ) (defun restore () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) )

(setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (cond ((not (equal 0 (getvar "tilemode"))) (princ "\n Command not allowed unless TILEMODE is set to 0 " ) ) ((> 2 (sslength (ssget "_x"

Page 92: Lsp

(list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab"))) ) ) ) (princ "\n Command works with one or more viewports only " ) ) ((not (setq fn (getfiled "Open ViewPort layer list" (vl-filename-base (getvar "dwgname")) "vpl" 0 ) ) ) ) ((not (setq f (open fn "r"))) (princ "\n Cannot read file!") ) (T (setq lst (read (read-line f))) (if (= (type lst) 'LIST) (PutVPlayers lst) ) (command "._pspace") (close f) ) ) safe (restore) (princ))

(defun c:CopyVPlayers (/ oldcmdecho *error* restore layers) (defun *error* (str) (restore) (if str (prompt (strcat "Error: " str)) ) (princ) ) (defun restore () (command "._undo" "_E") (setvar "cmdecho" oldcmdecho) )

(setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (command "._UNDO" "_BE") (cond ((not (equal 0 (getvar "tilemode"))) (princ "\n Command not allowed unless TILEMODE is set to 0 " ) ) ((> 3 (sslength (ssget "_x" (list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab"))) ) ) ) (princ "\n Command works with two or more viewports only "

Page 93: Lsp

) ) (T (setq layers (GetVPlayers)) (if layers (PutVPlayers layers) (princ "\n There are no frozen VP layers.") ) (command "._pspace") ) ) (restore) (princ))

(princ);;; vp-outline.lsp;;;;;; Creates a polyline in modelspace that;;; has the outline of the selected viewport.;;; Supports clipped viewports. polyline is supported;;; ellipse, spline, region and circle not supported at this point;;; If vp-outline is called when in mspace it detects;;; the active viewport.;;;;;; c:vp-outline;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2013 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2000-04-10;;; 2003-11-19 Added support for drawing the outline in other ucs/view than world/current;;;;;; 2006-04-06 Added support for twisted views Tom Beauford;;; 2013-06-08 Added support for circular viewports;;;;;; Should work on AutoCAD 2000 and newer(vl-load-com)

(defun dxf (n ed) (cdr (assoc n ed)))

(defun ax:List->VariantArray (lst) (vlax-Make-Variant (vlax-SafeArray-Fill (vlax-Make-SafeArray

vlax-vbDouble(cons 0 (- (length lst) 1))

) lst ) ))

(defun c:vp-outline (/ ad ss ent pl plist xy n vpbl vpur msbl msur ven vpno ok circ)

(setq ad (vla-get-activedocument (vlax-get-acad-object))) (if (= (getvar "tilemode") 0) (progn (if (= (getvar "cvport") 1)

(progn (if (setq ss (ssget ":E:S" '((0 . "VIEWPORT"))))

Page 94: Lsp

(progn (setq ent (ssname ss 0)) (setq vpno (dxf 69 (entget ent))) (vla-Display (vlax-ename->vla-object ent) :vlax-true) (vla-put-mspace ad :vlax-true) ; equal (command "._mspace")

; this to ensure trans later is working on correct viewport (setvar "cvport" vpno)

; (vla-put-mspace ad :vlax-false) ; equal (command "._pspace") (setq ok T) (setq ss nil)

) ))(setq ent (vlax-vla-object->ename (vla-get-activepviewport ad)) ok T)

) (if ok

(progn (setq circle nil) (setq ven (vlax-ename->vla-object ent)) (if (/= 1 (logand 1 (dxf 90 (entget ent)))) ; detect perspective

(progn (if (= (vla-get-clipped ven) :vlax-false) (progn ; not clipped (vla-getboundingbox ven 'vpbl 'vpur) (setq vpbl (trans (vlax-safearray->list vpbl) 3 2)

msbl (trans vpbl 2 1) msbl (trans msbl 1 0) vpur (trans (vlax-safearray->list vpur) 3 2) msur (trans vpur 2 1) msur (trans msur 1 0) vpbr (list (car vpur) (cadr vpbl) 0) msbr (trans vpbr 2 1) msbr (trans msbr 1 0) vpul (list (car vpbl) (cadr vpur) 0) msul (trans vpul 2 1) msul (trans msul 1 0) plist (list (car msbl)

(cadr msbl) (car msbr) (cadr msbr) (car msur) (cadr msur) (car msul) (cadr msul))

) ) (progn ; clipped (setq pl (entget (dxf 340 (entget ent)))) (if (= (dxf 0 pl) "CIRCLE") (setq circle T) (progn (setq plist (vla-get-coordinates

(vlax-ename->vla-object (dxf -1 pl)) )

plist (vlax-safearray->list (vlax-variant-value plist)) n 0 pl nil

) (repeat (/ (length plist) 2) (setq xy (trans (list (nth n plist) (nth (1+ n) plist)) 3 2)

xy (trans xy 2 1) xy (trans xy 1 0) pl (cons (car xy) pl) pl (cons (cadr xy) pl)

Page 95: Lsp

n (+ n 2) ) ) (setq plist (reverse pl))

) ) ))(if circle (vla-AddCircle (vla-get-ModelSpace ad) (ax:List->VariantArray (trans (trans (trans (dxf 10 pl) 1 0) 2 1) 3 2) ) (/ (dxf 40 pl) (caddr (trans '(0 0 1) 2 3))) ) (vla-Put-Closed (vla-AddLightWeightPolyline (vla-get-ModelSpace ad) (ax:List->VariantArray plist) ) :vlax-True ))

) ))

) ) ) (if ss (vla-put-mspace ad :vlax-false) ) ; equal (command "._pspace")) (princ));;;---------------------------------------------------------------------------;;;;;;; vpsel.lsp;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;;;;; 2000-04-14 - First release;;; Tested on AutoCAD 2000;;;;;;---------------------------------------------------------------------------;;;; DESCRIPTION;;;;;; Select all visible objects in selected or active paperspace viewport;;; Works transparently when in modelspace and for polygonal viewports too;;; Example1: ERASE ALL R 'VPC >>> Erase all in model except what is visible;;; Example2: (command "erase" "all" "r" (c:vpc) "");;; Example3: VPC ERASE >>> VPC is run previous the command and the objects;;; are also in previous selection set;;;;;; c:vpc - select all visible objects with crossing in viewport;;; c:vpw - select all visible objects with window in viewport;;;---------------------------------------------------------------------------;

(defun c:vpc () (vpsel "C")

Page 96: Lsp

(princ))

(defun c:vpw () (vpsel "W") (princ))

(defun dxf (n ed) (cdr (assoc n ed)))

(defun vpsel (typ / ad ss ent vpno ok vpbl vpur msbl msur msul mslr ss1 pl nlist x n ) (vl-load-com) (setq ok t) (if (= (getvar "tilemode") 0) (progn (setq ad (vla-get-activedocument (vlax-get-acad-object))) (if (= (getvar "cvport") 1) (if (and (= (getvar "cmdactive") 0) (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil) ) (progn (setq ent (ssname ss 0)) (setq vpno (dxf 69 (entget ent))) (vla-Display (vla-get-activepviewport ad) :vlax-true) (vla-put-mspace ad :vlax-true) (setvar "cvport" vpno) ) (progn (setq ok nil) ) ) (setq ent (vlax-vla-object->ename (vla-get-activepviewport ad))) ) (if (and ok (/= 1 (logand 1 (dxf 90 (setq ed (entget ent)))))) (progn (if (= (vla-get-clipped (vlax-ename->vla-object ent)) :vlax-false ) (progn (vla-getboundingbox (vla-get-activepviewport ad) 'vpbl 'vpur ) (setq msbl (trans (vlax-safearray->list vpbl) 3 2)) (setq msur (trans (vlax-safearray->list vpur) 3 2)) (setq msul (list (car msbl) (cadr msur))) (setq mslr (list (car msur) (cadr msbl))) (setq ss1 (ssget (strcat typ "P") (list msbl msul msur mslr)) ) ) (progn (setq pl (entget (dxf 340 (entget ent)))) (setq nlist nil) (foreach x pl (if (eq 10 (car x)) (setq nlist (cons (trans (cdr x) 3 2) nlist)) ) ) (setq ss1 (ssget (strcat typ "P") nlist))

Page 97: Lsp

) ) (sssetfirst nil ss1) (if ss1 (setq n (sslength ss1)) (setq n 0) ) (princ n) (princ " found ") (if (and ss1 (= (getvar "cmdactive") 1)) ss1 ) ) ) ) ) (setq ss nil ss1 nil))

(princ)(defun XrefRename (oldname newname newpath) (if (and (findfile (strcat newpath newname ".dwg")) (ssget "X" (list '(0 . "INSERT") (cons 2 oldname)))) (progn ; rename the xref if it is found (command "rename" "b" oldname newname) ; change the path of the xref if it is found (command "-xref" "p" newname (strcat newpath newname) ) ) ));; XRP2004.lsp by Mark McDonough;; V3.3 Oct.15, 1999;; Updated as XRP2004.lsp by Mark McDonough, 4/20/04

;; Rev.1 05/03/99 updated to work for renamed XREFs and for AK2;; Rev.2 10/10/99 updated to work for Image paths;; Rev 3 04/20/04 updated to remove restrictions on long filenames;; Rev 4 12/14/06 updated to allow loading in running in AutoCAD 2007 (although it's not been tested in 2007);; Rev 5 12/06/08 updated by Jimmy Bergmark;; updated to allow running in AutoCAD 2010;; updated to be possible to run without user interaction

;; This lisp utility searches the block table, finds all Xrefs, then ;; repaths the Xrefs (if needed) with shorter "relative paths", thus ;; enhancing drawing file portability. The program strips unneeded;; drive letter references and superfluous upper level directory path;; information, using instead the old DOS CHDIR or "CD ..\.." syntax.

;; This program is supplied "AS IS". The author specifically disclaims ;; all warranties, expressed or implied, regarding the merchantability;; or fitness for any purpose. The author does not warrant that the;; XRP program will be free of errors and assumes no liability for ;; damages, direct or consequentail, which may result from the use of ;; XRP.

;***new error definition

Page 98: Lsp

;-----------------------(defun xrperr (msg) (if ce (setvar "cmdecho" ce)) (if v_r (setvar "visretain" v_r)) (if r_a (setvar "regenmode" r_a)) (setq *error* orgerr) ;reset previous error def. (princ "\nCommand cancelled!") (prompt "\n ") (princ))

;1 loop through block list, see if any regular xrefs, if so count them;---------------------------------------------------------------------(defun ifxref (/ flag) (setq cnt nil cnttot nil) (prompt "\n ") (princ "\n") ;(princ "\nXRP - XREF Relative Path Utility")

(if (null (setq blkdat (tblnext "block" T))) (princ "\n 0 Xrefs in this drawing.") ) (if (null (setq image_ss (ssget "X" '((0 . "IMAGE"))))) (princ "\n 0 Images in this drawing.") )

(if blkdat (progn (setq blkdat 1 cnt 0 flag 0) (while blkdat (if (= flag 0) (setq blkdat (tblnext "block" T)) (setq blkdat (tblnext "block")) ) (setq flag 1) (if blkdat (if (member (cdr (assoc 70 blkdat)) '(4 12 36 44)) (setq cnt (1+ cnt)))) ) ) ) (if (= cnt 0) (princ "\n 0 Xrefs in this drawing!") (if cnt (progn (princ (strcat "\n " (itoa cnt) " Xrefs in this drawing.")) ) ) ) (if image_ss (progn (setq flag 0) (princ (strcat "\n " (itoa (sslength image_ss)) " Images in this drawing (some might be duplicates).")) ) ) (if (>= cnt 1) (setq cnttot cnt)) (if image_ss (setq imagetot (sslength image_ss))) ;;(princ "\n Hit any key to continue.") ;;(grread) (princ))

;the following function is called by the "repath" function, used for the;summary message to indicate how many XREFs cannot be found (counts XREFs;that are still attached but can't be found because someone has moved or

Page 99: Lsp

;renamed the XREF drawings.;---------------------------------------------------------------------------(defun ifnf (/ flag) (setq blkdat 1 flag 0) (while blkdat (if (= flag 0) (setq blkdat (tblnext "block" T)) (setq blkdat (tblnext "block")) ) (setq flag 1) (if blkdat (if (member (cdr (assoc 70 blkdat)) '(4 12)) (setq cntnf (1+ cntnf))) ) ))

;Step through block list, if item is an xref, determine its position ;relative to base drawing and then repath it.;------------------------------------------------------------------------(defun repath () (setq blkdat 1 flag 0 xnam nil cnt 0 cnt6 0 cntnf 0 cntdr 0) (while blkdat (if (= flag 0) (setq blkdat (tblnext "block" T)) (setq blkdat (tblnext "block")) ) (setq flag 1 dpath (getvar "dwgprefix")) (if blkdat (if (member (cdr (assoc 70 blkdat)) '(4 12)) (progn (setq xpath (strcase (cdr (assoc 1 blkdat))) xnam (realxnam) xnam2 (strcase (cdr (assoc 2 blkdat))) ) (princ (strcat "\nXref " XNAM2 (pad) " **Not currently loaded, NOT REPATHED")) ) ) ) (if blkdat (if (member (cdr (assoc 70 blkdat)) '(36 44)) (progn (setq xpath (strcase (cdr (assoc 1 blkdat))) xnam (realxnam) xnam2 (strcase (cdr (assoc 2 blkdat)))

;;important revision ;;XNAM = real XREF dwg name, stripped from ASSOC 1 fullname, w/o ".dwg" ;; = external XREF name ;;XNAM2 = XREF name grabed from ASSOC 2 (always has no ".dwg" extension) ;; = internal XREF name (used for reporting to screen) ;;This revision accounts for renamed XREFs! ) (if (and (/= (substr xpath 1 1) (strcase (substr dpath 1 1))) (wcmatch xpath "*:*") ) (progn (princ (strcat "\nXref " XNAM2 (pad) " **On different drive, NOT REPATHED")) (setq cntdr (1+ cntdr)) ) (progn (trpath) (if (wcmatch xpath "*:*") (progn (compath)

(if (member (cdr (assoc 70 blkdat)) '(4 12))

Page 100: Lsp

(princ (strcat "\nXref " XNAM2 (pad) " **Not currently loaded, NOT REPATHED")) ) (cond ;***condition for lateral path xrefs... the majority ;--------------------------------------------------- ((and (> (strlen X1path) 0) (> (strlen d1path) 0)) (progn (repeat (cntsteps d1path) (setq x1path (strcat ".." (chr 92) x1path)) ) (setq x1path (strcase (strcat x1path (xnamful)) T)) (if (findfile x1path) (progn (command "xref" "path" xnam2 x1path) (princ (strcat "\nXref " XNAM2 (pad) " Repathed, lateral directory")) (setq cnt (1+ cnt)) ) (progn (princ (strcat "\nXref " XNAM2 (pad) " **NOT FOUND, NOT REPATHED")) (setq cntnf (1+ cntnf)) ) ) (setq xnam nil xnam2 nil) ) ) ;***condition for xrefs directly above main drawing ;-------------------------------------------------- ((and (= (strlen X1path) 0) (> (strlen d1path) 0)) (progn (repeat (cntsteps d1path) (setq x1path (strcat ".." (chr 92) x1path)) ) (setq x1path (strcase (strcat x1path (xnamful)) T)) (if (findfile x1path) (progn (command "xref" "path" xnam2 x1path) (princ (strcat "\nXref " XNAM2 (pad) " Repathed, above base directory")) (setq cnt (1+ cnt)) ) (progn (princ (strcat "\nXref " XNAM2 (pad) " **NOT FOUND, NOT REPATHED**")) (setq cntnf (1+ cntnf)) ) ) (setq xnam nil xnam2 nil) ) ) ;***condition for xrefs at same level as main drawing ;---------------------------------------------------- ((and (= (strlen X1path) 0) (= (strlen d1path) 0)) (progn ;(if (or (> (strlen xnam2) 8) (wcmatch xnam2 "* *")) ;(princ (strcat "\nXref " XNAM2 (pad) " **Long filename used, NOT REPATHED")) (progn (princ (strcat "\nXref " XNAM2 (pad) " Repathed, to base directory")) (command "xref" "path" xnam2 (xnamful)) (setq xnam nil xnam2 nil cnt (1+ cnt))

) ;) ) ) ;***condition for xrefs below main drawing level ;----------------------------------------------- ((and (> (strlen X1path) 0) (= (strlen d1path) 0))

Page 101: Lsp

(progn (setq x1path (strcat (homepath) (chr 92) x1path)) (setq x1path (strcase (strcat x1path (xnamful)) T)) (if (findfile x1path) (progn (command "xref" "path" xnam2 x1path) (princ (strcat "\nXref " XNAM2 (pad) " Repathed, below base directory")) (setq cnt (1+ cnt)) ) (progn (princ (strcat "\nXref " XNAM2 (pad) " **NOT FOUND, NOT REPATHED**")) (setq cntnf (1+ cntnf)) ) ) (setq xnam nil xnam2 nil) ) ) );end cond ) ;end progn (progn ;***else, no drive letter and path is already localized ;------------------------------------------------------ (princ (strcat "\nXref " XNAM2 (pad) " *does not need repathing*")) (setq cnt6 (1+ cnt6)) ) ) ;end if wcmatch xpath *.* )) );end progn ) ) ))

;***This function lines up Xref path messages... just for looks; Numeric value can be increased to accomodate longer names;--------------------------------------------------------------(defun pad (/ spacer) (setq spacer " ") (if (< (strlen XNAM2) 24) (repeat (- 24 (strlen XNAM2)) (setq spacer (strcat " " spacer))) ) (eval spacer))

;***Chops path off of DWGPREFIX, isolating name of single base subdirectory;--------------------------------------------------------------------------(defun homepath ( / cnt4) (setq rchr nil cnt4 (strlen dpath)) (if (= (substr dpath cnt4 1) "\\") (setq dpath (substr dpath 1 (- (strlen dpath) 1)) cnt4 (1- cnt4)) ) (while cnt4 (setq rchr (substr dpath cnt4 1)) (if (= rchr "\\") (setq dpath (strcat ".." (substr dpath cnt4)) cnt4 nil) (setq cnt4 (1- cnt4)) ) ) (eval dpath))

;***Gets real (external) XREF name by parsing ASSOC 1 of the ; full xref pathname, (w/o the ".dwg" extension) = XNAM2;-----------------------------------------------------------(defun realxnam ( / cnt5)

Page 102: Lsp

(setq rchr nil temp xpath cnt5 (strlen xpath)) (if (wcmatch temp "*\\*") (while cnt5 (setq rchr (substr temp cnt5 1)) (if (= rchr "\\") (setq temp (strcat (substr temp (1+ cnt5))) cnt5 nil) (setq cnt5 (1- cnt5)) ) ) ) (if (wcmatch (strcase temp) "*.DWG") (setq temp (substr temp 1 (- (strlen temp) 4))) ) (eval temp))

;***Trims xref path by removing xref drawing name; This function is a necessary test in R12 & R13;-------------------------------------------------(defun trpath () (if (wcmatch (strcase xpath) "*.DWG")(setq xpath (substr xpath 1 (- (strlen xpath) 4)))) (setq xpath (substr xpath 1 (- (strlen xpath) (strlen xnam)))))

;***Important function to determine xref's position relative to main dwg,; chops off path common to xref & base dwg, leaving unique path remainder.; The symbol "slashcnt" is used to backtrack the path, to ensure the common; path is a whole path that's truncated at a path delimitor, not at a ; similar named directory.; ----------------------------------------------------------------------(defun compath (/ cnt2) (setq d1path (strcase (substr dpath 3)) x1path (strcase (substr xpath 3)) cnt2 (strlen d1path) slashcnt 0 ) (while (/= cnt2 0) (if (= (substr d1path 1 1) (substr x1path 1 1)) (progn

(setq d1path (substr d1path 2) x1path (substr x1path 2)) (if (or (= (strlen d1path) 0) (= (strlen x1path) 0)) (setq cnt2 0) ) (if (wcmatch (substr x1path 1 1) "\\") (setq slashcnt 0) (setq slashcnt (1+ slashcnt)) ) ) (setq cnt2 0) ) ) ; (setq zzz x1path) (if (not (wcmatch (substr x1path 1 1) "\\")) (progn (setq x1path (strcat (substr xpath (- (strlen xpath) (+ slashcnt (- (strlen x1path)2))) (1- slashcnt)) x1path ) ) ) ))

Page 103: Lsp

;***Counts # of backslashes in remainder path, thus determining ; number of steps to apply DOS CD ..\ syntax; -----------------------------------------------------------(defun cntsteps (x / cnt3) (setq cnt3 0 slash 0 rchr nil) (while (/= cnt3 (strlen x)) (setq cnt3 (1+ cnt3) rchr (substr x cnt3 1)) (if (= rchr "\\") (setq slash (1+ slash))) ) (eval slash))

;***Ensures repathed xref has a ".dwg" extension, for consistency; -------------------------------------------------------------(defun xnamful () (if (not (wcmatch XNAM "*.dwg")) (strcase (strcat XNAM ".dwg") T) ))

;Step through IMAGE selection set, determine its position ;relative to base drawing and then repath it.;------------------------------------------------------------------------(defun image_repath () (setq flag 0 xnam nil imgcnt 0 imgok 0 imgnf 0 imgdr 0 #images 0 image_elist1 (entget (ssname image_ss 0)) image_elist2 (entget (cdr (assoc 340 image_elist1)))

image_elist3 (entget (cdr (assoc 330 image_elist2))) image_names (member (assoc 3 image_elist3) image_elist3)

dpath (getvar "dwgprefix") ) (while (/= imgcnt (length image_names));maybe should be less than < (progn (setq xnam2 (strcase (cdr (nth imgcnt image_names)))

xpath (strcase (cdr (assoc 1 (entget (cdr (nth (1+ imgcnt) image_names)))))) image_wholepath xpath istat (cdr (assoc 280 (entget (cdr (nth (1+ imgcnt) image_names)))))

) ;if istat = 0, not loaded ;XNAM gets set via the (img_path) function below

(img_path) ;delivers xnam, and modified xpath (if (= istat 0) (progn (princ (strcat "\nImage " XNAM2 (pad) " **Not currently loaded, NOT REPATHED")) (setq imgnf (1+ imgnf)) )

(progn ;eei (if (and (/= (substr xpath 1 1) (strcase (substr dpath 1 1))) (wcmatch xpath "*:*") ) (progn (princ (strcat "\nImage " XNAM2 (pad) " **On different drive, NOT REPATHED")) (setq imgdr (1+ imgdr))

(setq xnam nil xnam2 nil) )

(progn ;xyz(if (wcmatch xpath "*:*") (progn ;aai

(compath) (cond ;***condition for lateral path images...the majority

;---------------------------------------------------

Page 104: Lsp

((and (> (strlen X1path) 0) (> (strlen d1path) 0)) ;1st cond (progn (repeat (cntsteps d1path) (setq x1path (strcat ".." (chr 92) x1path)) ) (setq x1path (strcase (strcat x1path xnam))) (if (findfile x1path) (progn (princ (strcat "\nImage " XNAM2 (pad) " Repathed, lateral directory")) (command "_image" "path" XNAM2 x1path) (setq #images (1+ #images)) ) (progn (princ (strcat "\nImage " XNAM2 (pad) " **NOT FOUND, NOT REPATHED")) (setq imgnf (1+ imgnf)) ) ) (setq xnam nil xnam2 nil) ) ) ;end 1st COND ;***condition for images directly above main drawing ;--------------------------------------------------- ((and (= (strlen X1path) 0) (> (strlen d1path) 0));2nd cond (progn (repeat (cntsteps d1path) (setq x1path (strcat ".." (chr 92) x1path)) ) (setq x1path (strcase (strcat x1path xnam))) (if (findfile x1path) (progn (princ (strcat "\nImage " XNAM2 (pad) " Repathed, above base directory")) (command "_image" "path" xnam2 x1path) (setq #images (1+ #images)) ) (progn (princ (strcat "\nImage " XNAM2 (pad) " **NOT FOUND, NOT REPATHED**"))

(setq x xnam y xpath x2 xnam2) (setq imgnf (1+ imgnf)) ) ) (setq xnam nil xnam2 nil) ) );end 2nd cond ;***condition for images at same level as main drawing ;----------------------------------------------------- ((and (= (strlen X1path) 0) (= (strlen d1path) 0)) (progn ;(if (or (> (strlen xnam2) 8) (wcmatch xnam2 "* *")) ;(princ (strcat "\nImage " XNAM2 (pad) " **Long filename used, NOT REPATHED"))

(progn (princ (strcat "\nImage " XNAM2 (pad) " Repathed, to base directory")) (command "_image" "path" xnam2 xnam) (setq xnam nil xnam2 nil #images (1+ #images)) ) ;) ) ) ;***condition for images below main drawing level ;------------------------------------------------ ((and (> (strlen X1path) 0) (= (strlen d1path) 0)) (progn (setq x1path (strcat (homepath) (chr 92) x1path)) (setq x1path (strcase (strcat x1path xnam)))

Page 105: Lsp

(if (findfile x1path) (progn (princ (strcat "\nImage " XNAM2 (pad) " Repathed, below base directory"))

(command "_image" "path" xnam2 x1path) (setq #images (1+ #images)) ) (progn (princ (strcat "\nImage " XNAM2 (pad) " **NOT FOUND, NOT REPATHED**"))

(setq x xnam y xpath x2 xnam2) (setq imgnf (1+ imgnf)) ) ) (setq xnam nil xnam2 nil) ) )

) ;end Whole COND ) ;end progn aai

(progn ;***else, no drive letter and path is already localized ;------------------------------------------------------ (princ (strcat "\nImage " XNAM2 (pad) " *does not need repathing*")) (setq imgok (1+ imgok)) )

) ;end if wcmatch ) ;end progn xyz

;=======

);end if ) ;end progn eei ) ;end if istat (setq imgcnt (+ 2 imgcnt)) ) ;end progn ) ;end while) ;end defun

(defun img_path ( / imgcnt2) (setq rchr nil imgcnt2 (strlen xpath)) (if (= (substr xpath imgcnt2 1) "\\") (setq xpath (substr xpath 1 (- (strlen xpath) 1)) imgcnt2 (1- imgcnt2)) ) ;this will probably never be used (while (> imgcnt2 0) (setq rchr (substr xpath imgcnt2 1)) (if (= rchr "\\") (setq xnam (strcase (substr xpath (1+ imgcnt2)))

;img_pathnam (strcat (strcase (substr xpath 1 (1- imgcnt2))) "\\") xpath (strcase (substr xpath 1 imgcnt2)) imgcnt2 nil)

(setq imgcnt2 (1- imgcnt2)) ) ))

;Main xref repath function;-------------------------(defun xrp ( ) (setq sca "scale" orgerr *error* *error* xrperr v# "v3") (if (or (wcmatch (getvar "acadver") "*14*")(wcmatch (getvar "acadver") "*15*") (wcmatch (getvar "acadver") "*16*")(wcmatch (getvar "acadver") "*17*")

(wcmatch (getvar "acadver") "*18*")

Page 106: Lsp

) (progn (ifxref) (if (or image_ss (> cnt 0)) (progn

(setq ce (getvar "cmdecho")) (setvar "cmdecho" 0) (setq r_a (getvar "regenmode")) (setq v_r (getvar "visretain")) (setvar "regenmode" 0) (setvar "visretain" 1) (repath)

(if image_ss (image_repath)) (if (>= cnt 1) (command "regen")) (setvar "regenmode" r_a) ;;(textscr)

(xrp_report) (princ "\n ") (princ "\n ") ;;(princ "\nHit any key") ;;(grread) (princ "\r ") ;;(graphscr) (if v_r (setvar "visretain" v_r))

(if ce (setvar "cmdecho" ce)) (setq v_r nil ce nil cnt nil r_a nil flag nil rchr nil) ) ) ) (alert "This version of XRP is designed for AutoCAD R14 - 2010 only") ) (setq *error* orgerr orgerr nil) ;;(princ "\n Done with XRP - Xref Relative Path Utility v3.2 by MMcD") (princ))

(defun xrp_report () (if (>= cnt 1) ;***If xrefs exist, report status of repath operations (progn (prompt "\n ") (princ (strcat "\n" (if (< cnttot 10) " " "") (itoa cnttot) " Xrefs Total")) (princ (strcat "\n-" (if (< cnt 10) "-" "") "-------------")) (princ (strcat "\n" (if (< cnt 10) " " "") (itoa cnt) " Xrefs repathed")) (if (>= cnt6 1) (princ (strcat "\n" (if (< cnt6 10) " " "") (itoa cnt6) " Xrefs did not need repathing")) ) (ifnf) (if (>= cntdr 1) (princ (strcat "\n" (if (< cntdr 10) " " "") (itoa cntdr) " Xrefs on different drive, NOT REPATHED")) ) (if (>= cntnf 1) (princ (strcat "\n" (if (< cntnf 10) " " "") (itoa cntnf) " Xrefs could not be found, NOT REPATHED")) ) (prompt "\n ") (setq cnttot nil cnt6 nil cntdr nil cntnf nil) ) ) (if (> #images 0) (progn (prompt "\n ")

Page 107: Lsp

(princ (strcat "\n" (if (< (/(length image_names)2)10) " " "") (itoa (/(length image_names)2)) " Different Images Total")) (princ (strcat "\n-" (if (< #images 10) "-" "") "-----------------------")) (princ (strcat "\n" (if (< #images 10) " " "") (itoa #images) " Images repathed")) (if (>= imgok 1) (princ (strcat "\n" (if (< imgok 10) " " "") (itoa imgok) " Images did not need repathing")) ) (if (>= imgdr 1) (princ (strcat "\n" (if (< imgdr 10) " " "") (itoa imgdr) " Images on different drive, NOT REPATHED")) ) (if (>= imgnf 1) (princ (strcat "\n" (if (< imgnf 10) " " "") (itoa imgnf) " Images could not be found, NOT REPATHED")) ) (prompt "\n ") ;(setq image_ss nil #images nil imgok nil imgdr nil imgnf nil) ) ))

(defun c:xrp () (xrp))

; Remove the ; in the row below to have the function automatically run when the lisp is loaded.;(xrp)(princ);;; zoome.lsp;;;;;; Zoom extents in all viewports;;;;;; By Jimmy Bergmark;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved;;; Website: www.jtbworld.com;;; E-mail: [email protected];;; 2000-08-29;;; Tested on AutoCAD 2000

(defun c:zoome (/ oldcmdecho vplist curcvport nr vpss ms en x) (setq oldcmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (setq vplist (mapcar 'car (vports))) (setq curcvport (getvar "cvport")) (if (= (getvar "tilemode") 0) (progn (if (= (setq ms (getvar "cvport")) 1) (command "._mspace") ) (setq vpss (ssget "_x" (list '(-4 . "<AND") '(0 . "VIEWPORT") (cons 410 (getvar "ctab")) '(-4 . "<NOT") '(69 . 1) '(-4 . "NOT>") '(-4 . "AND>") ) ) ) (setq nr 0) (if vpss ; in case there are no viewports (repeat (sslength vpss) (setq en (entget (ssname vpss nr)))

Page 108: Lsp

(if (and (= 0 (logand 1 (cdr (assoc 90 en)))) ; not perspective (< 0 (cdr (assoc 68 en))) ; on and active (/= 16384 (logand 16384 (cdr (assoc 90 en)))) ; not locked ) (progn (setvar "cvport" (cdr (assoc 69 en))) (command "._zoom" "_e") ) ) (setq nr (+ 1 nr)) ) ) (if (= ms 1) (command "._pspace")) ) (foreach x vplist (setvar "cvport" x) (command "._zoom" "_e") ) ) (setq vpss nil) (setvar "cvport" curcvport) (setvar "cmdecho" oldcmdecho) (princ))