DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

set text in report legend with python script

Solved!
Go to solution

How does one specify the curve related text in a report legend from a python script? 

 

I found this documentation for visual basic scripting: https://zone.ni.com/reference/en-XX/help/370858P-01/reportapi/properties/report_property_relatedlege...

However, the objects seem to differ from VBS to python. How does this line from the example in the documentation translate to python?

oMy2DCurve1.RelatedLegendText(2) = "First Curve"

 

0 Kudos
Message 1 of 4
(1,440 Views)

Hi cdbocksti,

 

I agree, as far as I can tell, this should be the corollary code in python, but those 2 lines you mentioned don't run in DIAdem 2020 SP1 like I would expect them to.  I have tried a variety of guesses and have found no way to tickle the syntax into working.

dd.Data.Root.Clear()
dd.DataFileLoad(r"C:\Users\Public\Documents\National Instruments\DIAdem 2020\Data\Example.tdm", "TDM")
dd.Report.NewLayout()
oMy2DAxisSystem = dd.Report.ActiveSheet.Objects.Add(dd.eReportObject2DAxisSystem, "My2DAxisSystem")
oMyPos = oMy2DAxisSystem.Position.ByCoordinate
oMyPos.X1 = 20
oMyPos.X2 = 80
oMyPos.Y1 = 20
oMyPos.Y2 = 80
oMy2DCurve1 = oMy2DAxisSystem.Curves2D.Add(dd.e2DShapeLine, "My2DCurve1")
oMy2DCurve1.Shape.XChannel.Reference = ""
oMy2DCurve1.Shape.YChannel.Reference = "[4]/[1]" 
oMy2DCurve2 = oMy2DAxisSystem.Curves2D.Add(dd.e2DShapeLine, "My2DCurve2")
oMy2DCurve2.Shape.XChannel.Reference = ""
oMy2DCurve2.Shape.YChannel.Reference = "[4]/[2]" 
oMy2DAxisSystem.CurveLegend.Visible = True
oMyCurveLegendText = oMy2DAxisSystem.CurveLegend.Columns.Add()
oMyCurveLegendText.Type = dd.eLegendTextCurveRelatedText
#oMy2DCurve1.RelatedLegendText(2) = "First Curve"
#oMy2DCurve2.RelatedLegendText(2) = "Second Curve"
oMyLegendPosition = oMy2DAxisSystem.CurveLegend.Position
oMyLegendPosition.RelativePosition = dd.eLegendRelativePositionBottomRight
oMyLegendPosition.ElementHeight = 10
oMyLegendPosition.ElementWidth = 20
dd.Report.Refresh()

 

I have filed Bug #1265795 and will let you know what R&D says,

Brad Turpin

Principal Technical Support Engineer

NI

 

0 Kudos
Message 2 of 4
(1,399 Views)
Solution
Accepted by topic author cdbocksti

Hi cdbocksti,

 

I heard back from R&D.  In python we have to use the SetRelatedLegendText(No, Text) method, instead of directly setting the property's array element, like this:

oMy2DCurve1.SetRelatedLegendText(2, "First Curve")
oMy2DCurve2.SetRelatedLegendText(2, "Second Curve")

Now the code runs through for me.  R&D was already planning on adding python code snippets all over the Help system for the next version of DIAdem.  They specifically said they would make sure the SetRelatedLegendText() command was used in the python version for this Help page.

 

Thanks for pointing this out!

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 3 of 4
(1,386 Views)

Worked on the first try... thanks!

0 Kudos
Message 4 of 4
(1,376 Views)