Batchplot

Discussion in 'AutoCAD' started by Gilles, Jun 24, 2003.

  1. Gilles

    Gilles Guest

    Hi all,

    This code is the one I found in the Autocad 2002 VBAHelp. I tried to adapt
    it to my needs but unsucsefully......
    The original code passes through all layouts existing in the drawing and ask
    if you want to plot it. Working perfectly.
    What I am trying to do is filter out some specific layouts named for example
    "A3 1-200*". I marked my modifications (very simple) in the code by some "
    **** ".
    When I do that in the code, only one of them gets plotted. Does anyone know
    why???

    Thanks in advance for your attention,


    Gilles


    Code begins
    ****************************************************
    Sub SetLayoutsToPlot()
    ' This example creates a Circle in model space and allows the user
    ' to select which layouts for the drawing to plot. It then uses
    ' a batch operation to send the selected layouts to the current
    ' plot device and allows the user to cancel the batch plot at certain
    ' intervals.

    Dim Plot As AcadPlot
    Dim AddedLayouts() As String
    Dim LayoutList As Variant
    Dim Layout As AcadLayout
    Dim ArraySize As Integer, BatchCount As Integer

    ' Prompt user for Layouts to plot
    For Each Layout In ThisDrawing.Layouts
    If Layout.Name Like "A3 1-200*" Then '**** **** **** ****
    **** **** **** **** **** **** **** ****
    If MsgBox("Do you wish to plot the layout: " & Layout.Name,
    vbYesNo) = vbYes Then
    ArraySize = ArraySize + 1
    ReDim AddedLayouts(1 To ArraySize)
    AddedLayouts(ArraySize) = Layout.Name
    End If
    '**** **** **** **** **** **** **** **** **** **** **** ****
    End If
    Next

    ' If the user did not select any Layouts to plot then exit
    If ArraySize = 0 Then
    MsgBox "There was no Layout selected"
    Exit Sub
    End If

    ' Send the array list containing the layout names to a variant
    ' which is compatible with SetLayoutsToPlot
    LayoutList = AddedLayouts

    ' Get the plot object from the drawing
    Set Plot = ThisDrawing.Plot

    ' Set plot options
    Plot.QuietErrorMode = False ' We do want to be notified of errors
    ' * Note: Normally, in a batch
    situation, you do
    ' not want to be notified of errors,
    since this
    ' will halt the batch process.

    Plot.NumberOfCopies = 1 ' We only need one copy

    ' Start the batch plot the selected layouts

    Plot.StartBatchMode ArraySize ' Number of items in this batch

    For BatchCount = 1 To ArraySize
    ' This must be called every time we call PlotToDevice
    Plot.SetLayoutsToPlot LayoutList

    ' Plot to default device
    Plot.PlotToDevice

    ' Display the results of the batch plot. This property should
    really be
    ' displayed to and set from a VBA Form, but for this example, we
    will
    ' use a message box
    If Plot.BatchPlotProgress Then
    If MsgBox("Would you like to cancel the batch plot?", vbYesNo) =
    vbYes Then
    Plot.BatchPlotProgress = False
    End If
    Else
    MsgBox "The batch plot has finished!"
    End If
    Next

    MsgBox "Finished plotting the selected Layouts!"
    End Sub

    ****************************************************
    Code ends
     
    Gilles, Jun 24, 2003
    #1
  2. Gilles

    Gilles Guest

    Thanks Mark,


    Working nearby perfectly. Now I get all my layouts plotted BUT 2
    times........ :)
    Once not enough, once too much.....
    You know what is happening?


    Gilles
     
    Gilles, Jun 24, 2003
    #2
  3. Gilles

    Mark Propst Guest

    For BatchCount = 1 To ArraySizeyou're printing once for each layout in your list?
    :)
     
    Mark Propst, Jun 24, 2003
    #3
  4. Gilles

    Gilles Guest

    Mark,

    That's what I am trying to do...
    Have only one plot for each selected layout !

    And now, it works fine... Thanks a lot

    I deleted the "For BatchCount = 1 To ArraySize"

    Don't understand why it was coded like this in the help...

    (It was very bad for the paper roll...) ;-)


    Gilles
     
    Gilles, Jun 24, 2003
    #4
  5. Gilles

    Mark Propst Guest

    Yeah, the help files can be very useful to get the idea of how things are
    done, but you have to really study each line to see if it's what you want in
    your application.
    Unfortunately there's also lots of stuff that's just plain wrong and when
    you're trying to learn (like me) it's really tough to figure out which is
    which.
    Thank goodness for this ng!
     
    Mark Propst, Jun 24, 2003
    #5
  6. Unfortunately there's also lots of stuff that's just plain wrong ...

    Yeah, it's pretty obvious that the examples don't all get tested, since the
    msgbox in this one didn't even have the intended buttons. Of course, it's
    great that they are available for almost every command in the help file, and
    I've used them a lot.

    But to make them even better, Autodesk should run a beta-tester/editor
    program for the next help file, and farm out the various subroutines to
    different people to debug. After you get your name immortalized in online
    help credits... why, you can die a happy wo/man


    Here's the corrected example for SetLayoutsToPlot, free for Adesk's taking.

    Sub Example_SetLayoutsToPlot()
    ' This example creates a Circle in model space and allows the user
    ' to select which layouts for the drawing to plot. It then uses
    ' a batch operation to send the selected layouts to the current
    ' plot device and allows the user to cancel the batch plot at certain
    ' intervals.

    Dim Plot As AcadPlot
    Dim AddedLayouts() As String
    'Dim LayoutList As Variant 'jlb
    Dim circleObj As AcadCircle
    Dim centerPoint(0 To 2) As Double
    Dim radius As Double
    Dim Layout As AcadLayout
    Dim ArraySize As Integer, BatchCount As Integer

    ' Define the Circle object
    centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
    radius = 5#

    ' Create the Circle object in model space
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)

    ThisDrawing.Application.ZoomAll

    ' Prompt user for Layouts to plot
    For Each Layout In ThisDrawing.Layouts
    If MsgBox("Do you wish to plot the layout: " & Layout.Name, vbYesNo
    + vbQuestion) = vbYes Then 'flag "&" was incorrect - jlb
    ArraySize = ArraySize + 1
    ReDim Preserve AddedLayouts(1 To ArraySize)
    AddedLayouts(ArraySize) = Layout.Name
    End If
    Next

    ' If the user did not select any Layouts to plot then exit
    If ArraySize = 0 Then Exit Sub

    ' Send the array list containing the layout names to a variant 'delete
    line - jlb
    ' which is compatible with SetLayoutsToPlot 'delete line - jlb
    'LayoutList = AddedLayouts 'delete line - jlb

    ' Get the plot object from the drawing
    Set Plot = ThisDrawing.Plot

    ' Set plot options
    Plot.QuietErrorMode = False ' We do want to be notified of errors
    ' * Note: Normally, in a batch
    situation, you do
    ' not want to be notified of errors,
    since this
    ' will halt the batch process.

    Plot.NumberOfCopies = 1 ' We only need one copy

    ' Start the batch plot the selected layouts

    Plot.StartBatchMode ArraySize ' Number of items in this batch

    For BatchCount = 1 To ArraySize

    ' SetLayoutsToPlot requires variant array, and for batch purposes
    'jlb
    ' we want each layout to be in its own array 'jlb
    Dim LayoutListItem(0 To 0) As String 'jlb
    LayoutListItem(0) = AddedLayouts(BatchCount) 'jlb

    ' The single-cell array does not need to be copied into a variant,
    but may if you want to... --- jlb
    Dim varLayoutListItem As Variant 'jlb
    varLayoutListItem = LayoutListItem 'jlb

    ' ...because the code runs with either of the following lines
    uncommented --- jlb
    Plot.SetLayoutsToPlot LayoutListItem 'jlb
    'Plot.SetLayoutsToPlot varLayoutListItem 'jlb

    ' Plot to default device
    Plot.PlotToDevice

    ' Display the results of the batch plot. This property should
    really be
    ' displayed to and set from a VBA Form, but for this example, we
    will
    ' use a message box
    If Plot.BatchPlotProgress Then
    If MsgBox("Would you like to cancel the batch plot?", vbYesNo +
    vbQuestion) = vbYes Then 'flag "&" was incorrect - jlb
    Plot.BatchPlotProgress = False
    End If
    Else
    MsgBox "The batch plot has stopped!"
    End If
    Next

    MsgBox "Finished plotting the selected Layouts!"
    End Sub
     
    James Belshan, Jun 24, 2003
    #6
  7. Gilles

    Mark Propst Guest

    Nice work, James,
    now can you fix the rest of them?
    :)
     
    Mark Propst, Jun 24, 2003
    #7
  8. "Mark Propst" asked:

    nahhhh... you don't need them, you're beyond them. You answer a lot of
    questions here. So if they ever did this, I'd expect to see your name on a
    couple of examples...

    and, yes, I realize that donating time to a profit-making corporation
    doesn't make much sense, but it's not the dumbest thing I've ever done.


    James
     
    James Belshan, Jun 24, 2003
    #8
  9. Gilles

    Gilles Guest

    Thanks all for your attention

    Gilles

     
    Gilles, Jun 25, 2003
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.