Follow the steps below to programmatically assign the Y axis for each individual curve:
- Launch DIAdem and select the SCRIPT panel.
- Click File >> New to create a new script.
- Select either Visual Basic (VB) or Python script. This article provides an example for each programming language.
- Save the script.
- In the new script, enter the below lines to clear the Data Portal and load your data file.
- Change the file name and path for your data file accordingly. The code below assumes that the file is saved in the same folder as the script.
If using Python:
# Load data file and report layout
dd.Data.Root.Clear()
dd.DataFileLoad(dd.CurrentScriptPath + "Example Data.TDM", "TDM", "Load|ChnXYRelation")
If using VBScript:
' Define variables
Dim oMy2DAxisSystem, oMyPosition, oMyAxis, i, oMyCurve
' Load data file and report layout
Data.Root.Clear()
Call DataFileLoad(CurrentScriptPath + "Example Data.TDM", "TDM", "Load|ChnXYRelation")
- Use the Report.NewLayout() function to create a new report layout.
If using Python:
# Create a new report
dd.Report.NewLayout()
If using VBScript:
' Create a new report
Call Report.NewLayout()
- Using the below code, create a 2D Axis System on the report and position it centered on the page.
If using Python:
# Add a 2D axis system with 2 Y axes
oMy2DAxisSystem = dd.Report.ActiveSheet.Objects.Add(dd.eReportObject2DAxisSystem,"My2DAxisSystem")
oMyPosition = oMy2DAxisSystem.Position.ByCoordinate
oMyPosition.X1 = 20
oMyPosition.Y1 = 20
oMyPosition.X2 = 80
oMyPosition.Y2 = 80
If using VBScript:
' Add a 2D axis system with 2 Y axes
Set oMy2DAxisSystem = Report.ActiveSheet.Objects.Add(eReportObject2DAxisSystem,"My2DAxisSystem")
Set oMyPosition = oMy2DAxisSystem.Position.ByCoordinate
oMyPosition.X1 = 20
oMyPosition.Y1 = 20
oMyPosition.X2 = 80
oMyPosition.Y2 = 80
- Using the YAxisList property, add a second Y axis to the 2D Axis System.
If using Python:
oMyAxis = oMy2DAxisSystem.YAxisList.Add("SecondAxis")
If using VBScript:
Set oMyAxis = oMy2DAxisSystem.YAxisList.Add("SecondAxis")
- For each channel that should be plotted on the 2D Axis System, create a 2DCurve object and add it to the 2D Axis System.
- The example code below uses a For Loop to iterate through channels in the Data Portal.
If using Python:
# Using a For Loop, plot 4 channels on the 2D axis system
for i in range(dd.Data.Root.ChannelGroups(1).Channels.Count-1):
# Add the curve to the graph
oMyCurve = oMy2DAxisSystem.Curves2D.Add(dd.e2DShapeLine, "Data" + str(i+1))
oMyCurve.Shape.XChannel.Reference = "Example/Time" # Set X axis as Time channel
oMyCurve.Shape.YChannel.Reference = "Example/" + dd.Data.Root.ChannelGroups("Example").Channels.Item(i+2).Name
If using VBScript:
' Using a For Loop, set the Y axis for each individual curve
For i = 0 to (Data.Root.ChannelGroups(1).Channels.Count - 2)
' Add the curve to the graph
Set oMyCurve = oMy2DAxisSystem.Curves2D.Add(e2DShapeLine, "Data" + Str(i+1))
oMyCurve.Shape.XChannel.Reference = "Example/Time" ' Set X axis as Time channel
oMyCurve.Shape.YChannel.Reference = "Example/" + Data.Root.ChannelGroups("Example").Channels.Item(i+2).Name
Next
- Set the YAxisReference property for each of the curves added to the 2D Axis System.
- The example code below uses a For Loop to iterate through each curve.
- For each odd iteration, the curve is assigned the first Y axis.
- For each even iteration, the curve is assigned the second Y axis.
If using Python:
# Using a For Loop, set the Y axis for each individual curve
for i in range (1,oMy2DAxisSystem.Curves2D.Count+1):
oMyCurve = oMy2DAxisSystem.Curves2D.Item(i)
# Check if channel is even or odd
if (i) % 2 == 0:
# Even channel - plot against Y AXIS 2
oMyCurve.YAxisReference = 2
else:
# Odd channel - plor against Y AXIS 1
oMyCurve.YAxisReference = 1
If using VBScript:
' Using a For Loop, set the Y axis for each individual curve
For i = 1 to oMy2DAxisSystem.Curves2D.Count
Set oMyCurve = oMy2DAxisSystem.Curves2D.Item(i)
' Check if channel is even or odd
If i mod 2 = 0 Then
' Even channel - plot against Y AXIS 2
oMyCurve.YAxisReference = 2
Else
' Odd channel - plor against Y AXIS 1
oMyCurve.YAxisReference = 1
End if
Next
- Call the Report.Refresh() function to view changes on the REPORT panel.
If using Python:
# Refresh report
dd.Report.Refresh()
If using VBScript:
' Refresh report
Call Report.Refresh()