Author Topic: What is wrong?  (Read 1941 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
What is wrong?
« on: January 26, 2005, 12:04:50 PM »
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:

Code: [Select]

;;; ------------ 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
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

SMadsen

  • Guest
What is wrong?
« Reply #1 on: January 26, 2005, 12:12:02 PM »
My guess is that SETVAR speeds past the COMMAND functions so that the layer is set prematurely. Try inserting a loop like (while (> (getvar "CMDACTIVE") 0)) before SETVAR.