- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I’m trying to create a VBA macro to plot a specific area from the Model space in AutoCAD to a PDF file. The plot settings (e.g., plotter, paper size, plot style) are already configured, so I don’t need to set them again in the code. I only want to specify the coordinates of the area to plot and generate the PDF.
Here’s my current code, but I’m getting the error:
Error Number: 438, Description: Object doesn't support this property or method.
Sub TestPlotFromModel()
Dim fileName As String
fileName = "C:\Temp\ModelAreaPlot.pdf" ' Specify the output PDF file name
' Coordinates of the plot area (example values)
Call PlotSelectedAreaFromModel(fileName, 0, 0, 420, 297)
End Sub
Sub PlotSelectedAreaFromModel(plotFileName As String, lowerLeftX As Double, lowerLeftY As Double, upperRightX As Double, upperRightY As Double)
On Error GoTo ErrorHandler
' Disable background plotting
ThisDrawing.SetVariable "BACKGROUNDPLOT", 0
' Switch to Model space layout
ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Model")
' Set the plot window using the coordinates
ThisDrawing.ActiveLayout.SetWindowToPlot Array(lowerLeftX, lowerLeftY), Array(upperRightX, upperRightY)
' Plot directly to the specified file
Debug.Print "Plotting to: " & plotFileName
ThisDrawing.Plot.PlotToFile plotFileName
' Notify user
Debug.Print "PDF generated successfully: " & plotFileName
Exit Sub
ErrorHandler:
Debug.Print "Error Number: " & Err.Number & ", Description: " & Err.Description
Err.Clear
Exit Sub
End Sub
Solved! Go to Solution.