Plot to pdf automaticaly using acwindow as a plotType

Plot to pdf automaticaly using acwindow as a plotType

wianeh6700
Participant Participant
1,662 Views
4 Replies
Message 1 of 5

Plot to pdf automaticaly using acwindow as a plotType

wianeh6700
Participant
Participant

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

 

 

0 Likes
Accepted solutions (1)
1,663 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> but you still have to insert the corners manually

Well, how could the coordinates be found by your program?

When you ask the user to input lower left point ... how is the user specifying this point?
Do any rules exist to find this point automatically?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

wianeh6700
Participant
Participant

Hi, thank u for answering

I'm wondering if i can draw a frame or create a layer that contains the limits, is this possible ??

0 Likes
Message 4 of 5

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

>> I'm wondering if i can draw a frame or create a layer

>> that contains the limits, is this possible ??

Yes, then you need to either create a selection-set for polylines on this layer (or scan the model-space for such items), then get the extents of these polylines and use them to evaluate lower-left and upper-right point.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 5

maratovich
Advisor
Advisor

It may be easier for you to use a ready-made solution - Revers 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes