01-15-2021 06:55 AM
Is it possible to create a script where you calculate formulas from "calculation manager" and how in that case?
Solved! Go to Solution.
01-15-2021 09:39 AM - edited 01-15-2021 09:39 AM
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
01-18-2021 01:30 AM
In additional to Brads explanation, you will at least get a starting point using the Script macro recorder while executing a calculation.
01-22-2021 05:05 AM
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?
01-22-2021 05:18 PM
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
01-23-2021 02:53 AM
Thanks, this made the script a lot easier