Kean Walmsley

July 2009

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Twitter Updates

    follow me on Twitter



    « Creating a multileader in AutoCAD using a jig from .NET | Main | Driving a multi-sheet AutoCAD plot using .NET »

    September 25, 2007

    TrackBack

    TrackBack URL for this entry:
    http://www.typepad.com/services/trackback/6a00d83452464869e200e54ee872238833

    Listed below are links to weblogs that reference Driving a basic AutoCAD plot using .NET:

    Comments

    Sir,

    I am Akash, pursuing Masters in Construction Management from Indian Institute of Technology- Madras, Chennai (India)

    I had been using the VB 6.0 version till date and still would be continuing my work with that..

    I have an application to be coded where in 1) I have a set of coordinates say 6 coordinates for a cuboidal shape in excel sheet.
    2) I want to use them in Autocad to plot a drawing (every cuboid) based on these coordinates by importing from Excel file.

    3) I have a series of such cuboids to be connected to make a long span. I want this Plot to be finally displayed on VB form where my application is there.

    I look forward to receive some useful information from you at the earliest..

    PS: I have a bigger constraint in switchhing over to .Net for my application hence, please keep VB 6.0 in mind..

    Akash - please have your institute join ADN (if they're not already a member) or submit your question to one of the discussion groups.

    Regards,

    Kean

    G'day Kean

    Thanks for a great site.

    I am having trouble doing consecutive prints from one method call. I am trying to produce a DWF and a PDF of a drawing, but the second plot fails because the first plot does not start immediately. I have tried sleeping the thread and checking the ProcessPlotState. I also tried starting the plot in a separate thread, but that is crashing AutoCAD (even with try/catch blocks).

    Any ideas?

    Regards
    Michael

    Hi Michael,

    You probably need to make sure background plotting is disabled. If the BACKGROUNDPLOT sysvar is set to 1 or 3, then PLOT will background plot (which is not what you want).

    Cheers,

    Kean


    Thanks Kean, that did the trick.

    Dear Kean,

    I'm currently working on VBA for AutoCAD Mechanical 2007. I wonder if there is a way to edit the pc3/pmp files programatically from this interface. The goal is to enable the users to create custom sized flowsheets without manually add the Papersize to the pc3.
    So I'd like to create a mask, where the user types the desired width (height is given by the rolls in the plotter...) and they get their layout correctly sized. Wath I did as workaround is that I set up a 15 m long papersize for all Paperrolls and set the Cutting mode to extents. The only problem is, if I set up a Page Layout, users will get the whole 15 m as paper and this will be confusing I think... So can I access these settings programatically from VBA?
    Thanks in advance,
    Daniel

    Dear Daniel,

    The recommended way of changing plot configurations is via the API, not by modifying PC3 files. This API is exposed via C++ (ObjectARX) and .NET.

    I don't know of a way to access the API directly from VBA - you may need to include a C++ or .NET module in your application for this.

    Regards,

    Kean

    I'm writing some code for automatic PDF plotting (Won't go into details) but I'm new to AutoCAD.Net and I've been having problems adapting your code.

    I've tried stipping back my changes up to the point where it is basically a copy and paste of the above code without the progress bar in a hope to find what's wrong and I've made it to the point where even though my code is exactly the same I get this error: Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
    at Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.SetPlotConfigurationName(PlotSettings plotSet, String plotDeviceName, String mediaName)

    My code for that line being:
    Psv.SetPlotConfigurationName(Ps, "PDF Creator - A1.pc3", "A1");

    Any ideas?

    My best suggestion would be to double-check your assumptions by testing your code against another device/driver.

    Kean

    I've made it to the point where this all works except for the actual plot. It gets to the line "Pe.BeginPage(PpInfo, PInfo, true, null);"
    and then as soon as I step past it I get an error in AutoCAD saying "INTERNAL ERROR: !dbplotset.cpp@422: eLockViolation"

    Nobody seems to be able to give me a straight answer as to what this means, or why my code has only minor differences to yours (negligible) and yet when I run them together mine hits that point and crashes while yours doesn't.

    A lock violation typically means that access to a document has been attempted without it being locked or a second attempt has been made to access a currently locked document - I forget exactly which.

    The current document is locked implicitly when a command is entered, so perhaps you're not plotting the current document and have forgotten to lock it?

    Another (less likely) possibility is that it's somehow related to background plotting.

    If these suggestions don't help I suggest contacting the ADN team (if you're a member), or post it to the AutoCAD .NET Discussion Group, if not.

    Kean

    I figured it was something to do with access to the document. That being said, I thought I had already tested for that by commenting out practically my entire program apart from the plotting code and yet I'm still getting the same error. I then thought it was because the command is being run from a modeless dialog, but figured that wouldn't have any influence on a command run from it.

    At the moment my entire program is a foreach statement: foreach(string CurrentDwg in LstDwg.Items)
    this encloses: Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(CurrentDwg, false);
    and then proceeds straight to your plot code. After this is closes and discards changes.

    How is "the command" being run from a modeless dialog? If the code is simply behind a button (or another control), then it's running in the session context, so you must lock documents manually.

    The best way to drive functionality from a modeless dialog is to define actual commands and fire them off using SendStringToExecute(). That takes care of locking and lots of other bits and pieces.

    Although as you're looping through documents, you'll need to lock them yourself.

    Kean

    Once you enter the CommandMethod I've set up it opens the dialog. You select the settings you want to use (drawings, job number, etc.) and press the "Go" button.

    The above code is then run.

    The only thing I can think of now is closing each drawing, and then opening as read only before the plot code.

    I'll look into SendStringToExecute but for my purposes it may not work too well. At least I know where I'm going wrong now. Sort of.

    Try using Document.LockDocument() before you plot each one.

    SendStringToExecute() is actually a red herring, in this case: you have a session command that is working with multiple documents, so document locking is most likely the answer.

    Kean

    WORKED FIRST TIME!

    Can't believe the entire problem was missing 3 words!

    Hello Kean!

    If I run your function in modelspace, all is ok, but if I run your function when a layout with viewport is active i always get the error "eNotCurrentLayout" at "piv.Validate(pi);"!
    Is their something which i don't understand or works this function only if the modelspace is active?

    thanks in advance
    Patrick

    Hi Patrick,

    It works fine when a paperspace layout is selected, but I see it does fail if the modelspace viewport within that layout is active.

    I haven't coded to check for that (which it would take me some work to do), but there are couple of easy ways to code defensively for this case.

    1) You could execute a PSPACE command prior to executing the plot.
    2) You could use COM to do the same...

    Include the namespace for AutoCAD's COM interop assembly (after adding the assembly reference, of course):

    using Autodesk.AutoCAD.Interop;

    And this code early on in the SIMPLOT command:

    AcadDocument ad =
    (AcadDocument)doc.AcadDocument;
    ad.MSpace = false;

    I hope this helps,

    Kean

    I have used your example to some success, with the addition of reading the active layout's canonical media size before setting the new plot configuration.
    Having solved that one, I am having difficulty modifying to produce a plot preview. Do you have any pointers?

    This post should help.

    Kean

    Thanks for the pointers to the preview code.

    I have managed finally to program a custom eTransmit command that includes the plot to PDF and DWF along with a bound drawing.

    I was performing some final testing with a particularly large file (70MB) on a standard ISO plot. The plot to PDF can be completed manually, however when I execute the plot using .net I receive a System.AccessViolationException.
    Any attempts to avoid this using a Try Catch results in a pure virtual function call.

    The error occurs at:

    pe.BeginGenerateGraphics(null);

    The plot does appear to begin to work...

    Any ideas?

    Hi Mark,

    Sorry - I have no idea what's happening, although something about it makes it smell like a memory issue. I'd check to see whether the issue is reproducible with a slightly modified scenario:

    a) on another system
    b) with another, similarly-sized, drawing
    c) using a different (perhaps non-PDF) driver

    I'd also suggest submitting your question to the ADN team, if you're a member.

    Regards,

    Kean

    (meaning a, b or c, not a, b and c... :-)

    Kean

    Hello Kean, Do you have any sample in RealDWG application? thank you

    Here's a sample, although it's unrelated to this post (you can't plot from RealDWG).

    Kean

    Verify your Comment

    Previewing your Comment

    This is only a preview. Your comment has not yet been posted.

    Working...
    Your comment could not be posted. Error type:
    Your comment has been posted. Post another comment

    The letters and numbers you entered did not match the image. Please try again.

    As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

    Having trouble reading this image? View an alternate.

    Working...

    Post a comment

    Feed & Share

    Search