.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setsystemvariable USERS1-5

17 REPLIES 17
Reply
Message 1 of 18
bowa
1855 Views, 17 Replies

Setsystemvariable USERS1-5

Following a previous post about system variables, I can't seem to set and get the USERS variables.

With the imports statement:
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application

I am trying to:
AcadApp.SetSystemVariable("USERS5", "bwa")
but it doesn't seem to be working.

AcadApp.SetSystemVariable("USERI5", 5)
works without issue so I'm guessing that I'm not formating the string properly.

Can anyone provide assistance?

Thanks.
17 REPLIES 17
Message 2 of 18
NathTay
in reply to: bowa

This line works for me.

Application.SetSystemVariable("USERS2", strLevel)


Regards - Nathan
Message 3 of 18
bowa
in reply to: bowa

Nathan,
Thanks for the reply but it's still not working for me. As I pointed out I can set the USERI or USERR variables but the USERS group is really stumping me.

Application.SetSystemVariable("USERI5", 45)
Application.SetSystemVariable("USERR5", 54.0)
will work, but
Application.SetSystemVariable("USERS1", "temp")
will not work.

Thanks,
Bernie
Message 4 of 18
Anonymous
in reply to: bowa

Hi.

Try using an object like this :

object value = 45;
Application.SetSystemVariable("USERS1", value);

Regards
Peter

wrote in message news:5623395@discussion.autodesk.com...
Nathan,
Thanks for the reply but it's still not working for me. As I pointed out I
can set the USERI or USERR variables but the USERS group is really stumping
me.

Application.SetSystemVariable("USERI5", 45)
Application.SetSystemVariable("USERR5", 54.0)
will work, but
Application.SetSystemVariable("USERS1", "temp")
will not work.

Thanks,
Bernie
Message 5 of 18
bowa
in reply to: bowa

Peter, thanks for the response...

I'm doing this in VB and have tried both

Application.SetSystemVariable("USERS1", CObj("temp"))
Application.SetSystemVariable("USERS1", CType("temp", Object))

Neither form will work for me. Also, neither the USERI or USERR variables require the value to be converted to an object.

Obviously, I'm a newbie here. Am I missing something really obvious in my Imports or something?
Message 6 of 18
Anonymous
in reply to: bowa

It works for me in C# if I use a stringvalue,

object value = "45";
Application.SetSystemVariable("USERS1", value);

It should work in VB too.



wrote in message news:5623526@discussion.autodesk.com...
Peter, thanks for the response...

I'm doing this in VB and have tried both

Application.SetSystemVariable("USERS1", CObj("temp"))
Application.SetSystemVariable("USERS1", CType("temp", Object))

Neither form will work for me. Also, neither the USERI or USERR variables
require the value to be converted to an object.

Obviously, I'm a newbie here. Am I missing something really obvious in my
Imports or something?
Message 7 of 18
bowa
in reply to: bowa

Not working for me!

Getsystemvariable works:
LY_Order = Application.GetSystemVariable("USERS3")
but not set.

I've gone to using Interop with:
Dim acadApp2 As Autodesk.AutoCAD.Interop.AcadApplication
acadApp2 = GetObject(, "AutoCAD.Application")
acadApp2.ActiveDocument.SetVariable("USERS1", CObj(LY_FR))

This works but I was trying to get rid of the Interop reference

If anyone has an answer, I'd still be really interested in hearing it!
Message 8 of 18
Anonymous
in reply to: bowa

Are you converting to an object when you call the
Application.SetSystemVariable?
Have you tried to create the object variable and set the value first and
then use it when you call Application.SetSystemVariable?


wrote in message news:5623607@discussion.autodesk.com...
Not working for me!

Getsystemvariable works:
LY_Order = Application.GetSystemVariable("USERS3")
but not set.

I've gone to using Interop with:
Dim acadApp2 As Autodesk.AutoCAD.Interop.AcadApplication
acadApp2 = GetObject(, "AutoCAD.Application")
acadApp2.ActiveDocument.SetVariable("USERS1", CObj(LY_FR))

This works but I was trying to get rid of the Interop reference

If anyone has an answer, I'd still be really interested in hearing it!
Message 9 of 18
bowa
in reply to: bowa

Yes, I've tried it multiple ways, including:

Dim temp As Object = CObj(LY_Order)
Application.SetSystemVariable("USERS3", temp)

and
Application.SetSystemVariable("USERS3", CObj(LY_Order))

and
Application.SetSystemVariable("USERS3", CType(LY_Order, Object))

None of these variations will work
Message 10 of 18
Anonymous
in reply to: bowa

Just for the sake of it, have you tried to create the variable like this
just to be sure :

Dim temp As Object = "123"
Application.SetSystemVariable("USERS3", temp)


wrote in message news:5623614@discussion.autodesk.com...
Yes, I've tried it multiple ways, including:

Dim temp As Object = CObj(LY_Order)
Application.SetSystemVariable("USERS3", temp)

and
Application.SetSystemVariable("USERS3", CObj(LY_Order))

and
Application.SetSystemVariable("USERS3", CType(LY_Order, Object))

None of these variations will work
Message 11 of 18
bowa
in reply to: bowa

Just tried it with no luck. In AutoCAD, the variable continues to be an empty string. ("")
Message 12 of 18
Anonymous
in reply to: bowa

Very strange.
Hope someone with experience of VB.NET can help you.

Good luck...

wrote in message news:5623767@discussion.autodesk.com...
Just tried it with no luck. In AutoCAD, the variable continues to be an
empty string. ("")
Message 13 of 18
Anonymous
in reply to: bowa

I do not use VB.NET to do my development.

However, I did a test with VB after seeing your post.

Here is the simple code and it worked as expected:

Imports Autodesk.AutoCAD.Runtime

Imports ADApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class WDSGClass

' Define command 'Asdkcmd1'

_

Public Sub Asdkcmd1()

' Type your code here

ADApp.SetSystemVariable("USERS1", "1234567890A")

End Sub

End Class



After "NetLoad" the DLL and run the command "VBCMD", I called (getvar
"USERS1") at Acad command line. I got correct USERS1 value: "1234567890A".

I use Acad2006 and VS2005.

I am sure it works with C#, as other replies have confirmed.

So, it must be your other code causes the issue. You may want to look into
it harder or post your entire related code snippet. I'd not go too far by
trying re-install Acad/VS...


wrote in message news:5622523@discussion.autodesk.com...
Following a previous post about system variables, I can't seem to set and
get the USERS variables.

With the imports statement:
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application

I am trying to:
AcadApp.SetSystemVariable("USERS5", "bwa")
but it doesn't seem to be working.

AcadApp.SetSystemVariable("USERI5", 5)
works without issue so I'm guessing that I'm not formating the string
properly.

Can anyone provide assistance?

Thanks.
Message 14 of 18
Ed.Jobe
in reply to: bowa

Are you trying this as an isolated test or part of some other code which could have another problem that is causing the sysvar to get reset? IOW, make sure your test is as simple as possible to eliminate any other possible causes.

Ed


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.
How to post your code.

EESignature

Message 15 of 18
Anonymous
in reply to: bowa

Perhaps the part you are not telling us, is that you are
finding that the value of the system variable is an empty
string, after saving and reopening the drawing?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5622523@discussion.autodesk.com...
Following a previous post about system variables, I can't seem to set and get the USERS variables.

With the imports statement:
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application

I am trying to:
AcadApp.SetSystemVariable("USERS5", "bwa")
but it doesn't seem to be working.

AcadApp.SetSystemVariable("USERI5", 5)
works without issue so I'm guessing that I'm not formating the string properly.

Can anyone provide assistance?

Thanks.
Message 16 of 18
bowa
in reply to: bowa

Thanks for the suggestions guys. Yes Tony, I know that the USERS/R/I variables are document session specific and that they are not saved with the drawing. The problem is in the same session (in fact while debugging).

I am using AutoCAD Mechanical 2007 SP1 and have created a form with a button, two text boxes and a cancel button.

Code follows:
Imports Autodesk.AutoCAD.Runtime
Imports ADApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class frmMain

Private Sub btnUsers1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUsers1.Click
Dim txtU1 As String = txtUsers1.Text
ADApp.SetSystemVariable("USERS1", txtU1)
Dim txtU1a As String = ADApp.GetSystemVariable("USERS1")
txtGetUsers1.Text = txtU1a

End Sub

End Class

I used the txtU1 and txtU1as variables to simply see what was happening during debug. I still get nothing returned in the USERS1 variable.
Message 17 of 18
Anonymous
in reply to: bowa

OK, your code is simple enough: just set it and get it immediately.

I modified the code I posted previously, as following:


Imports Autodesk.AutoCAD.Runtime
Imports ADApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class WDSGClass

_
Public Sub Asdkcmd1()

' Set USERS1
ADApp.SetSystemVariable("USERS1", "A1234567890A")

' Get USER1
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
_
("Here is USERS1: " & ADApp.GetSystemVariable("USERS1"))
End Sub

End Class


It worked, of course, on both of my Acad2006 and Acad2007, to be precise,
Acad2006/7 MAP 3D.

So, I really do not know what problem is with your Acad. Does your other
code run OK? You may have bad luck of gettiing a "weird copy" of Acad, that
is all I can say, if nothing can solve it.

wrote in message news:5626215@discussion.autodesk.com...
Thanks for the suggestions guys. Yes Tony, I know that the USERS/R/I
variables are document session specific and that they are not saved with the
drawing. The problem is in the same session (in fact while debugging).

I am using AutoCAD Mechanical 2007 SP1 and have created a form with a
button, two text boxes and a cancel button.

Code follows:
Imports Autodesk.AutoCAD.Runtime
Imports ADApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class frmMain

Private Sub btnUsers1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUsers1.Click
Dim txtU1 As String = txtUsers1.Text
ADApp.SetSystemVariable("USERS1", txtU1)
Dim txtU1a As String = ADApp.GetSystemVariable("USERS1")
txtGetUsers1.Text = txtU1a

End Sub

End Class

I used the txtU1 and txtU1as variables to simply see what was happening
during debug. I still get nothing returned in the USERS1 variable.
Message 18 of 18
bowa
in reply to: bowa

To follow up on my earlier problems with SetSystemVariable and GetSystemVariable.

I ran into a couple of problems similar to this issue. Then when I installed AutoCAD 2007 on other machines in the office and tried to run my application, I kept getting errors indicating FileNotFoundException for Autodesk.AutoCAD.Interop Version=17.1.51.0
The version installed by AutoCAD 2007 is 17.0.54.0.

After a lot of hair pulling, I realized that the offending DLL had been installed on my machine when I checked out TrueView2008. It appears that it installs updated copies of the DLL that broke the GetSystemVariable and SetSystemVariable functions.

It also seems that it broke something in Environment.GetEnvironmentVariable("username"). I had to use AcadApp.GetSystemVariable("LOGINNAME") to get the user name.

I had to uninstall TrueView, uninstall AutoCAD 2007 and reinstall AutoCAD 2007 (a repair didn't correct the DLL's) to get things working. Now that I've cleaned out TrueView, everything is working as expected.

It would be nice if someone from Autodesk could verify that this is indeed the problem.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost