07-10-2023 01:59 PM
Hi,
Is there a way to get maximum Y value of all the Y values in a chart?
The number of curves, Y channel and Y channel expression will be changing with respect to report template used. Need to refer the channels and expression used in report template to find maximum Y value among all the curves in the chart.
Is there any DIAdem script command to do it in a better way?
Example:
In this template, 5 curves with 3-Y channels and 2 -Y expression channels. How to find the maximum value of Y among these 5 curves using DIAdem scripts?
Regards,
Durai
Solved! Go to Solution.
07-11-2023 02:30 AM
Call LogFileDel
Call GetMaxOfAllViewSheetCurves()
Function GetMaxOfAllViewSheetCurves()
Dim oSheet, oArea, oCurve, oChnX, oChnY
Set oSheet = View.ActiveSheet
Set oArea = oSheet.ActiveArea
For Each oArea In oSheet.Areas
If oArea.DisplayObjType = "CurveChart2D"Then
For Each oCurve In oArea.DisplayObj.Curves2D
Set oChnY = Data.GetChannel(oCurve.YChannelName)
Call ChnCharacter(oChnY)
Call LogFileWrite("Curve # " & oCurve.Index & vbTab & oChnY.GetReference(eReferenceIndexName) & vbTab & " max: " & Str(oChnY.Maximum,"AutoAdj") & " " & oChnY.UnitSymbol)
Next
End If
Next
End Function 'GetMaxOfAllViewSheetCurvesIO
07-11-2023 05:43 AM - edited 07-11-2023 05:44 AM
Hi Mark,
will the code work with report sheet?
I am trying to do it in report template. Some curves are having expression in Y channel.
regards,
Durai
07-13-2023 02:20 AM
Hello Durai26,
in REPORT you can get the maximum y value from all visible curves with this VBS function. It also considers constants that contain an expression.
function GetMaxYValueFromCurves(Curves)
dim Curve, MaxValue, CurveValue
for each Curve in Curves
' Only visible curves
if Curve.Enable then
if Curve.ShapeType = e2DShapeLineAndPoints or Curve.ShapeType = e2DShapeLine then
CurveValue = Data.GetChannel(Curve.Shape.YChannel.Reference).Maximum
elseif Curve.ShapeType = e2DShapeConstant then
if instr(Curve.Shape.YConstant.Reference, "@@") > 0 then
CurveValue = eval(replace(Curve.Shape.YConstant.Reference, "@", ""))
else
CurveValue = val(Curve.Shape.YConstant.Reference, Novalue)
end if
end if
if IsEmpty(MaxValue) or CurveValue > MaxValue then
MaxValue = CurveValue
end if
end if
next
GetMaxYValueFromCurves = MaxValue
end function
print(GetMaxYValueFromCurves(Report.ActiveSheet.Objects("2DAxis1").Curves2D))
07-13-2023 01:03 PM - edited 07-13-2023 01:37 PM
Hi AnJalpaka,
Thanks a lot for your suggestion, it was great to have some scripts like this.
It works fine for one of my template but unfortunately it throws error in my another template.
My report template refers to a particular channel and some situation there is no such channel exist in data portal. Since no channel exist, I am getting error in the below line,
CurveValue = Data.GetChannel(Curve.Shape.YChannel.Reference).Maximum
is there a option to check for channel existing before fetching the value? How to skip these lines if there is no channel present in data portal?
Also, sometimes channel exists but it has NOVALUE in maximum and minimum properties. Even in these scenario, it throws error.
regards,
Durai
07-14-2023 02:27 AM
Hello Durai26,
The script can of course safeguard other circumstances, such as Novalues or non-existent channels. If the maximum of a channel is not known, it can be determined by the ChnCharacter command. If you don't want this, then take out the section with the call of ChnCharacter.
function GetMaxYValueFromCurves(Curves)
dim Curve, MaxValue, CurveValue, Channels, Chn
for each Curve in Curves
' Only visible curves
if Curve.Enable then
if Curve.ShapeType = e2DShapeLineAndPoints or Curve.ShapeType = e2DShapeLine then
set Channels = Data.GetChannels(Curve.Shape.YChannel.Reference)
if Channels.Count = 1 then
set Chn = Channels(1)
if IsNull(Chn.Maximum) then
' Calculate maximum value
call ChnCharacter(Chn)
end if
CurveValue = Chn.Maximum
end if
elseif Curve.ShapeType = e2DShapeConstant then
if instr(Curve.Shape.YConstant.Reference, "@@") > 0 then
CurveValue = eval(replace(Curve.Shape.YConstant.Reference, "@", ""))
else
CurveValue = val(Curve.Shape.YConstant.Reference, Novalue)
end if
end if
if not IsNull(CurveValue) then
if IsEmpty(MaxValue) or CurveValue > MaxValue then
MaxValue = CurveValue
end if
end if
end if
next
GetMaxYValueFromCurves = MaxValue
end function
07-17-2023 01:31 AM