I havn't found a way to do this from .onaction but there is an easy way to tranfer variables between scripts using scripting.globals
Globals Property (Scripting Object)
Returns global name/key - value pairs. Use this property for script to script communications.
To store a global name/key - value pair:
Scripting.Globals("MyGlobalName") = "MyGlobalValue"
To read from a global name/key -value pair:
MsgBox Scripting.Globals("MyGlobalName")' Returns “MyGlobalValue”
To store a global object:
Set Scripting.Globals.Data(“MyGlobalObjName”) = myObj
To output the global object's name:
MsgBox Scripting.Globals("MyGlobalObjName").Name' Returns the value of myObj.Name
To iterate the keys:
For Each key In Scripting.Globals.Keys
MsgBox key & "=" & Scripting.Globals(key)
Use the ScriptHelper object in the called .vbs script.
Example menu line with arguments:
btn1.OnAction = "run called_script.vbs argument1 argument2"
Then in the called_script.vbs file do this:
Taken from the PCB Automation Reference document
Set ScriptArgs = ScriptHelper.Arguments
' The first argument is the third item in the collection
arg1 = ScriptArgs.Item(3)
arg2 = ScriptArgs.Item(4)
So, when I try to do a test (run test.vbs 1 from the Command Line toolbar) in DxD in Linux, I get the following error:
"Object required: 'ScriptHelper'"
Set args = ScriptHelper.Arguments
Is there something I need to do to initialize ScriptHelper to begin with?
Still looking for a solution concerning DxD/xDx and ScriptHelper, years later.
The long way around is to write the parameters to a text file, then read them with the external script once it is open. You can have the external script delete the file after it's done, if needed.
I do something like this to identify the selected part in DxDatabook to a vb.net application, as the part selection method that fires from DxDatabook cannot pass a value to my running app. Some operating system delay checks are necessary to ensure the file writes properly. In my case, since the app cannot know when the file will be written, I use a timer to periodically look at the file and see if it has changed.
This sounds like a lot of overhead but the file operations are very fast and the user cannot even tell they are happening. In my app it appears to happen real time. In your case, by the time the menu item is executed and the resulting window appears, they could be done and visible to the user as if they were passed directly.
One big benefit of this method is that there are no limits to what you can pass, as long as it can be represented in alphanumeric form, and you don't have to mess around with complicated OS API calls and the difficulty of setting and retrieving values from them.
Another long way around is to use the Windows registry to store the values. Pretty fast and no worries about leaving files hanging around. I would say you have to be careful to not clutter up the registry, so do some planning ahead of time, but the registry is already phenomenally cluttered up, so if you add a few keys it will be like a drop of water in a swimming pool.
Ok, thanks for the help. Between this and Global Variables, I'll have to make it work!