Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

check if system variable is available for lisp

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
RJanw01
1156 Views, 4 Replies

check if system variable is available for lisp

We have a few different releases of autocad for the daily users and the once a week users. Adding system variable settings to the lisp causes errors on previous releases and quits the loading. How can I check if a system variable is present, then set it if it is or skip over it if it is not?

 

ex. mtextcolum variable available in acad 2013 but not available in 2009.

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: RJanw01


@RJanw01 wrote:

.... How can I check if a system variable is present, then set it if it is or skip over it if it is not?

 

ex. mtextcolum variable available in acad 2013 but not available in 2009.


If there is no such System Variable in a given release, asking for a value for it will return nil:

 

(if (getvar 'mtextcolum)

  (setvar 'mtextcolum WhatYouWill); 'then'

)

 

No 'else' argument -- do nothing if that System Variable does not exist.

Kent Cooper, AIA
Message 3 of 5
stevor
in reply to: RJanw01

; system vars of like names (DeFun c:svq () (setq svq_qs (if svq_qs svq_qs "") ; svq_qs (get_s svq_qs "\n Setvar ? str") svq_qs (getstring "\n Setvar Str? ") ) (command "setvar" "?" (strcat "*" svq_qs "*" )) (princ) )
S
Message 4 of 5
Kent1Cooper
in reply to: stevor


@stevor wrote:
; system vars of like names (DeFun c:svq () (setq svq_qs (if svq_qs svq_qs "") ; svq_qs (get_s svq_qs "\n Setvar ? str") svq_qs (getstring "\n Setvar Str? ") ) (command "setvar" "?" (strcat "*" svq_qs "*" )) (princ) )

No (get_s) function defined.  And without line breaks, it's hard to tell what's going on -- how much of what follows that semicolon is commented out, and where does a new line begin?

 

If I understand the intent, I think the prompt "\n Setvar Str? " would be better as "\nSystem Variable substring? ".  A pet peeve of mine [a lot of people use the word this way]: a System Variable is not a "setvar."  If you're going to use a function name as the noun for what it relates to, it would make more sense most of the time to call a System Variable a "getvar," particularly in this case since apparently getting the System Variable value(s) is the purpose of the routine.

Kent Cooper, AIA
Message 5 of 5
lgabriel
in reply to: RJanw01

The Autolisp function GETVAR returns nil if the argument passed is not an AutoCAD system variable.

 

Line of Autolisp code where "nnn" is the name of the system variable and value is the desired setting for the system variable

 

if (/= (getvar "xxx") nil)(setvar "nnn" value))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost