DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a curve to a graph with VBS

Solved!
Go to solution

Hello,

I am new to DIAdem and to VBS so I am having some trouble creating some very basic code. I am trying to plot curves from data in a tdms file to a graph on a report layout but am getting an error code as seen in the screenshot below. I can't figure it out and would be glad if someone could help me out.

 

Below I have an image of the error and my code.

 

Thanks!


Call Picdelete()
Call Report.LoadLayout("Test.tdr")
Call Report.Sheets(2).Activate

dim index

dim MyArray(5)
MyArray(0)= "Wavelength_1"
MyArray(1)= "Wavelength_2"
MyArray(2)= "Wavelength_3"
MyArray(3)= "Wavelength_4"
MyArray(4)= "Wavelength_5"


For index= LBound(MyArray) to UBound(MyArray)
  Call GraphObjOpen("Graph1")   
  Call GraphObjNew("2D-curve","Curve_1") 'Creates a new 2D-Curve object called -MyCurve- in the report
  Call GraphObjOpen("Curve_1")
    D2CCHNXNAME      ="Daymode Off White LED`s"/"TempOven"
    D2CCHNYNAME      ="Daymode Off White LED`s"/MyArray(index)
  Call GraphObjClose("Graph1")
Next
 
Call Picupdate()

0 Kudos
Message 1 of 13
(4,018 Views)

Hi alexkon

 

you use a mixture of the object oriented API and the old, obsolete commands. The following script should resolve the problems. In the help (that you could easily open from the autocomplition tooltips) shows you more examples. There might be small changes nessary depending on you layout.

Call Report.NewLayout
Call Report.LoadLayout("Test.tdr")
Call Report.Sheets(2).Activate

dim index

dim MyArray(5)
MyArray(0)= "Wavelength_1"
MyArray(1)= "Wavelength_2"
MyArray(2)= "Wavelength_3"
MyArray(3)= "Wavelength_4"
MyArray(4)= "Wavelength_5"

Dim oMyObject,oMyCurve
For index= LBound(MyArray) to UBound(MyArray)
  Set oMyObject = Report.ActiveSheet.Objects("Graph1")  
  Set oMyCurve = oMyObject.Curves2D.Add(e2DShapeLine,"Curve_1") 
  oMyCurve.Shape.XChannel="Daymode Off White LED`s"/"TempOven"
  oMyCurve.Shape.YChannel="Daymode Off White LED`s"/MyArray(index)
Next
 
Call Report.Refresh()

Winfried

0 Kudos
Message 2 of 13
(4,007 Views)

Hi, thank you for your reply!

 

I implemented the code but it didnt work as I wished. I got an error message stating that the Curve_1 already exists and another error that the object doesnt support the method:"Shape.YChannel". So I added the .Reference and that should have solved the proble. Although I am still getting the error that the "Curve_1" already exists.

 

Any Ideas?

 

The TDMS file and the layout is also attached.

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.
Call Report.NewLayout
Call Report.LoadLayout("Test.tdr")
Call Report.Sheets(2).Activate

dim index

dim MyArray(5)
MyArray(0)= "Daymode Off White LED's/Wavelength_1"
MyArray(1)= "Daymode Off White LED's/Wavelength_2"
MyArray(2)= "Daymode Off White LED's/Wavelength_3"
MyArray(3)= "Daymode Off White LED's/Wavelength_4"
MyArray(4)= "Daymode Off White LED's/Wavelength_5"

Dim oMyObject,oMyCurve
For index= LBound(MyArray) to UBound(MyArray)
  Set oMyObject = Report.ActiveSheet.Objects("Graph1")  
  Set oMyCurve = oMyObject.Curves2D.Add(e2DShapeLine,"Curve_1")
  oMyCurve.Shape.XChannel.Reference="Daymode Off White LED`s/TempOven"
  oMyCurve.Shape.YChannel.Reference= MyArray(index)
Next
 
Call Report.Refresh()

Download All
0 Kudos
Message 3 of 13
(4,001 Views)
Solution
Accepted by alexkon

Hi alexkon

 

you are absolutly right with the missing "reference". I made some small changes, and replace the ' with the ` in your names:

Call Report.NewLayout
Call Report.LoadLayout("Test.tdr")
Call Report.Sheets(2).Activate

dim index

dim MyArray(5)
MyArray(0)= "Daymode Off White LED`s/Wavelength_1"
MyArray(1)= "Daymode Off White LED`s/Wavelength_2"
MyArray(2)= "Daymode Off White LED`s/Wavelength_3"
MyArray(3)= "Daymode Off White LED`s/Wavelength_4"
MyArray(4)= "Daymode Off White LED`s/Wavelength_5"

Dim oMyObject,oMyCurve
For index= LBound(MyArray) to UBound(MyArray)-1
  Set oMyObject = Report.ActiveSheet.Objects("Graph1")  
  Set oMyCurve = oMyObject.Curves2D.Add(e2DShapeLine,"Curve_" & index )
  oMyCurve.Shape.XChannel.Reference="Daymode Off White LED`s/TempOven"
  oMyCurve.Shape.YChannel.Reference=MyArray(index)
Next
 
Call Report.Refresh()

Winfried

 

Message 4 of 13
(3,995 Views)

Thank your very much Winfried, its working perfectly!

0 Kudos
Message 5 of 13
(3,991 Views)

Is there a way to create a title for a graph from the actual name of the graph? At the moment I only see the option to create a text fiel above my graph and write the title in there.

0 Kudos
Message 6 of 13
(3,978 Views)

Hi Winfried,

I would be glad if you could help me out again. I have got to sort out the values in my channels as following: In each group I have a Channel named SetVoltage. In this Channel there are repeating Values of 8,12 and 16. Now before I plot a Curve on a Graph I want to be able to filter the Rows in the group by the value of the SetVoltage channel and then plot the curve. By doing this I want to avoid plotting data that doesnt belong together in a graph. I hope I made myself relatively clear and that you are able to help me or at least point me in the right direction, because at the moment I dont know how I can solve this problem.

 

Alex

0 Kudos
Message 7 of 13
(3,968 Views)

Hi alexkon

 

I anot sure if I understand your problem. This is what I understand:

You want to get all values from a channel, e.g. "[1]/Y_Value_1" for which the value Setvalutage has a specific value e.g. "8".

 

There are some event functions in DIAdem (in the "channel function" group of ANLYSIS). When you press ctrl-shift-c you will get the correspondig code of the dialog.

 

This is the code that might help you. Please refer to the help to get the explanation of the commands:

ChnEventList1 = ChnEventDetectionWindow("", "[1]/SetVoltage", 8, 8, 0, 0) 
Call ChnEventCreateFilteredTrueChn("[1]/Filtered_Channel_with_NV", ChnEventList1, "[1]/Y_Value_1", NOVALUE)

'If you want to remove the NoValues
Call ChnNovHandle("[1]/Filtered_Channel_with_NV", , "Delete", "X", True, 1, 0 )
Data.Root.ChannelGroups(1).Channels("Filtered_Channel_with_NV").Name = "Filtered_Channel_without_NV"

If this is not the problem please describe more in detail.

Winfried

0 Kudos
Message 8 of 13
(3,965 Views)

Hello, your solution is going in the right direction but is not quite what I wanted.

I will try to describe in more detail.

At the moment I am plotting from the above tdms file for example the channels TempOven to Wavelength_1 from the Group Daymode Off White LED's. Beside the channel TempOven there is another channel called SetVoltage which contains the repeating values of 8,12 and 16. If I now simply take the channels tempoven and Wavelength_1 and plot them in a graph the results will not be correct because I am plotting the values for wavelength_1 to tempoven for the 3 different voltage values at the same temperature.

What I want to be able to do is sort of filter the channel so that all rows where the value of set voltage is 12 or 16 will be removed and only the rows where set voltage is equal to 8 should be plotted on a graph. In that case it would be from the group daymode off white led's the values for tempoven and wavelength_1 where the setvoltage channel values only equal to 8.

An i want to repeat this for each voltage value before plotting a graph.

 

I hope I have made myself clear and hope that you can help me.

 

Alex

0 Kudos
Message 9 of 13
(3,962 Views)

Hi alexkon

 

I think you can simply apply the function to all channels you want to analyze. The following script will create a copy with all channels of group 1.

 

ChnEventList1 = ChnEventDetectionWindow("", "[1]/SetVoltage", 8, 8, 0, 0) 
dim oMyNewChnGroup, oMychn, sMyNewChnGroupName
Set oMyNewChnGroup = Data.Root.ChannelGroups.Add(Data.Root.ChannelGroups(1).Name & "_Filtered")
sMyNewChnGroupName = oMyNewChnGroup.Name
for each oMychn in Data.Root.ChannelGroups(1).Channels
    Call ChnEventCreateFilteredTrueChn(sMyNewChnGroupName & "/"& oMychn.Name, ChnEventList1, oMychn, NOVALUE)
Next

Now you can plot these new channel in your layout. If you like you can choose the setting "Connect curve points when NoValues occur" to get a line instead of single points.

Instead of creating a copy of the channels you could also use a curve transformation, to create temporary channels while you are plotting them.Have look at this help topic Object: D2CurveTransformingContext

Here is an example in the help: Example>Creating a Report > Extracting Bits Using Curve Transformation

 

Hope this helps

Winfried

 

0 Kudos
Message 10 of 13
(3,942 Views)