Thanks for that BB.
Originally I tried to test if any images existed and if there was an image layer. Then make sure the image was on the image layer and Image layer "Locked". If there isn't an image or an Image Layer, do nothing. I just couldn't seem to get it to work.
I still want to do that without having the user select anything. The routine should run complete without any user input except entering the command to run the routine.
Here's what I have with your code incorporated.
Code:
(defun C:ERBDR ( / rev1 REV2 REF1 BD1 BD2 BD3 BD4 BR1 REF1 TB1 TB2 TB3 TB4 BR1 TB5 TR1)
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(defun *error* (msg)
(if ss
(vla-delete ss)
)
(if acDoc
(progn
(vla-endundomark acDoc)
(vla-regen acDoc acallviewports)
)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if (ssget "_:L" '((0 . "IMAGE") (8 . "~Image")));;Find any images. Create and set "image" Layer. User prompted to select .CAL file
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
;; get or create layer
(setq oLayer
(vla-add (vla-get-layers acDoc) (setq layerName "Image"))
)
;; set image layer
(vlax-for x (setq ss (vla-get-activeselectionset acDoc))
(vla-put-layer x layerName)
)
;; freeze image layer, set clayer
(vla-put-freeze oLayer :vlax-true)
(setvar 'clayer "Line1")
)
)
(*error* nil)
(setq rev1 (ssget "_c" '(33.375 21.4375) '(31.875 5.3125))) '((8 . "Line3,Line4,Line5"))
(setq rev2 (ssget "_w" '(31.4375 21.4375) '(31.75 5.3125))) '((8 . "Line3,Line4,Line5"))
(setq ref1 (ssget "_c" '(28.9375 4.9375) '(33.5625 3.3125))) '((8 . "Line3,Line4,Line5"))
(command "move" rev1 rev2 ref1 "" "31.75,21.4375" "38.75,21.4375");;move reference drawing #'s and revision text/lines out of old border
(setq bd1
(ssget "_c" '(0 0) '(1.5 23.1875))) '((8 . "Line0,Line3,Line4,Line5"));;erase White Border and left magenta line, text and triangles.
(command "erase" bd1 "")
(setq bd2
(ssget "_c" '(0 0) '(35 0.25))) '((8 . "Line0,Line3,Line4,Line5"));;erase Bottom magenta line, text and triangles.
(command "erase" bd2 "")
(setq bd3
(ssget "W" '(35 0.25) '(33.625 22.5))) '((8 . "Line0,Line3,Line4,Line5"));;erase Right magenta line, text and triangles.
(command "_layer" "Freeze" "Text0,Text1,Text5" "")
(command "erase" bd3 "")
(setq bd4 (ssget "_c" '(33.625 22.5) '(1.5 21.75))) '((8 . "Line0,Line3,Line4,Line5"));;erase Top magenta line, text and triangles.
(setq br1 (ssget "_c" '(32.125 21.625) '(33.375 21.5625)))
(command "erase" bd4 br1 "")
(setq tb1
(ssget "_c" '(28.8750 0.25) '(28.375 5.0)));;erase Revision #s/REV & Lines
(command "erase" tb1 "")
(setq tb2
(ssget "_c" '(28.875 1.6875) '(29.0625 0.25)));;erase Initial Text, Scale
(command "erase" tb2 "")
(setq tb3
(ssget "_W" '(29.5 1.3125) '(31.875 0.625)));;erase Scale, Approved, 21D-
(command "erase" tb3 "")
(setq tb4 (ssget "_c" '(33 0.625) '(32.0 0.625)))
(setq tr1 (ssget "_c" '(31.875 5.125) '(30.125 5.1875)));;Erase horizontal line above Sht number and Subject code
(command "erase" tb4 tr1 "")
(setq tb5
(ssget "_c" '(33.5625 2.9375) '(33.5625 1.6875)))
(command "-layer" "thaw" "Image,Text0,Text1,Text5,Line5" "")
(command "_insert" "21_CTL_SDH_ATT.DWG" "0,0" "1" "1" "0" "");;Insert new Attributed TB
(command "Explode" "Last" "")
(command "move" ref1 rev1 rev2 "" "38.75,21.4375" "31.75,21.4375" "");;move Reference drawing #'s and Revision text/lines back
(setvar "cmdecho" 1)
(setvar "osmode" 1)
(princ)
)