DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

xml plugin global variables problem

Solved!
Go to solution

Hi everyone,

 

recently I've started working on a SUD dialog, where the user can load  *.xml files in DIAdem.So far my code for the button looks like this:

 

....

     Call FileNameGet("ANY","FileRead", "*.xml" )
     Call DataFileLoad(FileDlgName,"XML_Plugin","Load")

....

 

And I must say it is working fine!I am able to load all listed in the file devices. BUT when I tried loading a number of devices, I used a global variable, which I define in the vbscript file I load the SUD from, I noticed that the global variables I defined with GlobalDim are not defined in the XML_Pluging vbs.:mansurprised:

Then I started experimenting and so far without success, regardless where I define global variables ,in my *.xml plugin they are all undefined!Even native commands and functrions of DIAdem doesn't work. If I run the script in DIAdem, it shows no error, but when I use the plugin to open a file then it gives an error.For example MsgBox is not allowed.

I used the example plugin for *.xml , which was posted on the website of NI, and I did some modifications.But overall I didn't corrupted it and I kept the same structure:

 

Sub ReadStore(File)

  Dim xmlFile : xmlFile = File.Info.FullPath  
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  ' open the file
  OpenXMLFile xmlFile

End Sub

 


 Sub OpenXMLFile(xmlFile)
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  ' Open MS-Xml Parser
  ' Create the ActiveX object for the Microsoft XML parser.
  Dim xDoc : set xDoc = CreateObject("MSXML2.DOMDocument.3.0")

  ' Try loading the XML document
  If xDoc.Load(xmlFile) = False Then
    ' The XML document failed to load.
    RaiseError "Could not load XML document!"
  End If

  dim originalLocale : originalLocale = GetLocale
  SetLocale "en-us"

  ' The XML document loaded successfully!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'----------------------------------------------
'Read out header information
'---------------------------------------------- 

 

Here I read some values from the Header and then I loop over all devices present in the file! 

So basically I have two subroutines and thats all.

 

SetLocale originalLocale

 

  End Sub

 

 

So what am I doing wrong??Why global variables and other functions won't work.Is it because there is xml code in the script as well or it is a version problem???

 

 

I'm using DIAdem 10.2 .If I use global variables in other vbscripts, I use to plot curves for example I have no problems.There I have no *.xml code and no subroutines.

 

I will appreciate any workaround which will make my *.xml plugin work.

 

 

 

 

0 Kudos
Message 1 of 5
(4,640 Views)
Solution
Accepted by topic author fscommand

Hi fscommand,

 

This is all expected behavior.  The XML DataPlugin, like all VBScript DataPlugins, runs in a separate VBScript host from the DIAdem VBScript host.  The DIAdem VBScript host adds all those green global variables and red global commands to the standard Microsoft VBScript host.  The DataPlugin VBScript host has its own special abilities (File object, Root object), but it does NOT have access to any of the green global variables or red global commands in the DIAdem VBScript host.  Your SUDialog runs in a third VBScript host that is separate from the other two and has abilities the other two do not (SUDialog control callback functions), but the SUDialog VBScript host and the DIAdem VBScript host DO share all the green global variables and red global commands.

 

Normally all the blue VBScript commands are allowed in all 3 VBScripts hosts, but for the particular case of DataPlugins the MsgBox and InputBox functions have been specifically repressed because dialogs could cause lots of trouble with the DataFinder.  They were actually allowed in DIAdem 9.1 which was the last DIAdem version before the DataFinder appeared.

 

So, why do you want to pass information between the XML DataPlugin and DIAdem?  If you want the DataPlugin to share information with DIAdem, then you should just expose each piece of information as a new property in the Data Portal, which the DIAdem VBScript will be able to read and use.  The file path of the XML file is already available inside the XML DataPlugin.  What other information in the calling DIAdem VBScript do you need to share with the DataPlugin?

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

Message 2 of 5
(4,609 Views)

Hi Brad,

 

I was not aware of this 😞 Well the problem that I cannot solve is that through the SUD dialog,I want to offer the option to load only a limited number of devices.I can do that by taking the input of an editbox and assign it to a global variable,which value will be evaluated in the *.xml plugin and the wanted number of devices only will be loaded.Or maybe I can use a selective load which I didn't tried so deep until now.Hmm, anyway I'll probably drop this function and hope that our designers will live with it.

Thanks for your post I will mark it as a solution.Have a nice day.  

0 Kudos
Message 3 of 5
(4,600 Views)

Hi fscommand,

 

Before you abandon the idea of this feature completely, let me offer you two alternatives.  First, if you know the channel indices that you want (which you may not), then you can load only those channels (say the first 3 channels of the first group), like this:

 

Call DataFileLoad(FileDlgName, "XML_Plugin", "[1]/[1-3]")

 

If on the other hand your selection depends on the channel name or some other channel or group property, then you can load all the data channels and delete the ones you don't want.  If the channels have a lot of data in them such that this is slow, you can register load all the data channels and exapnd the ones you don't delete, like this:

 

Call ChnValExpand(ChNum)

 

I'm including an example VBScript below,

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 5
(4,582 Views)

Grrr,

 

That first command has to have a "...Sel()" in it, like this:

 

Call
DataFileLoadSel(FileDlgName, "XML_Plugin", "[1]/[1-3]")

 

Brad

0 Kudos
Message 5 of 5
(4,581 Views)