i have a routine where I place a text bubble and intend on putting it on a specific layer. I have a user or two that, unfortunately, turn off this layer. How do i get it to check if it is frozen and/or locked/off while giving a chance to substitue another available layer if i do not want to unfreez/unlock the layer i want?
; Insert Detail Bubble and associated text
(defun C:Detbuble ( / x attrib auto# ang flag ortho c-styl spc scale *error* layr)
(defun *error* (msg)
(command)
(if LAYR (setvar "CLAYER" LAYR))
(if (>= (getvar "UNDOCTL") 😎 (command "UNDO" "E"))
(redraw)
(princ (strcat "\nError: " msg " "))
(princ)
)
(setq LAYR (getvar "CLAYER"))
(if (= (caar (vports)) 1)
(setq SCALE 1.0)
(if (= (strcase (getvar "CPROFILE")) "METRIC")
(setq SCALE (* SCL 0.0254))
(setq SCALE SCL)
)
)
(prompt "\nPlace Detail bubble ")
(setq RAD (* 0.375 SCALE)
SPC (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))
ANG (getvar "SNAPANG")
IP1 (bubble)
)
(if (and (boundp 'IP1)
(= (type IP1) 'LIST)
)
(progn
(if (> (getvar "UNDOCTL") 4) (command "UNDO" "BE"))
(if (tblsearch "LAYER" "DIMS") (setvar "CLAYER" "DIMS"))
(if (/= (strcase (getvar "CPROFILE")) "METRIC")
(command "INSERT" "DETBUBBLE" IP1 SCALE "" (rad_deg (getvar "SNAPANG")) "" "")
(command "INSERT" "DETBUBBLE" IP1 (* SCALE 0.03937) "" (rad_deg (getvar "SNAPANG")) "" "")
)
)
)
(setvar "CLAYER" LAYR)
(if (>= (getvar "UNDOCTL") 😎 (command "UNDO" "E"))
(princ)
)
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@JamesCarr1956 wrote:
i have a routine where I place a text bubble and intend on putting it on a specific layer. I have a user or two that, unfortunately, turn off this layer. How do i get it to check if it is frozen and/or locked/off while giving a chance to substitue another available layer if i do not want to unfreez/unlock the layer i want?
....
(if (tblsearch "LAYER" "DIMS") (setvar "CLAYER" "DIMS"))
....
It looks like that line is the crux of the matter, and that if that Layer doesn't exist, it will simply use the current Layer. Whether it's locked really has no relevance -- you can Insert something [or otherwise draw things] on a locked Layer. But whether it's off or frozen does, of course. Try substituting the above line with something like this [untested]:
(if (setq layinfo (tblsearch "layer" "DIMS"))
; [returns nil if it doesn't exist, so it will stick with the current Layer as before]
(if ; then argument for outer (if)
(or ; DIMS Layer is either turned off, frozen, or both
(minusp (cdr (assoc 62 layinfo))); turned off [color value is negative]
(= (logand (cdr (assoc 70 layinfo)) 1) 1); frozen
); or
(progn ; then for inner (if)
(initget "Yes No")
(if (= (getkword "\nThaw/turn On and use DIMS Layer [Yes/No]? <Yes>: ") "No")
(cond ; then -- User typed N or No
((= (setq lay (getstring "\nLayer to use instead <current>: ")) ""); User hit Enter for current default
(prompt "\nUsing current Layer.")
); default condition
((setvar 'clayer lay)); other-than-Enter User input of Layer name
); cond
(command ; else [User typed Y or Yes]
"_.layer" "_thaw" "DIMS" "_make" "DIMS" "" ; Make option will turn it on & set it current
"_.regen" ; may be needed if it was frozen, if you want other such marks visible
); command
); if
); progn
(setvar 'clayer "DIMS"); else for inner (if) [it's neither off nor frozen -- use it]
); if [inner]
); if [outer]
It could also be made to:
1. Also offer a choice of what Layer to use if the DIMS Layer doesn't exist [an 'else' argument for the outer (if) function], and/or whether to make it, rather than always using the current Layer;
2. Also offer a choice of Layer even if DIMS does exist and is thawed/on;
3. Check whether a User-typed alternative Layer name exists, and even ask again if it doesn't.