.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plotting Document while other doc is open

2 REPLIES 2
Reply
Message 1 of 3
chrnit
803 Views, 2 Replies

Plotting Document while other doc is open

Hi.
I've got a problem plotting a document.

At first, I'm new to AutoCAD and .NET.
So if I simply have missed something, it would be nice if you'd point me to the docs I've missed to read 😉

Now to my actual problem:
I'm writing an extension using .NET in C#.
The code should open a DWG, color some specific layer in a given color and plot the resulting drawing to a DWF file.

I've managed to open the DWG and color the layer.
I even managed to plott the active document to DWF.
Now here's the problem:
When I call my custom command, it will open the DWG in another window while the doc that was open before loading the DWG stays active. When I try to plot this document, this exception is thrown:
"Autodesk.AutoCAD.Runtime.Exception: eLayoutNotCurrent"

To solve this problem, I tried to set the active document to the one I just opened:
Document doc = app.DocumentManager.Open( filePath, true );
app.DocumentManager.MdiActiveDocument = doc;

When this is run, execution of my code stops when AutoCAD switches the active window to that of my DWG.
Execution continues when I switch back to the window that was active when my command started.

How can I plot the drawing in the DWG?
There must be some way to do this...
Any help is really appreciated.

Best Regards
Christian Nitschkowski
2 REPLIES 2
Message 2 of 3
cgay
in reply to: chrnit

Christian,

It would seem that your code is operating in the Document Context.
Of course, we would need to actually see it to fully explore this.
If this is indeed the case, you can add a Session attribute to your procedure to make it act in the Application context.
Be aware that you may need to lock the document to modify it though.

The definition of 'Session' is such, according to the ARX docs:
ACRX_CMD_SESSION
The command will be run in the application execution context rather than the current document context, with the different capabilities and limitations that entails. It should be used sparingly.

This is an excerpt from the ObjectARX 2007 Docs -> AutoCAD Managed Class Reference -> ObjectARX Managed Wrapper Classes -> titled 'Defining AutoCAD Commands in Managed Applications':
[code]
This attribute declaration defines an AutoCAD command named COMINTEROP, and identifies the ComInteropCommand subroutine as the command handling method.
The CommandFlags.Session command flag indicates that this command should run in the session context.
Note that this method is declared Shared. In C#, an analogous declaration looks like this:

[CommandMethod(“COMINTEROP”, CommandFlags.Session)]
public static void ComInteropCommand() {
//...
}
As in ObjectARX, a command handler must be a public method with no return value and no parameters. [/code]

Good Luck,

C
Message 3 of 3
chrnit
in reply to: chrnit

Hi CougerAC,

I've tried adding the CommandFlag Session to my CommandMethod and now it works just as expected.
Thank you for your hint.

By the way - it was still necessary to disable plotting in the background as it didn't seem to work very well when enabled, as it was by default.

According to some other post here (http://discussion.autodesk.com/thread.jspa?messageID=4912343) there seems to be some trouble with background plotting in combination with .NET.
When I was using background plotting AutoCAD quit and wanted to report some uncaught exception to Autodesk.
After disabling background plotting, the problem was gone and my code works like a charm.

Best Regards
Christian Nitschkowski

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost