Set value to variable, VL ...

Set value to variable, VL ...

carlos_m_gil_p
Advocate Advocate
1,043 Views
5 Replies
Message 1 of 6

Set value to variable, VL ...

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.

I am trying to set a variable with VL functions, but it gives me an error.

; error: Automation Error. Error setting system variable

Why does this happen and how can I correct it?

 

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-variant-value (vla-GetVariable doc "3dosmode"))
(vla-SetVariable doc "3dosmode" 3)

 

Thanks a lot.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Accepted solutions (1)
1,044 Views
5 Replies
Replies (5)
Message 2 of 6

john.uhden
Mentor
Mentor

Why struggle unnecessarily?  Just use getvar and setvar.

John F. Uhden

0 Likes
Message 3 of 6

hak_vz
Advisor
Advisor
Accepted solution

If you strictly use visual lisp than  use this.

Visual lisp functions need to be feed with adequate data type i.e. variants. Google or lookup in help vlax-make-variant

 

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq old_3dosmode (vlax-variant-value (vla-GetVariable doc "3dosmode")))
(setq new_val (vlax-make-variant 3 vlax-vbInteger))

(vla-SetVariable doc "3dosmode" new_val)

Or simply

(setvar '3dosmode 3)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 6

carlos_m_gil_p
Advocate
Advocate

Hi thanks.

I will be more pending.
I will always forecast the data to avoid errors.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 5 of 6

carlos_m_gil_p
Advocate
Advocate

Hi @john.uhden , I'm just trying to get a better understanding of these functions and how they work.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 6 of 6

john.uhden
Mentor
Mentor

Learning is a great thing.  Attaboy!

John F. Uhden

0 Likes