DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Custom Channel Propertiesfrom an External VB Script

Solved!
Go to solution

I'm am updating an inhouse VB script that opens a datasets, and generates an ISOMME dataset for processing. (

 

The script creates an instance of Diadem objects and iterates the channel collection, and exports the raw data into the ISOMME format.

 

I need to update my script to allow creation of and reading of custom channel properites.

 

I can do this easily within a VB script running inside DIADEM (see below)

 

Dim i
Dim sChanName
Dim sChanComment

For i = 1 To GlobUsedChn
sChanName = CN(i)
sChanComment = CC(i)

'Add custom property

' Write custom properties SensorID and Sensitivity
if i = 2 Then
Call Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Add("SensorID", "ID1234ABC",DataTypeString)
Call Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Add("Sensitivity", 0.123456789,DataTypeFloat64)
End if

Next

 

For i = 1 To GlobUsedChn
sChanName = CN(i)
sChanComment = CC(i)

' Read custom propertiees
if Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Exists("SensorID") Then
LogFileWrite "Channel " & sChanName & " :: SensorID=" & Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Item("SensorID").Value
End if
if Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Exists("Sensitivity") Then
LogFileWrite "Channel " & sChanName & " :: Sensitivity=" & Data.Root.ChannelGroups(1).Channels(sChanName).Properties.Item("Sensitivity").Value
End if

Next

 

 

But I wish to do this via an external VBScript that instanitates an instance of Diadem,how would I do that?

 

I can access Channel names, but cannot get to the custom properties. Have a sample of my script below. The bit in red does not work as the properties/methods I would like to access are not available. Is there a way for me to do this? 

 

    Set oDiadem = CreateObject("DIAdem.TOCommand")       
    Set oDiademSheet = CreateObject("DIAdem.TODataSheet") 

    oDiadem.CmdExecuteSync ("DataDelAll(1)") 
     nDiademStatus = oDiadem.TextVarSet("T3", sDataSet)
     oDiadem.CmdExecuteSync ("DataLoad(T3)")
      'Use the diadem command GlobUsedChn to recover the number of channels       
      oDiadem.CmdExecuteSync ("L3 := GlobUsedChn")    
      'Get the value of GlobUsedChn from L3 and put it into nChannelCount)
      nDiademStatus = oDiadem.TextVarGet("L3", nChannelCount )
        
        
      For i = 1 To nChannelCount 
            If Not oDiadem.bInterfaceLocked Then
                nDiademStatus = oDiademSheet.ChnNameGet(i, sChannelName)
                nDiademStatus = oDiademSheet.ChnCommentGet(i, sChannelComment)            
            End If            
            
            If sChannelName = "13APILBOMIMIACXP" Then 
                Set oTargetChannel = oDiademSheet.Data.GetChannel("13APILBOMIMIACXP")
                oTargetChannel.Properties.Add  "'SEnsitivity'" , 123.4567, DataTypeFloat64                

            End If 
        Next    
    End If 

 

 

 

 

 

0 Kudos
Message 1 of 3
(3,310 Views)

Hello,

 

Have you confirmed that it is ever entering the sequence in red? From a quick look at VBS operators I think the issue is that the if statement needs an extra = sign as right now it is assigning the value rather than comparing.

 

https://www.tutorialspoint.com/vbscript/vbscript_operators.htm

 

What environment is the VBS script actually running in? They're may be debugging tools within this environment to check for things like, whether the oTargetChannel actually has any channel data assigned to it.

 

Best regards,

 

Ed

0 Kudos
Message 2 of 3
(3,236 Views)
Solution
Accepted by topic author Onkar

Hi

 

My approach was incorrect. Here is a solution for anyone that wishes to add custom properties via VBscript running outside of Diadem.

 

Dim oData

Dim oDiadem

Dim oDiademSheet,

Dim i

 

Set oDiadem = CreateObject("DIAdem.TOCommand")

Set oDiademSheet = CreateObject("DIAdem.TODataSheet") 

nDiademStatus = oDIAdem.VariantVarGet("Data", oData)

 

For i=1 To nChannelCount
    If Not oDiadem.bInterfaceLockedThen
        nDiademStatus=oDiademSheet.ChnNameGet(i,sChannelName)
        nDiademStatus=oDiademSheet.ChnCommentGet(i,sChannelComment)
    EndIf
    'Here are am interested in setting the ID For only one particular sensor. 23 Is a constant for String
    If sChannelName="13APILBOMIMIACXP"Then
        Call oData.Root.ChannelGroups(1).Channels(sChannelName).Properties.Add("SensorID","ID1234ABC",23)
    EndIf
Next

0 Kudos
Message 3 of 3
(3,217 Views)