How do I check, with LISP, if a System Variable is read only? In particular ANNOTATIVEDWG. This one is read/write when there are no annotative objects in a drawing, but read-only if there are.
Simon
Solved! Go to Solution.
Mybe this will help you:
When you try to change variable ,which is not read-only, you will get this:
Command: (setq catchit (vl-catch-all-apply 'setvar '(cmdecho 1)))
1
But if you can't change variable (for example variable "date"), you will have this:
Command: (setq catchit (vl-catch-all-apply 'setvar '(date 1)))
#<%catch-all-apply-error%>
Now you can explore this error.
-To see comlete error mesage:
Command: (vl-catch-all-error-message catchit)
"AutoCAD variable setting rejected: DATE 1"
-Or you can just gert TRUE if there is an error, or NIL if there is'nt any error mesage:
Command: (vl-catch-all-error-p catchit)
T
Simon_Weel wrote:
How do I check, with LISP, if a System Variable is read only? In particular ANNOTATIVEDWG. This one is read/write when there are no annotative objects in a drawing, but read-only if there are.
Simon,
usually is easy determine if a variable is readonly, You can use dicra's method, or instead of setvar function, which immediately gives an error, use the commannd function:
(defun c:test () (if(command "viewmode" 1) (Prompt "\n The System Variable ANNOTATIVEDWG is NOT Read Only!!! ") (Prompt "\n The System Variable ANNOTATIVEDWG IS Read Only!!! ") );if (princ) )
but in relation to the system variable ANNOTATIVEDWG, and i dont know why, and it is very strange that happens... if you use
(setvar "ANNOTATIVEDWG" 1) or (command "ANNOTATIVEDWG" 1), to one or zero, in a dwg where the variable is readonly,
it changes the AutoCAD system variable ANNOTATIVEDWG to the value you set, and should not be possible, because it is
Read Only...
So I had to work around this situation and came to this code:
(defun c:test1 (/ an lpr) (setq an (getvar "annotativedwg")); gets annotativedwg value (command "annotativedwg" (abs (- an 1))); sets the annotativedwg to the inverse value (setq lpr (getvar "lastprompt")); gets the last prompt (if (= (vl-string-left-trim "Command: " lpr) (rtos (abs (- an 1)))); trims the string to gets only the prompt and see if it is equal to the value we set (progn; if yes (setq an (getvar "annotativedwg")); gets yhe new annotativedwg value (setvar "annotativedwg" (abs (- an 1))); sets back the old value (Prompt "\n The System Variable ANNOTATIVEDWG IS Read Only!!! "); prompts the result ); progn (progn; if not (setq an (getvar "annotativedwg")); gets yhe new annotativedwg value (setvar "annotativedwg" (abs (- an 1))); sets back the old value (Prompt "\n The System Variable ANNOTATIVEDWG is NOT Read Only!!! "); prompts the result ); progn ); if (princ) )
hope that helps
Henrique
@hmsilva wrote:
but in relation to the system variable ANNOTATIVEDWG, and i dont know why, and it is very strange that happens... if you use
(setvar "ANNOTATIVEDWG" 1) or (command "ANNOTATIVEDWG" 1), to one or zero, in a dwg where the variable is readonly,
it changes the AutoCAD system variable ANNOTATIVEDWG to the value you set, and should not be possible, because it is
Read Only...
Hi,
this is not true...if ANNOTATIVEDWG is read only you can not set it, although the (setvar) function looks like
it runs normal (does not return an error) it doesn't change the variable.
(if (command "annotativedwg" 1) .... )
no need to check the return value from (command) function cause it always returns nil.
Moshe
Moshe-A wrote:
this is not true...if ANNOTATIVEDWG is read only you can not set it...
Command: ANNOTATIVEDWG
ANNOTATIVEDWG = 0 (read only)
Command: (setvar "ANNOTATIVEDWG" 1)
1
Command: ANNOTATIVEDWG
ANNOTATIVEDWG = 1 (read only)
notice that was changed to 1...should not, but it was changed.
Henrique
Henrique,
Yes you are right, but it depends on which version you have
in R2008/2009 it works as it shoud (it won't let to change).
to me it looks like a bug on this issue from R2010 and up.
Moshe
Moshe,
thanks for sharing this information, I only have currently installed in our machines
R2010 and up, so, I have no way to test for previous versions.
Cheers
Henrique
Thanks for all the answers! I can now establish if the variable is read/write or read-only.
My idea was to use this variable to determine if a drawing is annotative or not. As soon as a drawing holds an annotative obect, this variable becomes read-only wether it's 0 or 1, so for my purpose it's pretty useless... I doubt if it has any use at all??
Simon
Can't find what you're looking for? Ask the community or share your knowledge.