DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

calculation managers to script

Solved!
Go to solution

Is it possible to create a script where you calculate formulas from "calculation manager" and how in that case?

 
 

 

0 Kudos
Message 1 of 6
(1,944 Views)
Solution
Accepted by erlera

Hi erlera,

 

Yes, the key starting point is the object variable "CalculationSet", from which all the contents in the Calculation Manager dialog can be edited and invoked.  The code completion for that variable in the DIAdem SCRIPT panel seems to be missing in DIAdem 2020, though, so I'm afraid you have to dig pretty hard in the Help system to find how to use it.  Here's an example to get you started, using the default Calculation Manager that DIAdem ships with and the default data set that DIAdem loads when it starts fresh:

 

 

Dim CalcGroup, Calculation
Set CalcGroup = CalculationSet.CalculationGroups("Vehicle Power")
Set Calculation = CalcGroup.Calculations("Power")
'Set Calculation = CalculationSet.GetCalculation("Vehicle Power/Power")
'CalculationSet.ShowExecutionDlg
LogFileDel
LogFileWrite Calculation.CalculationGroup.Name & "/" & Calculation.Name
LogFileWrite Calculation.CalculationScript
LogFileWrite CalcVarOutput(Calculation.Inputs)
LogFileWrite CalcVarOutput(Calculation.Outputs)
Call Calculation.Run()


Function CalcVarOutput(CalcVariables)
  Dim i, iMax, Output
  iMax = CalcVariables.Count
  Output = ""
  FOR i = 1 TO iMax
    Output = Output & CalcVariables(i).Name & " = "
    IF CalcVariables(i).ReferenceType = eReferenceTypeChannel THEN
      Output = Output & CalcVariables(i).Reference.Channel
    END IF
    IF i < iMax THEN Output = Output & vbCRLF
  NEXT ' i
CalcVarOutput = Output
End Function ' CalcVarOutput()

 

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 2 of 6
(1,923 Views)

In additional to Brads explanation, you will at least get a starting point using the Script macro recorder while executing a calculation.

0 Kudos
Message 3 of 6
(1,866 Views)

THANKS, 

Is it posible to put this new generated channel in a spesific default group or will it be placed in the lower default group anyway?

0 Kudos
Message 4 of 6
(1,847 Views)
Solution
Accepted by erlera

Hi erlera,

 

Sure, in the Calculation Manager you can specify the full "channel path" of the output channel.  If you leave the Group part blank, it will send the new channel to the default Group:

 

Output = "/ChannelName"

 

If you provide the Group index or name, it will send the new channel to the Group you indicate:

 

Output = "[5]/ChannelName"

Output = "GroupName/ChannelName"

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 5 of 6
(1,840 Views)

Thanks, this made the script a lot easier

0 Kudos
Message 6 of 6
(1,828 Views)