Setvar USERR1 Not Working

Setvar USERR1 Not Working

Abby_Baratta
Enthusiast Enthusiast
788 Views
6 Replies
Message 1 of 7

Setvar USERR1 Not Working

Abby_Baratta
Enthusiast
Enthusiast

Hello!

 

I've recently been working on updating some code from about 20 years ago and I ran into an issue with the AutoLISP routines and using the setvar command.

 

The program that I'm working with begins with AutoCAD's VBA enabler, loads and calls the AutoLISP routines to make my drawing, and then returns to the VBA enabler to finish out the program. I'm trying to edit the way that the program prints to PDF, so I wanted to grab the drawing scale that was set in my AutoLISP routine and create a variable to store it in the VBA script.

 

I figured that the easiest way to do this was to use the USERR1 and USERR2 system variables, as those are easily callable from VBA. When I wrote out the lines of code to set the variables, however, I noticed that they never actually changed the value from its default. I tried again, this time using USERS1 and the same thing happened.

 

The part I found odd was that I was able to set these variables directly from the VBA script and it worked fine. 

 

The portion of AutoLISP that I wrote is:

;grab the GSCALE value for each drawing
(setvar "USERS1" "COMPLETE")
(if (= DWGTYP "SETTING")(setvar "USERR1" GSCALE))
(if (= DWGTYP "CORE")(setvar "USERR2" GSCALE))

With the GSCALE variable being a scaling factor determined earlier on in the code - its data type is a real.

 

And the VBA code doing the same thing is:

ThisDrawing.SendCommand "USERS1 COMPLETE" & vbCr
ThisDrawing.SendCommand "USERR1 12.5" & vbCr
ThisDrawing.SendCommand "USERR2 13.0" & vbCr

And this one sets these system variables just fine. I spent a while this morning looking online to see if I could find some answers, but I haven't found anything that said that this shouldn't work for both of my cases.

 

Does anyone happen to know why this might be happening? 

0 Likes
789 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

I see nothing about the DWGTYP variable.  Has that been set prior to this?  Might it ever be other than one of those two possibilities?  If it's either non-existent or something different, the USERRx variable(s) would not be set.  And even if it is one of those values, only one of the USERRx variables would be set.  Your VBA version does not look like it's really "doing the same thing," since it doesn't appear to be dependent on a test for anything, and because it appears to use fixed values, not a variable, and because the values are different, not the same one but assigned to only one of two USERRx variables.  [But I'm not versed in VBA, so I may be wrong.]

Kent Cooper, AIA
0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor
(setvar 'users1 "COMPLETE")
(setvar 'userr1 12.5)
(setvar 'userr2 13)
(mapcar 'set '(a b c) (mapcar '(lambda (x)(getvar x)) '(users1 userr1 userr2)))
(list a b c)
>>("COMPLETE" 12.5 13.0)

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 7

Abby_Baratta
Enthusiast
Enthusiast

After staring at this for hours, I've realized my silly mistake only after posting on here.

 

I completely forgot that the USERRx and USERSx system variables are stored in the drawing itself and will reset back to their default values when a new drawing is loaded. In my AutoLISP routine, it is drawing and saving three different drawings. To get around having to reset system variables stored in the drawing each time, it was written to 'Save As' the name I want, then delete everything and make another drawing. 

 

When I bounce back to VBA, the script opens up a new drawing, which means that all my variables store in the drawing reset. I was trying to grab these values AFTER I opened a new drawing, which would be why it appeared that it didn't work.

 

I really appreciate your feedback - sorry for the essentially unneeded post!

 

0 Likes
Message 5 of 7

scot-65
Advisor
Advisor

@Abby_Baratta,

 

USERS1 is not stored in the drawing. R and I are.

"S" stands for String and this variable can only accept a string (it will not convert a list, integer, real, etc. into a string - you have to do this yourself).

 

I would suggest using the dictionary vlax-ldata-put instead as these USERx variables WERE

originally designed for user variables displayed in diesel expressions (POP and MODEMACRO).


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

"I'm trying to edit the way that the program prints to PDF" Do you need a Lisp and VBa COMBO why not do it all in lisp, we have been plotting multi pdfs from one menu button click for years.

0 Likes