Sunday, January 5, 2014

OnBase VB Script and Thick Client API to export all image pages

Link to other onbase scripts.

Below is an OnBase VB Script and Thick Client API to export all of an image's pages:

Sub Main35()

Dim objApplication, objCurrentDocument
Set objApplication = CreateObject("OnBase.Application")
Set objCurrDoc = objApplication.CurrentDocument
Dim filePath, memHandle, MZ_LOCALPATH, MZ_MULT_TIF4
memHandle = 0

Dim exportDirectory
exportDirectory = "\\share location\"

Dim mzApiSessionHandle, mzAPI
mzApiSessionHandle = ScriptAPI.Session
Set mzAPI = ScriptAPI.Object
Dim returnCode : returnCode = 0

'MsgBox "objCurrDoc.Handle is-" & objCurrDoc.Handle

returnCode = mzAPI.mzInitQueryByDocumentID(mzApiSessionHandle, objCurrDoc.Handle)
'MsgBox "1 returnCode is-" & returnCode

Dim mzApiQueryHandle
mzApiQueryHandle = returnCode
returnCode = mzAPI.mzExecuteQuery(mzApiQueryHandle, 0)
'MsgBox "2 returnCode is-" & returnCode

Dim returnDocumentHandle, outDocumentName, outDocumentType, outDocumentDate, outFileFormat, outRevision, outComment, msg

returnCode = mzAPI.mzGetDocumentInfo(mzApiQueryHandle, MZ_FIRST, outDocumentName, outDocumentType, outDocumentDate)
returnDocumentHandle = returnCode

Dim fileExtension, returnedFilePath
fileExtension = "TIF"

returnCode = mzAPI.mzGetDocumentPage(mzApiQueryHandle, returnDocumentHandle, -1, "Image File Format", 0, 1, 8, returnedFilePath, memHandle)
'MsgBox "returnCode: " & returnCode & vbcrlf & "returnedFilePath: " & returnedFilePath
returnCode = mzAPI.mzEndQuery(mzApiQueryHandle)
Set mzAPI = Nothing

Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile returnedFilePath, exportDirectory & objCurrDoc.Handle & ".TIF"
Set fso = Nothing

End Sub


Riyad Mammadov said...

Hi, thanks for posting the script. Will it work with an encrypted document?

John F Webber said...

You can try it. I would move to Unity for more robust options.