How to set System environment variable using batch/script before AutoCAD launch

How to set System environment variable using batch/script before AutoCAD launch

Anonymous
Not applicable
3,607 Views
9 Replies
Message 1 of 10

How to set System environment variable using batch/script before AutoCAD launch

Anonymous
Not applicable

How to set System environment variable using batch/script before AutoCAD launch

 

I have a requirement to load an external plugin which reads system environment variable

system environment variable values changes based on the CAD Application

Requirement is to have separate system environment variable values for AutoCAD which should be set before AutoCAD process is started.

 

Any help on this will be highly appreciated.

0 Likes
3,608 Views
9 Replies
Replies (9)
Message 2 of 10

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

set ‹var name›=‹value> is the syntax I would suggest.  This can be contained in a script, login batch file or simply run at the Windows command line.

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 3 of 10

ArchD
Collaborator
Collaborator

You may want to do a condition that checks for autocad version, then sets the variable based on that.

 

So create an acad.lsp file that everyone reads and do something like:

 

(cond
	((= (getvar "acadver") "23.0s (LMS Tech)")
		(setenv "VARIABLE" "SETTING")
	)
(setenv "VARIABLE" "SETTING")
)

Obviously you can add as many autocad versions as you need. Also, this won't set it before AutoCAD is run, but during startup.

Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
0 Likes
Message 4 of 10

scot-65
Advisor
Advisor

You will have to do some investigating first.
What variable(s) are you trying to set?

After gathering the suspect variables, go to help --> system variables
and determine if the variable is either:
a) Drawing specific.
b) "User Setting" or Registry.
c) "Not Saved".

The only manipulation externally, before launch, would be item "b". However, if
the entry is located inside a profile sub-section, one will need to know the name
of the profile.
For "a" - One can only manipulate a DXF file (I think).
For "c" - It would have to be set during launch.

Do a search here for key phrase "load order", "startup sequence" or similar to see

the sequence of third party interface points verses when the plugin(s) is loaded.

Image below is a screen capture from 2014 (of unknown origin).

 

ACAD-StartupSequence.jpg

 

???


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

Message 5 of 10

Anonymous
Not applicable

Hi John

 

I tried using wgm.scr with below contents

set PTC_WGM_ROOT=C:\Users\%username%\Documents\wgmcache\wgm
set PTC_WLD_ROOT=C:\Users\%username%\Documents\wgmcache\wld
set PTC_WF_ROOT=C:\Users\%username%\Documents\wgmcache\wf
set PTC_WFS_ROOT=C:\Users\%username%\Documents\wfs

And AutoCAD shortcut target changed as shown below

"C:\Program Files\Autodesk\AutoCAD 2018\acad.exe" /product ACAD /language "en-US" /b "C:\Program Files\Autodesk\AutoCAD 2018\wgm.scr"

 

However it does not work correctly.

I need the AutoCAD to be launched with above environment variable and not the environment variable set after the launch.

 

Let me know if you need any further information.

 

It would be good if you can share any sample batch or script file.

 

Regards

Amey Parkar

0 Likes
Message 6 of 10

alex101000
Collaborator
Collaborator

To install additional paths, you can use a registry entry, for example (AutoCAD 2016)

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R20.1\ACAD-F001:419\Profiles\<<YOUR-PROFILE>>\General]

"ACAD"=...

 

--
Please select the Accept as Solution button if my post solves your issue or answers your question.
Message 7 of 10

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

Is this custom app one that you have designed? Or is it from another developer?

 

If you are on a Windows domain, can you not set the environment with GP?

 

Or if stand alone, how many users would you need to set this up on?

 

If only a couple then perhaps just set it manually?

 

Capture.PNG

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.

 

 


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 8 of 10

Anonymous
Not applicable

Hello John

 

Thanks for your time on this.

 

This app/plugin is a PTC Windchill app developed by PTC for connection with Windchill PLM Tool

 

We are on windows domain, however we cannot set environment variable through group policy as we have separate cache folder for each CAD Application like AutoCAD, Creo, Solidworks, etc., Having common cache folder might have issues with loading these data to PDM.

 

We have around 10-15 users each at 4 sites, so setting up manually will not be a good option either.

 

I am looking to setup a batch or script or any other way to set environment variables which should be set before the AutoCAD launch. There should be some way out for this.

 

Regards

Amey Parkar

0 Likes
Message 9 of 10

alex101000
Collaborator
Collaborator

I can tell you only an approximate way to write a script.
We check if AutoCAD is running:

 

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery( _
    "Select Name From Win32_Process " _
    & "Where Name = 'acad.exe'")

If colProcesses.Count >= 1 Then
  Set objShell = Wscript.CreateObject("Wscript.Shell")
  objShell.Run "notepad.exe"
else
  Msgbox "No AutoCAD"
End If


Set or delete values of environment variables:

 

http://www.robvanderwoude.com/vbstech_data_environment.php

To set a variable, specify new values for its Name, UserName and/or VariableValue properties.

The following code, from the book Windows Server Cookbook by Robbie Allen, creates a new system environment variable called FOOBAR:

strVarName = "FOOBAR"
strVarValue = "Foobar Value"

Set objVarClass = GetObject( "winmgmts://./root/cimv2:Win32_Environment" )
Set objVar      = objVarClass.SpawnInstance_
objVar.Name          = strVarName
objVar.VariableValue = strVarValue
objVar.UserName      = "<SYSTEM>"
objVar.Put_
WScript.Echo "Created environment variable " & strVarName
Set objVar      = Nothing
Set objVarClass = Nothing

And the following code removes the environment variable again by giving it an empty value:

strVarName = "FOOBAR"

Set objVarClass = GetObject( "winmgmts://./root/cimv2:Win32_Environment" )
Set objVar      = objVarClass.SpawnInstance_
objVar.Name          = strVarName
objVar.VariableValue = ""
objVar.UserName      = "<SYSTEM>"
objVar.Put_
WScript.Echo "Removed environment variable " & strVarName
Set objVar      = Nothing
Set objVarClass = Nothing

Replace the dot in the GetObject commands by a remote computer name to manage environment variables on that remote computer.

--
Please select the Accept as Solution button if my post solves your issue or answers your question.
0 Likes
Message 10 of 10

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

This isn't really an AutoCAD issue. Setting the Windows environment variables for your 3rd party add-in can be done manually, through group policy or through the script in the last post.  You might even consider using the setenv in a user login script.

 

If none of these fits your requirements I suggest contacting the developer of the 3rd party app to see if they can offer suggestions that are different than those already provided in this thread.  I am sorry that I dont have additional resources on this process for you.  

 

You might also consider a post in the Installation and Licensing forum as they might have some other methods that they have used to help with customer deployments.

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.

 

 


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes