I have a piece of code that inserts blocks. I set a certian layer before insert and insert the blocks the reset the layer but when I check the layers of the object I see that the last one inserted is on the old layer why?
If I take out the call to return to the old layer everthing is fine except that I am on the wrong layer now. Here is a spot of code:
;;; ------------ Insert View Name Callout into Drawing
(defun INSERT_DETAIL_CALLOUT ( / ArrowDirectory DetailArrow DetailName Directory InsPoint LyrName OldAttDia OldClayer OldOsmode)
;; Set enviroment variables
(setq OldClayer (getvar "CLAYER"))
(setq OldOsmode (getvar "OSMODE"))
(setq OldAttDia (getvar "ATTDIA"))
;; Check to see if the Layer is already there
(setq LyrName "G-VIEW-NAME")
(if (not (tblsearch "LAYER" LyrName))
(CREATE_LAYER)
)
;; Check to see if the detail is in the search path
(setq DetailName "DetailCallout.dwg")
(setq DetailArrow "DetailCalloutArrow.dwg")
(if (not (findfile DetailName))
(progn
(setq Directory (vl-filename-directory (findfile(getfiled "Locating Detail Callout" "DetailCallout" "dwg" 8))))
(setq DetailName (strcat Directory "\\" DetailName))
)
)
(if (not (findfile DetailArrow))
(progn
(setq ArrowDirectory (vl-filename-directory (findfile(getfiled "Locating Detail Callout Arrow" "DetailCalloutArrow" "dwg" 8))))
(setq DetailArrow (strcat ArrowDirectory "\\" DetailArrow))
)
)
;; Set layer to insert layer and insert block
(setvar "CLAYER" "G-VIEW-NAME")
(setq InsPoint (getpoint "Select Insertion Point:"))
(setvar "ATTDIA" 1)
(command "-insert" DetailName InsPoint "" "" "")
(command "-insert" DetailArrow InsPoint "" "")
;; Reset sys variables
;(setvar "CLAYER" OldClayer)
(setvar "ATTDIA" OldAttDia)
(princ)
)
I have run into this before but cannot remember how to get around it.
Thanks