54
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*****************************************************
'If you have a 50 user or site license then use the unlock code we provide you here so the filename dialog does not
popup.
'Other users will have the file dialog popup per our standard licensing which only allows full access to the API for
50 and more users.
'**********************************************VERY IMPORTANT*****************************************************
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 "