DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a curve to a graph with VBS

Solved!
Go to solution

I created a curve transformation script:

Sub Select_8(Context)
  Dim oMyDataContext
  Set oMyDataContext = Context.DataContext
  Select Case Context.DataType
    Case e2DCurveTransformDataTypeXY 
      Call ChnCopy  (oMyDataContext.XChannelNumberIn ,oMyDataContext.XChannelNumberOut) 'Copy the input channel into the output channel
      ChnEventList1 = ChnEventDetectionWindow("", data.GetChannel(oMyDataContext.YChannelNumberIn).ChannelGroup.Name & "/SetVoltage", 8, 8, 0, 0) 
      Call ChnEventCreateFilteredTrueChn( oMyDataContext.YChannelNumberOut, ChnEventList1, oMyDataContext.YChannelNumberIn, NOVALUE)
  End Select 
End Sub

Save code as vbs file and add this in script as user command in script. You can add more user command for 12 and 16 by replacing 8 with these numbers.

Now create your layout and make use of this user command for curve transformation:

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")  
  oMyObject.Settings.UseCurveTransformation =true
  Set oMyCurve = oMyObject.Curves2D.Add(e2DShapeLine,"Curve_" & index )
  oMyCurve.OnCurveTransformation = "Select_8"
  oMyCurve.Shape.XChannel.Reference="Daymode Off White LED`s/TempOven"
  oMyCurve.Shape.YChannel.Reference=MyArray(index)
  oMyCurve.Shape.Settings.ConnectNoValueNeighbors = True
Next
 
Call Report.Refresh()

 

Message 11 of 13
(523 Views)

Thank you very much Winfried!

0 Kudos
Message 12 of 13
(519 Views)

Hello Winfried,

 

I have another problem that I havent been able to solve and I am not getting any replies to the post I created on the subject. Maybe you can help me. I created a simple VI to open DIAdem, load the data, the report template and run the script. I can see DIAdem opening the report but not creating a pdf file as programmed in the script. When I run the script manually in DIAdem everything works fine after loading the data and report. After doing some research in the forums, I think that this line is what might be the problem but I cant seem to narrow the problem and fix it.

 

Dim PDFFile : PDFFile = DataReadPath&Data.Root.Name&".pdf"

 

I have attached the VI and a snip of the code.

 

' create PDF
Dim PDFFile : PDFFile = DataReadPath&Data.Root.Name&".pdf"

Call Report.Sheets.ExportToPDF(PDFFile,False)
If (Err.Number <> 0) Then
  Call MsgBoxDisp("Cannot create the PDF document.")
else
  ' show results in PDF reader
  If FileExist(PDFFile) Then Call ExtProgram("", PDFFile)
  If Err.Number <> 0 Then MsgBox "Cannot start the PDF Reader. Have you installed a PDF Reader on your computer?"
End If

0 Kudos
Message 13 of 13
(481 Views)