API Sample - VBA
This sample will create 2 different files of the current layout. The first one will be named after the drawing and will use the AcroPlot Jr. defaults. The second one will be in Monochrome, 11x17, Scaled-To-Fit and will be named after the drawing and Tabloid-Monochrome.
Sample VB/VBA Application Using the AcroPlotJ Methods
Sub TestCurrentLayout()
On Error Resume Next
Dim oAcroPlotApp As Object
Dim oAcadApp As AcadApplication
Dim sSettingName As String
Dim sOutputFile As String
'First try to get the AcroPlot Application Interface
'We'll use late binding to make it easier
Set oAcroPlotApp = CreateObject("AcroPlot.AcroPlotApplication")
If oAcroPlotApp Is Nothing Then
MsgBox "Unable to get the AcroPlot Application Interface"
Exit Sub
End If
'Get the current AutoCAD.Application Object
Set oAcadApp = ThisDrawing.Application
'Set the Settings Name use "AcroPlotJunior." for the last used settings in AcroPlot Jr.
sSettingName = "AcroPlotJunior"
'Set the output filename equal to the drawing name .pdf
sOutputFile = ThisDrawing.FullName
sOutputFile = Strings.Left$(sOutputFile, Len(sOutputFile) - 4) & ".pdf"
'Now we should set the Undo mark because if the layout was set to a printer that does
'not exist we cannot restore that due to AutoCAD limitations. But the Undo can.
ThisDrawing.StartUndoMark
'Now let convert the current layout
oAcroPlotApp.Init
'***************VERY IMPORTANT***************
'Provide the AcroPlot Auto unlock code here so the filename dialog does not popup.
'Other users will have the filename dialog popup per our standard licensing for the AcroPlot Suite, and will need to select the “Save As” button for each file created.
'***************VERY IMPORTANT***************
oAcroPlotApp.UnlockAPI "YOUR_REGISTRATION_CODE_FOR_ACROPLOT_AUTO"
oAcroPlotApp.RestoreSettings sSettingName
oAcroPlotApp.SetOutputFilename sOutputFile
oAcroPlotApp.AcroPlotJCurrent oAcadApp
'Now let's change the papersize to tablod, monochrome, and scaled to fit
sOutputFile = ThisDrawing.FullName
sOutputFile = Strings.Left$(sOutputFile, Len(sOutputFile) - 4) & "-Tabloid-Monochrome" & ".pdf"
oAcroPlotApp.SetOutputFilename sOutputFile
oAcroPlotApp.SetSetting "DwgPaperSize", 3
oAcroPlotApp.SetSetting "Grayscale", 1
oAcroPlotApp.SetSetting "PlotScale", 0
Err.Clear
oAcroPlotApp.AcroPlotJCurrent oAcadApp
'Release the AcroPlot Application
oAcroPlotApp.Quit
Set oAcroPlotApp = Nothing
'Now let's undo the changes
ThisDrawing.EndUndoMark
ThisDrawing.SendCommand "_u "
End Sub
Sample VB/VBA Application Using the Convert Method
To create or convert files using the command line mode API or ActiveX automation mode interface, it is required to purchase a license of AcroPlot Auto for each server running the process. If there will be additional PC's running AcroPlot Suite licenses or any of its components, then it is also required to purchase the number licenses needed in addition to the AcroPlot Auto server license.
Private Sub ConvertFile(ByVal sInputFile As String, ByVal sOutputFile As String, ByVal sSettingName As String)
On Error Resume Next
Dim oAcadObject As Object
Dim oAcroPlotApp As Object
Dim sFilesCreated As String
Dim bResults As Boolean
Dim lWait As Long
Dim lFilesOpened As Long
Dim lLoop As Long
Dim sConversionFinished As String
Set oAcroPlotApp = CreateObject("AcroPlot.AcroPlotApplication")
If oAcroPlotApp Is Nothing Then
MsgBox "Unable to get the AcroPlot Application Interface"
Exit Sub
End If
oAcroPlotApp.RestoreSettings sSettingName
'Now maybe we want to override the settings and make the output grayscale
oAcroPlotApp.SetSetting "Grayscale", 1
'Since we do not want to append to the end of the existing file we should delete it first if it exists. There should of coarse be some error checking here.
Kill sOutputFile
'Lets use our own internal converter for this first one.
oAcroPlotApp.SetSetting "UseInternalViewerForPlotting", -1
'Now we want to do the conversion modal so it will not return control to our application until it finishes.
Call oAcroPlotApp.Convert(sInputFile, sOutputFile, True, 0, False)
sFilesCreated = oAcroPlotApp.GetFilesCreatedAsString
'For the next ones let's use AutoCAD for the conversion.
oAcroPlotApp.SetSetting "UseInternalViewerForPlotting", 0
'Now let's say we want to test running it 200 times and having it close AutoCAD after 100 files
'We will also do this conversion modeless so we would need to have a loop to wait and check every second if the conversion is finished.
For lLoop = 0 to 199
'Since we do not want to append to the end of the existing file we should delete it first if it exists. There should of coarse be some error checking here.
Kill sOutputFile
Call oAcroPlotApp.Convert(sInputFile,sOutputFile, False, 0, False)
'Here now we want to wait until we write a value other than 0 to the HKEY_CURRENT_USER\Software\CADzation\ACROPLOT\API.ConversionFinished
'The ReadRegVal would be a wrapped function in VB or VBA to read a registry value
For lWait = 0 to 300
Sleep 1000 'Windows API function to wait specified number of milliseconds
sConversionFinished = ReadRegVal(HKEY_CURRENT_USER, "Software\CADzation\ACROPLOT", "API.ConversionFinished")
If sConversionFinished = "1" then
'Created the output file
Exit For
Else if sConversionFinished = "-1"
'Failed to create the output file
Exit For
End if
Next
If lFilesOpened < 100 then
lFilesOpened = lFilesOpened + 1
Else
lFilesOpened = 0
oAcroPlotApp.EndAutoCAD
End if
Next
'Now let's properly exit AcroPlot.Application
oAcroPlotApp.Quit
Set oAcroPlotApp = Nothing
End Sub