Trouble with centerplot and vba

Discussion in 'AutoCAD' started by Alejandro, Oct 15, 2004.

  1. Alejandro

    Alejandro Guest

    Here's what I've gotten stuck with: when manipulating a drawing from a
    vb6 module, calling (ActiveLayout.CenterPlot = True) puts the lower left
    of the drawing in the exact middle of the plot area, (drawing not
    centered at all) but the same code run from within a .dvb puts the
    drawing's center in the middle (like I expect). The lower left corner
    of the drawing is on the left edge of the plot area, centering the
    content of the plot in the middle of the plot area.

    It seems like an inconsistency between a VB module and a .dvb, but I
    rather think that I have a setting wrong (or something). Below is the
    code as I run it from VB.

    Any ideas?

    Alex


    Dim x As Object
    Dim acadDrawing As Object
    Set x = CreateObject("AutoCAD.Application")

    x.documents.Open fileName & ".dwg"
    Set acadDrawing = x.activedocument

    With acadDrawing.activelayout
    .RefreshPlotDeviceInfo
    .PlotWithPlotStyles = True
    .ConfigName = "JPG 400x350.pc3"
    .CenterPlot = True ' not the same behavior as within a dvb
    .CanonicalMediaName = "UserDefinedRaster (400.00 x 350.00Pixels)"
    .plotrotation = ac0degrees
    .StyleSheet = "monochrome.ctb"
    .RefreshPlotDeviceInfo
    End With

    acadDrawing.plot.PlotToFile fileName & ".jpg"
     
    Alejandro, Oct 15, 2004
    #1
  2. are you sure it's related to VB vs VBA?

    Try running your code and then manually do PAGESETUP to see if all the plot
    settings are identical between your VB and VBA runs. For example, if
    "Layout" is chosen for "What to Plot", you can't center the plot, and your
    VB statement would be ignored (or maybe error).... Point is, make sure
    you're comparing apples to apples with all the plot settings.

    Alternatively, I've run into the situation where my changes to plot settings
    via code don't take effect until I open and close the PAGESETUP window.
    Could this be happening to you? Does your plot area move when you run
    PAGESETUP after running your VB program? If so, I have a (not pretty)
    work-around that I used for this situation that I could post.

    James
     
    James Belshan, Oct 15, 2004
    #2
  3. Alejandro

    Alejandro Guest

    James,

    Here's the thing: I stopped both sets of code and did PAGESETUP, and
    both had exactly the same print settings. Inclusive, the plot origin
    values were correct in the PAGESETUP dialog in both instances, but yet
    when I have been checking the value of the origin in the code (as it is
    running) it is wrong.

    Heres the sample code I use:
    v = acadDrawing.ActiveLayout.PlotOrigin
    Debug.Print v(0) & "," & v(1)

    where the origin should be something like (0, 45) (left edge slightly
    off the bottom), the printed values (and later the actual plot) are way
    off, to the tune of (194.23, 171.09). Like I said, the values in the
    PAGESETUP dialog are right, but yet plotting output is wrong, but only
    in the VB (external control of AutoCAD) code.

    It seems that my problem is very similar to the problem you mentioned
    about settings not taking effect until the PAGESETUP dialog is opened
    and closed. So if you can, could you share your workaround.

    Also, if you can think of anything I haven't yet tried to diagnose this
    confusion I would be so thankful.

    Thanks,

    Alex
     
    Alejandro, Oct 16, 2004
    #3
  4. What I found when changing the plot area in my code was that I had to open
    and close the PageSetup dialog in order for the print area to change on
    screen (and in the plot). I just did a hack like:

    Code:
    .CenterPlot = true
    SendKeys "{ENTER}"
    ThisDrawing.SendCommand ("pagesetup" & vbCr)
    
    Occasionally the ENTER key doesn't get sent to the dialog and the dialog is
    left hanging open, but my work is all in-house so it's no big deal. We just
    hit ENTER to close the dialog box and the macro continues on.

    I saw in another thread that this problem may be fixed in ACAD 2005.

    James
     
    James Belshan, Oct 16, 2004
    #4
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.