08-22-2014 03:20 AM
Solved! Go to Solution.
08-22-2014 10:54 AM
Hi LaxG,
If your script is creating the calculated channels, then you know what you're naming them-- why couldn't your REPORT layout contain references to those channel names already? Is it a dynamic number of curves conditional to the results of the analysis, or perhaps a dynamic number of REPORT sheets?
You can programmatically change the channel reference of existing curves or table columns with a DIAdem VBScript. You can also add a curve or table column with a DIAdem VBScript. But the more you can save in the TDR file, the less work you'll have programming, so that's the best place to start.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
08-25-2014 12:59 AM
Hi LaxG,
Brad is absolute right. It is possible to create your whole layout via script.
If you have loaded the example report layout you can copy these lines to create a new line in your plot. This is the recommended object oriented way.
call Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Add(e2DShapeLine, "anyName")
Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape.XChannel.Reference = "[1]/Zeit"
Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape.YChannel.Reference = "[1]/Geschwindigkeit"
For performance reasons it's recommended to use the it like this.
dim oLine
set oLine = Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape
oLine.XChannel.Reference = "[1]/Zeit"
oLine.YChannel.Reference = "[1]/Geschwindigkeit"
Like Brad mentioned it is much easier, that you have a stored template of your report with all setings and customisations already done.
You open this layout file and have stored the names of your calculated channels. When you are doing this with a script they always have the same name and belong to the same group.
Now you can customize the references of the line items.
Kind Regards,
Philipp K.
AE | NI Germany
08-26-2014 07:49 AM
Dear Brad_turpin and Wendler,
Thanks for the useful comments. Its really helpful and works fine.
Best regards,
LaxG
07-05-2019 06:05 AM
Hello Phil & Brad
Why do we need to use strings as Reference to XChannel in report objects? Wouldn't it be nice to use the data.channelgroups.channel-object and assign this object to be the XChannel object directly?
Currently my work-around is
strXName = "Time"
strYName = "anyYChannel"
strArea = "2D-Axis1"
call Report.ActiveSheet.Objects(strArea).Curves2D.RemoveAll
Set oGrpList = data.GetChannelGroups("*16*")
for each oMyChnGrp in oGrpList
Set oMyDisplayObj = Report.ActiveSheet.Objects(strArea).Curves2D.Add(e2DShapeLine,"")
Set o2DCurve = Report.ActiveSheet.Objects(strArea).Curves2D.Item(Report.ActiveSheet.Objects(strArea).Curves2D.Count)
o2DCurve.Shape.XChannel.Reference = oMyChnGrp.Channels(strXName).GetReference(eRefTypeNameName)
o2DCurve.Shape.YChannel.Reference = oMyChnGrp.Channels(strYName).GetReference(eRefTypeNameName)
next
As you can see, "Reference" and "GetReference" are used to transfer the information from one object (datsa channel) to the other (graph curve).
But it could be
set o2DCurve.Shape.XChannel = oMyChnGrp.Channels(strXName)
instead.
KR
MiC
07-08-2019 04:53 PM - edited 07-08-2019 04:57 PM
Hi MiC,
I agree that it would be nice to have a property or method with which one could just pass the object variable directly, rather than deriving a string representation of it to assign. The reason the current approach was implemented first is that it lines up with the use of the *.TDR file. Most customers save what they see in the REPORT panel to a *.TDR file and then load that *.TDR file back in at a later time. The *.TDR file is saved internally as an XML file, so any channel references will HAVE to be a string when saved to disk in XML. By forcing the programmer to choose HOW that string is formatted at the point that it's assigned to the REPORT object property, it guarantees that the programmer CHOSE the string format that eventually gets written to the XML inside the *.TDR file that is saved.
Admittedly, this is not a perfect rationale. There is a default string syntax that is used when dragging and dropping channels interactively in DIAdem, which the programmer could set at any time, and this could be used automatically when assigning a channel object to a REPORT object property. Personally, I'd love to see a GetReference() method be added (with no parameters beyond the object variable) at every location where you currently have the Reference property. But I think you can imagine that this is lower priority than other items, given that there is a reasonable, if inelegant workaround.
The bottom line is that the REPORT object needs to be ready to convert any channel references to string representation at the drop of a hat. The current implementation forces the programmer to choose that representation with the extra effort of calling the Channel.GetReference() method. Ugly, but transparent and predictable.
Feel free to add a request to the DIAdem Idea Exchange (ni.com/diademideas),
Brad Turpin
DIAdem Product Support Engineer
National Instruments