Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
Simon_Weel
Posts: 84
Registered: ‎12-11-2008
Message 1 of 8 (485 Views)
Accepted Solution

How to check if a System Variable is readonly?

485 Views, 7 Replies
11-22-2012 04:24 AM

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

 

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

Valued Contributor
dicra
Posts: 94
Registered: ‎02-20-2011
Message 2 of 8 (475 Views)

Re: How to check if a System Variable is readonly?

11-22-2012 05:21 AM in reply to: Simon_Weel

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

*Expert Elite*
hmsilva
Posts: 3,374
Registered: ‎12-17-2004
Message 3 of 8 (443 Views)

Re: How to check if a System Variable is readonly?

11-22-2012 12:36 PM in reply to: Simon_Weel

 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

 

 

 

 

Distinguished Mentor
Moshe-A
Posts: 829
Registered: ‎09-14-2003
Message 4 of 8 (439 Views)

Re: How to check if a System Variable is readonly?

11-22-2012 01:39 PM in reply to: hmsilva

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

  

 

 

 

 

 

*Expert Elite*
hmsilva
Posts: 3,374
Registered: ‎12-17-2004
Message 5 of 8 (435 Views)

Re: How to check if a System Variable is readonly?

11-22-2012 01:59 PM in reply to: Moshe-A

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

Distinguished Mentor
Moshe-A
Posts: 829
Registered: ‎09-14-2003
Message 6 of 8 (409 Views)

Re: How to check if a System Variable is readonly?

11-22-2012 10:12 PM in reply to: hmsilva

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

 

*Expert Elite*
hmsilva
Posts: 3,374
Registered: ‎12-17-2004
Message 7 of 8 (394 Views)

Re: How to check if a System Variable is readonly?

11-23-2012 01:01 AM in reply to: Moshe-A

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

Valued Contributor
Simon_Weel
Posts: 84
Registered: ‎12-11-2008
Message 8 of 8 (353 Views)

Re: How to check if a System Variable is readonly?

11-26-2012 02:00 AM in reply to: Simon_Weel

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

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.