Check System Variable Value

Check System Variable Value

C.Utzinger
Collaborator Collaborator
2,731 Views
10 Replies
Message 1 of 11

Check System Variable Value

C.Utzinger
Collaborator
Collaborator

HI

 

I have a simple LSP for saving System Variables to registry and apply them.

 

There is a code part to test if the varible exists:

 

(if (and (/= spivar1 "")(not (getvar spivar1)))(alert (strcat "Systemvariable < " spivar1 " > existiert nicht!")))

 

but i want also test if the given value is good or not.

 

I tried something like:

 

(if (and (/= spiwer1 "")(not (setvar spivar1 (atoi spiwer1))))(alert (strcat "Systemvariablenwert < " spiwer1 " > nicht möglich!")))

 

but this don't work.

 

Any idea?

 

 

0 Likes
Accepted solutions (1)
2,732 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

I'm not familiar with those as System Variables -- they're not in Acad2017 here.  But if they are in the your-language version or an overlay program, and they're really System Variables and not variables you have created, then I see two things:

 

(not (getvar spivar1))

 

would always return nil, because I don't think System Variables ever do not exist -- don't they always have an initial or default value?

 

And this:

(/= spivar1 "")

 

should be this:

 

(/= (getvar spivar1) "")

 

and similarly elsewhere.

 

But if they're really variables you make yourself, then (setq) should be used instead of (setvar), and just the variable name instead of putting it in (getvar) functions.

Kent Cooper, AIA
0 Likes
Message 3 of 11

C.Utzinger
Collaborator
Collaborator

HI

 

Sorry I think there is a missunderstanding...

 

The hole code attached with the Dialog BOX would clear that.

 

But i just change that for better understanding...

 

(if (and (/= spiwer1 "")(not (setvar 'ORTHOMODE (atoi spiwer1))))(alert (strcat "Systemvariablenwert < " spiwer1 " > nicht möglich!")))

 

What i'm looking for is an alert message when the user introduce a wrong number for the Systemvariable.

For example <5> for the ORTHOMODE, this valuer does not exist, so (alert "this value does not exist for OTRHOMODE")

0 Likes
Message 4 of 11

ambrosl
Autodesk
Autodesk
Accepted solution

You can use the VL-CATCH-ALL-APPLY, VL-CATCH-ALL-ERROR-P, and VL-CATCH-ALL-ERROR-MESSAGE functions to catch and test for an error.

 

Here is an example that might help, if the value passed to the ORTHOMODE system variable isn't valid the error returned by SETVAR is caught and the error message is displayed in an alert:

(setq testVal (vl-catch-all-apply 'setvar (list "orthomode" 5)))
(if (vl-catch-all-error-p testVal)
  (alert (vl-catch-all-error-message testVal))
)



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 5 of 11

C.Utzinger
Collaborator
Collaborator

That helps

 

Thank you very much!

 

Kind regards

0 Likes
Message 6 of 11

C.Utzinger
Collaborator
Collaborator

HI

 

I have still a little problem. Why does it work with numbers and not with words?

 

HPQUICKPREVIEW has a value ein/aus (on/off).

 

(vl-catch-all-apply 'setvar (list "HPQUICKPREVIEW" "ein"))

 

Or i'm doing something wrong :)...

 

 

Best regards

0 Likes
Message 7 of 11

C.Utzinger
Collaborator
Collaborator

Very strange!

 

With "EIN" it doesn't work, but with "AUS" it does.

 

Smiley Frustrated

0 Likes
Message 8 of 11

ambrosl
Autodesk
Autodesk

"EIN" didn't work for me, but I wonder if it is based on the language pack that is installed and being used though that shouldn't affect this situation.

 

Command: (setq testVal (vl-catch-all-apply 'setvar (list "HPQUICKPREVIEW" "ein")))
#<%catch-all-apply-error%>
Command: (vl-catch-all-error-message testVal)
"AutoCAD variable setting rejected: \"HPQUICKPREVIEW\" \"ein\""

 

Command: (setq testVal (vl-catch-all-apply 'setvar (list "HPQUICKPREVIEW" "aus")))
#<%catch-all-apply-error%>
Command: (vl-catch-all-error-message testVal)
"AutoCAD variable setting rejected: \"HPQUICKPREVIEW\" \"aus\""

 

I would expect all strings to fail as the system variable is of the SWITCH type.  While HPQUICKPREVIEW at the Command prompt will accept ON, via the SETVAR function that same value is rejected and requires the use of 0 or 1.

 

Command: HPQUICKPREVIEW
Enter new value for HPQUICKPREVIEW <ON>: on

Command: (setvar "hpquickpreview" "on")
; error: AutoCAD variable setting rejected: "hpquickpreview" "on"

 

Command: HPQUICKPREVIEW
Enter new value for HPQUICKPREVIEW <ON>: 1
Command: (setvar "HPQUICKPREVIEW" 1)
1



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 9 of 11

C.Utzinger
Collaborator
Collaborator

I just fixed it with this code:

 

(setq spiwer1 (cond ((= spiwer1 "EIN") "1")((= spiwer1 "AUS") "0")(T spiwer1)))

 

Now it works ;)...

 

Thank you and best regards

0 Likes
Message 10 of 11

ambrosl
Autodesk
Autodesk

@C.Utzinger wrote:

I just fixed it with this code:

 

(setq spiwer1 (cond ((= spiwer1 "EIN") "1")((= spiwer1 "AUS") "0")(T spiwer1)))

 

Now it works ;)...

 

Thank you and best regards


If you can ensure spiwer1 will always be EIN and AUS, then you shouldn't have any problems.  If the values might be lowercase or mixed-case, you might want to use the STRCASE to ensure the value is always uppercase only.

 

(= (strcase spiwer1) "EIN")



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 11 of 11

C.Utzinger
Collaborator
Collaborator

Already done ;)... 

 

Thank you

0 Likes