I created the following to print autocad files. My only problem is that it won't work on a layout that has not been initialized. When this code switches to an un-initialized layout the page setup dialog appears.
Unfortunatly, all the plot properties of the layout don't appear any different from an initialized layout. So you can't tell via properties if the layout is initialized.
Does anyone know a way to tell if a layout is not initialized? I'll just skip those in the case that the user picks "ALL" layouts.
=========================================================
Public Function PlotDWG(strFile As String, _
PlotID As String,Optional intCopies As Integer=1, _ Optional strSize As String = "Letter", _
Optional intScale As Integer = 100, _
Optional intRotation As Integer = 0, _
Optional strDevice As String = "Default", _
Optional strPages As String = "ALL", _
Optional strDescription As String = "",
Optional strOwner As String = "") As String
'NOTE: return value is the resulting Status ("OK", "NoFile", etc...)
Dim objAutoCAD As AutoCAD.AcadApplication
Dim objDocument As AutoCAD.AcadDocument
Dim objPlotConfig As AutoCAD.AcadPlotConfiguration
Dim arrLayouts As Variant
On Error GoTo GenError
GetAutoCADRef objAutoCAD
objAutoCAD.Visible = True
'open strFile in autocad
Set objDocument = objAutoCAD.Documents.Open(strFile, True)
'TODO: copy appropriate PSS file to PSS file location
objDocument.Plot.NumberOfCopies = intCopies
Select Case strPages
Case "All"
For i = 0 To objDocument.Layouts.Count - 1
'TODO: if layout is not configured, it
' brings up a dialog
MsgBox objDocument.Layouts.Item(i).ConfigName
SetAcadLayoutPlotProps objDocument.Layouts. _
Item(i), strSize, intScale, intRotation, _
strDevice
objDocument.ActiveLayout = _
objDocument.Layouts.Item(i)
objDocument.Plot.PlotToDevice
Next
Case Else
If strPages = "*Current*" Or _
strPages = "Current" Then
strPages = objDocument.ActiveLayout.Name
End If
For i = 0 To objDocument.Layouts.Count - 1
SetAcadLayoutPlotProps objDocument.Layouts. _
Item(i), strSize, intScale, intRotation, _
strDevice
If objDocument.Layouts.Item(i).Name=strPages Then
objDocument.ActiveLayout = _
objDocument.Layouts.Item(i)
End If
Next
objDocument.Plot.PlotToDevice
End Select
'close drawing
If Not objDocument.Saved Then
objDocument.SaveAs gAppPath & "junk.dwg"
End If
objDocument.Close
PlotDWG = "OK"
Exit Function
GenError:
Debug.Print CStr(Err.Number) & ":" & Err.Description
Err.Clear
CloseAutoCADRef objAutoCAD
PlotDWG = PlotAnyFile(strFile, PlotID, intCopies, _
strSize, intScale, intRotation, strDevice, _
strPages, strDescription, strOwner)
End Function
=========================================================