DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Script access to 2D Axis Curves

Solved!
Go to solution

Hello,

 

I am very seriously failing to understand the object model used in Report. The following line of code works perfectly in one of my scripts:

Report.ActiveSheet.Objects("2DAxis1").Curves2D("2DAxis1_Curve1").Shape.XChannel.Reference = HWChn.Name

However, when I transfer it to another script that uses a different Report file and change the channel reference to the first channel of the first group, it fails:

Report.ActiveSheet.Objects("2DAxis1").Curves2D("2DAxis1_Curve1").Shape.XChannel.Reference = "[1]/[1]"

The error message says: Object doesn't support this property or method: 'XChannel'

 

At first I thought it was the channel reference but now I suspect it's the name of the Curves2D object. The error message is not clear in which object it's referring to. I used Ctrl+Shift+C on the Curves and Axis Definition dialogue box and the reference in the retrieved text is:

Report.ActiveSheet.Objects("2DAxis1").Curves2D.Item(1).Shape.XChannel.Reference = "[1]/[1]"

The above line is using Item to refer to the first curve.

 

Opening the Curve Parameters dialogue box for curve 1 and using Ctrl+Shift+C yields:

Report.ActiveSheet.Objects("2DAxis1").Curves2D.Item("2DObj1_Curve1").Shape.XChannel.Reference = "[1]/[1]"

 

That's three different ways of accessing the same curve, but the first way only works on one of my Report files and not the other.

 

I then created a dummy Report file using a single axis system and tested my first line - it worked perfectly. I then added a second axis system, because that's the only difference that I can see between my two Report files, and ran the line once more. Again, it worked fine. So, now I'm stuck as to what the difference is between the various ways of accessing the curve objects. What's wrong with the first way, and how do I get the actual name of each curve to guarantee that I am correctly referencing them in code?

 

Thanks, Simon. 

0 Kudos
Message 1 of 2
(1,854 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon,

 

I have two suggestions for you.  The first is to break up your object tree into multiple variables.  This will make subsequent commands easier to type and read (like looping over N curves of a graph).  More importantly, it will make it easier to debug, because this way you really will be told which object level is struggling in the new context when you transplant code:

 

Set Sheet = Report.ActiveSheet
Set Graph = Sheet.Objects("2DAxis1")
Set Curve = Graph.Curves2D("2DAxis1_Curve1").Shape
Curve.XChannel.Reference = "[1]/[1]"

 

 

My second bit of advice is to use curve indices unless there's a compelling reason to name your curves.  This is for the same reason that you encountered trouble-- different *.TDR files often name their objects and their subobjects differently, but they all work with indicies:

 

Set Sheet = Report.ActiveSheet
Set Graph = Sheet.Objects("2DAxis1")
Set Curve = Graph.Curves2D(1).Shape
Curve.XChannel.Reference = "[1]/[1]"

 

 

I do recommend that you stick with object names, because the order of object creation often changes between *.TDR files, plus it's pretty easy to interactively rename a parent object with a simple right-click on it, and you can see the object name if you click on it and look at the bottom left of the DIAdem screen.

 

Brad Turpin

Senior Technical Support Engineer

National Instruments

0 Kudos
Message 2 of 2
(1,779 Views)