- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I have to create a VBA macro for AutoCAD, but I'm no VBA expert.
The main purpose of the code is to plot dwg files to pdf file automatically
I want to use the acwindow as a plot type but I want the conversion to be automatic
So far I worked on this code, but you still have to insert the corners manually
code:
Public Sub Example_SetWindowToPlot()
Dim pdfFile As String
pdfFile = "D:\stage\output.pdf"
AppActivate ThisDrawing.Application.Caption
Dim point1 As Variant, point2 As Variant
' Get first point in window
point1 = ThisDrawing.Utility.GetPoint(, "Click the lower-left of the window to plot.")
ReDim Preserve point1(0 To 1)
' Get second point in window
point2 = ThisDrawing.Utility.GetPoint(, "Click the upper-right of the window to plot.")
ReDim Preserve point2(0 To 1)
ThisDrawing.ActiveLayout.SetWindowToPlot point1, point2
' Read back window information
ThisDrawing.ActiveLayout.GetWindowToPlot point1, point2
MsgBox "Press any key to plot the following window:" & vbCrLf & vbCrLf & _
"Lower Left: " & point1(0) & ", " & point1(1) & vbCrLf & _
"Upper Right: " & point2(0) & ", " & point2(1)
ThisDrawing.ActiveLayout.PlotType = acWindow
ThisDrawing.ActiveLayout.ConfigName = "DWG to PDF.pc3"
ThisDrawing.ActiveLayout.CanonicalMediaName = "ISO_A4_(210.00_x_297.00_mm)"
ThisDrawing.ActiveLayout.CenterPlot = True
ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
Dim result As Boolean
result = ThisDrawing.Plot.PlotToFile(pdfFile)
If result Then
MsgBox "Plotting to pdf file succeeded."
Else
MsgBox "Plotting to pdf file failed."
End If
End Sub
Solved! Go to Solution.