DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

can't open datafile after Export to pdf

Hello,

 

I have an issue with my script.
I generate some channels and fill them with values of different files. When this process is done I load a report file and generate automatically different reports with changing X-Y axis. Before each change I export the ActiveSheet into a PDF document with the export to PDF (true) command.

So now i have the issue that sometimes the PDF File can't be opened after my script is finished.

PDF Adobe Reade gives me the message "There was an error opening this document. The file is damaged and could not be repaired."

I tried already the
Call DocStart .... Call DocEnd command but didn't solve the issue.

 

When I tried the command Call Export to PowerPoint I got once the meesage that he can't do the command because the file is already opened. But normally only the script itselfe access the file while my script is running.

 

So i also thought about a waiting time or a waiting loop for the pdf export but still the same issue.

 

0 Kudos
Message 1 of 5
(868 Views)

The "True" argument appends the report sheet to the PDF file.  It works even if the file doesn't already exist.

 

Call Report.ActiveSheet.ExportToPDF(sFilePathPdf, TRUE)

 

Please try running the script below and see if you still have the error.  I ran this in DIAdem 2019 script panel.  I assume you are running your script in DIAdem?    Also, try opening the .pdf file with something other than Adobe PDF reader.  Lots of free and browser based reader options available.  Adobe may be trying to read and index the contents of the PDF file you are creating.  If you have Adobe software running in the Windows tray, try stopping or shutting it down.

 

More DIAdem solutions available at www.SavvyDIAdemSolutions.com

 

Option Explicit
Call LogFileDel()
Dim sFilePathPdf, iRptSht
Const bAppendRpt = True
sFilePathPdf = SHGetFolderPath(&H0005) & "DIAdemRptChartAppended.pdf"
If FileExist(sFilePathPdf) Then Call FileDelete(sFilePathPdf)
For iRptSht = 1 To 3
'Create a Report sheet 2D chart with DateTime X-Axis
Call bCreateRpt2DChart(iRptSht)
Call Report.Refresh()
Call LogFileWrite("Appending report sheet # " & Str(iRptSht) & " to " & sFilePathPdf)
Call Report.ActiveSheet.ExportToPDF(sFilePathPdf, bAppendRpt)
Next
Call WndShow("SCRIPT")

Function bCreateRpt2DChart(ByVal iRptSht)
'Load a single numeric time channel + three numeric data channels "Speed","RPM","Torque"
Call Data.Root.Clear(): Portal.NoOfGroupsToExpand = 1
If FileExist(sFilePathDIAdemExample("Example.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdm"),"TDM","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example.tdms")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdms"),"TDMS","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example_data.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example_data.tdm"),"TDM","[1]/*")
Else
Call LogFileWrite("DIAdem example files cannot be found")
End If
Dim oGrp, oChnTime, oChnDateTime, oChnX, oChnY
Dim oRptSht, oRptObj, oCurve2D, iCurve, oElement, eNSystemsMode
Set oGrp = Data.Root.ChannelGroups("Example")
Set oChnTime = oGrp.Channels("Time")

'Create a DateTime channel of type time
Set oChnDateTime = oGrp.Channels.AddChannel(oChnTime, 2)
oChnDateTime.Name = "DateTime"
'NOTE: This data doesn't have any absolute date/time reference, including time zone.
' If you have an absolute reference, it should be included with your data.
' The absolute reference of the storage date/time will be used for this example.
Call ChnNumericToTime(oChnDateTime, Data.Root.Properties("datetime").Value, False)
Call ChnCharacterAll()
'Call LogFileWrite("oChnDateTime.Minimum = " & Str(oChnDateTime.Minimum,"#dd-ttt-yyyy hh:nn:ss,ffff AMPM") & " = " & oChnDateTime.Minimum & " sec since 1 Jan 0000" )

'I like to generalize the Report 2D chart channel references to oChnX and oChnY
Set oChnX = oChnDateTime: Set oChnY = oGrp.Channels("Speed")
Call Report.NewLayout()

'Add a new Report sheet
Set oRptSht = Report.Sheets.Add(sGetUniqueReportSheetName("2dChtDateTimeXaxis","")): Call Report.Refresh()
'Create the 2D chart
Set oRptObj = oRptSht.Objects.Add(eReportObject2DAxisSystem, "2DAxisNSystems")
oRptObj.Position.ByCoordinate.X1 = 12
oRptObj.Position.ByCoordinate.X2 = 95
oRptObj.Position.ByCoordinate.Y1 = 22
oRptObj.Position.ByCoordinate.Y2 = 84
'Frame the grid
oRptObj.Settings.Grid.DisplayMode=e2DAxisGridModeFrame

iCurve = 0
iCurve = iCurve + 1
Set oCurve2D = oRptObj.Curves2D.Add(e2DShapeLine, "2DCurve" & str(iCurve))
oCurve2D.Shape.XChannel.Reference = oChnX.GetReference(eRefTypeIndexIndex)
oCurve2D.Shape.YChannel.Reference = oChnY.GetReference(eRefTypeIndexIndex)

'X-Axis label
oRptObj.XAxis.Label.Text = "@@ChnName(CurrChnNo)@@ [@@ChnDim(CurrChnNo)@@]"
oRptObj.XAxis.Label.Text = oChnX.Name & " [" & oChnX.UnitSymbol & "]"
oRptObj.XAxis.Label.UseCurveColor = False
oRptObj.XAxis.Label.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.XAxis.Numbers.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.XAxis.Numbers.Format = "#dd-ttt-yyyy hh:nn:ss.ffff"
oRptObj.XAxis.Numbers.Font.Size = 2.2
oRptObj.XAxis.Numbers.Angle = 45
oRptObj.XAxis.Numbers.RelativePosition=eRelativePositionLeftBottom
oRptObj.XAxis.Scaling.AutoScalingType = eAxisAutoScalingCompleteAutomatic
oRptObj.XAxis.Scaling.Begin = oChnX.Minimum
oRptObj.XAxis.Scaling.End = oChnX.Maximum
oRptObj.XAxis.Scaling.MiniTickCount = 1
oRptObj.XAxis.Scaling.Type = e2DXScalingLinear

'Show the Y-Axis labels if eNSystemsMode = e2DAxisNSystems
eNSystemsMode = e2DAxisNSystems
If eNSystemsMode = e2DAxisNSystems Then
oRptObj.YAxis.Label.Text = "@@ChnName(CurrChnNo)@@ [@@ChnDim(CurrChnNo)@@]"
Else
oRptObj.CurveLegend.Visible = True
oRptObj.CurveLegend.Frame.Visible = False
oRptObj.CurveLegend.Position.InteractiveMoveMode=eLegendMoveAutomatic
oRptObj.CurveLegend.Position.RelativePosition = eLegendRelativePositionTopLeft
oRptObj.CurveLegend.Position.SizeMode =eLegendSizeElementwise
oRptObj.CurveLegend.Position.Anchor.Type=eLegendAnchorTypePageRelated
oRptObj.CurveLegend.Position.Anchor.PageRelatedX = 75
oRptObj.CurveLegend.Position.Anchor.PageRelatedY = 90
oRptObj.CurveLegend.Settings.UseAutoFontSize = False
oRptObj.CurveLegend.Settings.Font.Size = 3.0
End If
oRptObj.Settings.NSystemsMode = eNSystemsMode
oRptObj.YAxis.Label.UseCurveColor = False
oRptObj.YAxis.Label.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.YAxis.Numbers.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.YAxis.Scaling.AutoScalingType=eAxisAutoScalingCompleteAutomatic

'Title
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptTitle")
oRptObj.Font.Size = 6
oRptObj.Font.Bold = True
oRptObj.PositionXY.X = 52.132
oRptObj.PositionXY.Y = 95.648
oRptObj.PositionXY.RelativePosition = eRelativePositionCenter
oRptObj.Text = "2D Chart With DateTime X-Axis - Page #" & Str(iRptSht)
Set oRptObj = Nothing

'Sub Title
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptSubTitle")
oRptObj.Font.Size = 5
oRptObj.PositionXY.X = 52.132
oRptObj.PositionXY.Y = 89.824
oRptObj.PositionXY.RelativePosition = eRelativePositionCenter
oRptObj.Text = "www.SavvyDIAdemSolutions.com"
Set oRptObj = Nothing

'Metadata at upper right
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptMetadata")
oRptObj.Font.Size = 2
oRptObj.PositionXY.X = 97
oRptObj.PositionXY.Y = 97
oRptObj.PositionXY.RelativePosition =eRelativePositionLeftBottom
oRptObj.Text = Str(Now(),"#dd-ttt-yyyy") & vbCrLf & Data.Root.Name
Set oRptObj = Nothing

Call oRptSht.Activate()
Set oRptSht = Nothing: Set oCurve2D = Nothing: Set oElement = Nothing
End Function 'bCreateRpt2DChart()


'===============================================================================
' Helper functions

Function sFilePathDIAdemExample(ByVal sFilename)
'Returns the full absolute file/path for the location of the DIAdem
'example (TDM/TDMS) file sFilename. Looks in the usual places.
'Returns "" if the file cannot be found.
sFilePathDIAdemExample = ""
Dim arrFilePaths, sFilePath, sFolder
ReDim arrFolders(1)
arrFolders(0) = ProgramDrv
arrFolders(1) = CommonDocumentsPath
Call MsgLineDisp("Searching DIAdem examples for file '" & sFilename & "'..")
For Each sFolder In arrFolders
arrFilePaths = DirListGet(sFolder,sFilename,"Date/Time","FullFilenamesRecursive")
If IsArray(arrFilePaths) Then
For Each sFilePath In arrFilePaths
If InStr(1,sFilePath,"Libr",vbTextCompare) = 0 Then
sFilePathDIAdemExample = sFilePath
Exit For
End If
Next
End If
If Len(sFilePathDIAdemExample) > 0 Then Exit For
Next
If IsArray(arrFilePaths) Then Call Erase(arrFilePaths)
If IsArray(arrFolders) Then Call Erase(arrFolders)
Call MsgLineDisp(vbTab)
End Function 'sFilePathDIAdemExample()


Function sGetUniqueReportSheetName(ByVal sPrefix, ByVal sSuffix)
'Returns a unique View sheet name with
'optional parameters sPrefix and sSuffix included in the
'new sheet name.
sGetUniqueReportSheetName = ""
Dim sSheet, i
i = 0
Do
If i = 0 Then
sSheet = Trim(sPrefix) & Trim(sSuffix)
Else
sSheet = Trim(sPrefix) & Trim(sSuffix) & Str(i)
End If
i = i + 1
Loop Until Not Report.Sheets.Exists(sSheet)
sGetUniqueReportSheetName = sSheet
End Function 'sGetUniqueReportSheetName()

 

 

 

 

0 Kudos
Message 2 of 5
(814 Views)

Hello markwkiehl,

 

thanks a lot for you response.

Yes I know that the "Call Report.ActiveSheet.ExportToPDF(sFilePathPdf, TRUE)" command true creates a PDF file and add new pages to that.

Normally I had run the script before on Diadem 2018 and a Windows 7 System. In the last month we got an update to Windows 10 and with that I installed the Diadem 2019 version to be up to date.

 

When I run your script you would delete always the file. So when i commend the command:

If FileExist(sFilePathPdf) Then Call FileDelete(sFilePathPdf)

The file couldn't be opened after the second run.


I deleted now adobe but the failure still exist. Now even with you command to delete the existing file I get the issue that the file couldn't be opened.

 

If I run the script I can see when Diadem needs more time to do the export process the data file gets a failure and can't be opened.

0 Kudos
Message 3 of 5
(793 Views)

Hi hier,

 

DIAdem allows you to use the built-in PDF file writer that Windows 10 installs.  Check out the DIAdem Settings for REPORT and try checking or unchecking the "Create PDF files with Microsoft printer" checkbox.  While you're there, you could also try "Output print data as graphic".  I haven't heard of the exact issue you've run into, but I want to make sure you've tried these 2 checkboxes in all for permutative states.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 5
(767 Views)

Hello Turbin,

you tips didn't work.
With Microsoft PDF Export you always only get 1 sheet in the file at the end.

Also the graphic output didn't changed anything.

dim i
for i =1 to 3

Call Report.ActiveSheet.Exporttopdf("",true)

next

 

But with you tip i got a new idea:

At first I thought that this has something to do with the change from win7 to win10 because now the system allready has a included PDF print function instead of the old windows were we had PDF creator additionaly. But the changes to use for Diadem PDF Export function different PDF software systems didn't get the needed solution.

Then I realized that with the Diadem 2019 software you changed the Export to PDF drivers from Amyuni 550 to 600.
I saw that because I had to delet my diadem 2019 the reason for that were that i destroyed some files from the amyuni plugin.

My solution:
1. Install Diadem 2018 (So it would be good if you still could download older versions from your website)
2. Install 2019 it overrides the Diadem PDF Export (printer)
3. In preferences --> Printer&scanner -->delet Diadem PDF Export
4. Go to Diadem2018 folder and use DiademStart.exe
--> So then in the Diadem PDF Export (printer) is still the Amyuni 550 instead of the Amyuni 600

0 Kudos
Message 5 of 5
(745 Views)