Skip to content

Commit 7ca6747

Browse files
committed
Actually fixed #2, including folder access permissions. Opening DevMenu now updates exported script.
1 parent a8a8ae2 commit 7ca6747

File tree

2 files changed

+54
-36
lines changed

2 files changed

+54
-36
lines changed

DevExport/ClassScript-Project.vb

+54-36
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ Public Sub DevMenu_Show(Optional pXFolder As CscXFolder=Nothing, Optional pXDoc
144144

145145
If Not IsDesignMode() Then Exit Sub
146146

147+
' Keep an exported copy of the project script updated.
148+
' Called via eval and ignoring errors so this will work if it is in the project, and no error if it is not.
149+
On Error Resume Next
150+
Eval("Dev_ExportScriptAndLocators()")
151+
On Error GoTo 0
152+
147153
Debug.Clear
148154
Dim Choices(1000) As String, Choice As Integer, Items As Dictionary
149155
Set Items=DevMenu_Items()
@@ -222,8 +228,14 @@ Public Sub DevMenu_Execute(sf As ScriptFunction, Optional pXFolder As CscXFolder
222228
Set Param1=pXFolder
223229
Else
224230
If Not pXDoc Is Nothing Then
225-
Debug.Print("Executing function using parent folder of xdoc.")
226-
Set Param1=pXDoc.ParentFolder 'This might not be valid for a function that tries to modify the folder
231+
Debug.Print("Executing function using parent folder of xdoc (overriding single-document mode and folder access permissions).")
232+
' Normally if you go to the parent folder from a doc level event, then back down through the xdocinfos to the xdocs,
233+
' that would result in an error saying that it is not currently possible to access documents.
234+
' Disabling single doc mode will allow access to the xdocs
235+
' These commands are unsupported and have high potential to cause problems: They should never be touched at runtime.
236+
pXDoc.ParentFolder.SetSingleDocumentMode(False)
237+
pXDoc.ParentFolder.SetFolderAccessPermission(255)
238+
Set Param1=pXDoc.ParentFolder
227239
End If
228240
End If
229241
End Select
@@ -284,61 +296,65 @@ End Function
284296

285297
' Functions to test from DevMenu
286298

287-
Public Sub ExportPagesAsTiffs(pXDoc As CscXDocument)
288-
Dim fso As New FileSystemObject
289-
Dim ExportPath As String
290-
ExportPath=Project.ScriptVariables("ExportPath")
291-
292-
If Not fso.FolderExists(ExportPath) Then ExportPath=fso.BuildPath(fso.GetFile(Project.FileName).ParentFolder, "ExportedImages")
293-
If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
299+
Public Sub FolderAsTiffs(pXFolder As CscXFolder)
300+
Dim DocIndex As Integer
301+
For DocIndex=0 To pXFolder.GetTotalDocumentCount()-1
302+
Debug.Print("Executing on document " & DocIndex+1 & "/" & pXFolder.DocInfos.Count())
303+
ExportDocAsMultipageTiffs(pXFolder.DocInfos(DocIndex).XDocument)
304+
Next
305+
End Sub
294306

295-
' Create a folder for this document named by the filename of the first source file
296-
Dim DocName As String
297-
DocName=fso.GetBaseName(pXDoc.CDoc.SourceFiles(0).FileName)
298-
ExportPath=fso.BuildPath(ExportPath,DocName)
299-
If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
307+
Public Sub ExportDocAsIndividualTiffs(pXDoc As CscXDocument)
308+
ExportDocAsTiff(pXDoc, GetExportPath(), False)
309+
End Sub
300310

301-
Debug.Print("Exporting " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
302-
Dim PageIndex As Integer
303-
For PageIndex=0 To pXDoc.CDoc.Pages.Count-1
304-
If (PageIndex+1) Mod 10 = 0 Then Debug.Print(" Processing page " & PageIndex + 1 & "/" & pXDoc.CDoc.Pages.Count & " from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
305-
pXDoc.CDoc.Pages(PageIndex).GetImage().Save(fso.BuildPath(ExportPath,DocName & "-Page-" & Format(PageIndex+1,"000") & ".tif"),CscImgFileFormatTIFFOJPG)
306-
pXDoc.CDoc.Pages(PageIndex).UnloadImage()
307-
Next
308-
Debug.Print("Finished " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
311+
Public Sub ExportDocAsMultipageTiffs(pXDoc As CscXDocument)
312+
ExportDocAsTiff(pXDoc, GetExportPath(), True)
309313
End Sub
310314

311-
Public Sub ExportPagesAsMultipageTiff(pXDoc As CscXDocument)
312-
' Saves a doc as a multipage tiff
315+
Public Function GetExportPath() As String
313316
Dim fso As New FileSystemObject
314317
Dim ExportPath As String
315318
ExportPath=Project.ScriptVariables("ExportPath")
316319

317320
If Not fso.FolderExists(ExportPath) Then ExportPath=fso.BuildPath(fso.GetFile(Project.FileName).ParentFolder, "ExportedImages")
318321
If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
322+
Return ExportPath
323+
End Function
319324

320-
' Multipage document named by the filename of the first source file
325+
Public Sub ExportDocAsTiff(pXDoc As CscXDocument, ExportPath As String, Optional MultiPage As Boolean=True)
326+
Dim fso As New FileSystemObject
321327
Dim DocName As String, TempPath As String, TiffPath As String
322328
DocName=fso.GetBaseName(pXDoc.CDoc.SourceFiles(0).FileName)
323-
TiffPath=fso.BuildPath(ExportPath,DocName & ".tif")
324-
TempPath=TiffPath & ".tmp"
329+
If MultiPage Then
330+
' Multipage document named by the filename of the first source file
331+
TiffPath=fso.BuildPath(ExportPath,DocName & ".tif")
332+
TempPath=TiffPath & ".tmp"
333+
Else
334+
' Create a folder for this document named by the filename of the first source file
335+
ExportPath=fso.BuildPath(ExportPath,DocName)
336+
If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
337+
End If
338+
325339

326340
Debug.Print("Exporting " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
327341
Dim PageIndex As Integer, img As CscImage, imgformat As CscImageFileFormat
328342
For PageIndex=0 To pXDoc.CDoc.Pages.Count-1
329343
If (PageIndex+1) Mod 10 = 0 Then Debug.Print(" Processing page " & PageIndex + 1 & "/" & pXDoc.CDoc.Pages.Count & " from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
330-
Set img=pXDoc.CDoc.Pages(PageIndex).GetImage()
331-
imgformat=IIf(img.BitsPerSample=1 And img.SamplesPerPixel=1,CscImageFileFormat.CscImgFileFormatTIFFFaxG4,CscImageFileFormat.CscImgFileFormatTIFFOJPG)
332-
333-
img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepFileOpen, TempPath, 0, 0)
334-
img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepExistingPages, TempPath, 0, 0)
335-
img.Save(TempPath, imgformat)
336344

337-
338-
pXDoc.CDoc.Pages(PageIndex).UnloadImage()
345+
If MultiPage Then
346+
Set img=pXDoc.CDoc.Pages(PageIndex).GetImage()
347+
imgformat=IIf(img.BitsPerSample=1 And img.SamplesPerPixel=1,CscImageFileFormat.CscImgFileFormatTIFFFaxG4,CscImageFileFormat.CscImgFileFormatTIFFOJPG)
348+
img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepFileOpen, TempPath, 0, 0)
349+
img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepExistingPages, TempPath, 0, 0)
350+
img.Save(TempPath, imgformat)
351+
Else
352+
pXDoc.CDoc.Pages(PageIndex).GetImage().Save(fso.BuildPath(ExportPath,DocName & "-Page-" & Format(PageIndex+1,"000") & ".tif"),CscImgFileFormatTIFFOJPG)
353+
pXDoc.CDoc.Pages(PageIndex).UnloadImage()
354+
End If
339355
Next
340356

341-
If pXDoc.CDoc.Pages.Count>0 Then
357+
If MultiPage And pXDoc.CDoc.Pages.Count>0 Then
342358
' Close the multipage tiff file that was kept open
343359
Set img=pXDoc.CDoc.Pages(0).GetImage()
344360
img.StgFilterControl(CscImageFileFormat.CscImgFileFormatTIFFFaxG4, CscStgControlOptions.CscStgCtrlTIFFCloseFile, TempPath, 0, 0)
@@ -352,6 +368,8 @@ Public Sub ExportPagesAsMultipageTiff(pXDoc As CscXDocument)
352368
Debug.Print("Finished " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+1 & " (" & DocName & ")")
353369
End Sub
354370

371+
372+
355373
Private Sub Batch_Open(ByVal pXRootFolder As CASCADELib.CscXFolder)
356374
' Invoke DevMenu by testing the Batch_Open function (lightning bolt)
357375
DevMenu_Show(pXRootFolder)

Project/DevMenu.fpr

183 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)