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

Access plot parameters after successful plot

17 REPLIES 17
Reply
Message 1 of 18
Anonymous
667 Views, 17 Replies

Access plot parameters after successful plot

I am trying to get the details (paper size, number of copies, etc.) at the end of a successful plot event - success meaning that the plot was sent to plotter without error. But I am not sure how to get the details - see attempt below - which fails - invaild objectid ? Please Help. Thx...


void prm_EndPlot(object sender, Autodesk.AutoCAD.PlottingServices.EndPlotEventArgs e)
{
Database DB = acadApp.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager TM = DB.TransactionManager;
Transaction TR = TM.StartTransaction();
try
{
Autodesk.AutoCAD.PlottingServices.PlotInfo PI1 = new PlotInfo();
Layout L1 = (Layout)TR.GetObject(PI1.Layout,OpenMode.ForRead,false,false);
TR.Dispose();
}
catch(Autodesk.AutoCAD.Runtime.Exception ex)
{
TR.Dispose();
MessageBox.Show(ex.Message.ToString());
}
}
17 REPLIES 17
Message 2 of 18
Anonymous
in reply to: Anonymous

I have resorted to reading the log file produced by the plot stamp facility.
The ideal method would be to monitor all print jobs at operating system level - independant of applications.
It would be greatly appreciated if anybody can indicate how to do that or indicate the optimal .net method in accessing plot details.
Thanks, Kevin.
Message 3 of 18
Anonymous
in reply to: Anonymous

Kevin
All the details that you want for a plotting job are not available at the endPlot event. You need to collect them from where they are available.
For ex: the PlotInfo object that you want is available through the BeginPageEventArgs when the BeginPage event is fired. So you need to trap that event and extract the details. similarly for others. Take a look at all the events in PlotReactorManager and what data is available when the various events are fired.
HTH
Jai
Message 4 of 18
Anonymous
in reply to: Anonymous

Thx Jai. The details (e.g. .PlotPaperSize.X) appear to be in the Layout referred by the Layout objectid in the PlotInfo object. Is the Layout object part of the Layout dictionary? To which object do you apply the GetObject method, using the Layout objectid stored in PlotInfo?
Looks like I'm almost there ... I hope ...
Thanks again...
Message 5 of 18
Anonymous
in reply to: Anonymous

Kevin
You *are* almost there.
You would do domething like this:

private void
BeginPageEventHandler(object obj, Autodesk.AutoCAD.PlottingServices.BeginPageEventArgs e)
{
PlotInfo plotInfo = e.PlotInfo;

Database DB = acadApp.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager TM = DB.TransactionManager;
Transaction tr= TM.StartTransaction();
Layout layout = tr.GetObject(plotInfo.Layout, OpenMode.ForRead) as Layout;
Point2d plotPaperSize = layout.PlotPaperSize;
}
<\code>

HTH
Jai
Message 6 of 18
Anonymous
in reply to: Anonymous

Superb! Couldnt find the copies count but will keep digging. All the World should know that Jai's a Star!
Message 7 of 18
Anonymous
in reply to: Anonymous

Found it!... Copies and PlotToFile in BigenDocument - All done!
Message 8 of 18
Anonymous
in reply to: Anonymous

Oops! The EndPlot event fires at the end of a plot preview as well as the End of a plot. So I will need to handle CommandEnded instead and check for the plot command being ended. Thanks for the Initialize and Terminate methods of IExtensionApplication. These will come in very handy in future. I could add the CommandEnded event handler ther too. But then the only drawing being watched would be the drawing active when the program was loaded. How do I add a Command event handler that will be applied to any drawing?
Thanks for your patience...
Kevin.
Message 9 of 18
Anonymous
in reply to: Anonymous

To add an event handler that applies to all drawings you should have an application wide object that reacts to documents.

ex:

private Autodesk.AutoCAD.ApplicationServices.DocumentCollection m_docs = null;

Initialise()
{
...
m_docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
m_docs.DocumentCreated += new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(eventHandler1);
m_docs.DocumentToBeDestroyed+= new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(eventHandler2);
...
}
...
Thes event handlers will be fired every time a new document is created/destroyed. So you can attach plot specific event handlers in eventHandler1 and eventHandler2.

HTH
Jai
Message 10 of 18
Anonymous
in reply to: Anonymous

It's working. I cant distribute my dll though as it produces an unhandled exception when acad is terminated. Here's the changes I made... it must be missing a dispose or "unload" somewhere...

private Autodesk.AutoCAD.ApplicationServices.DocumentCollection m_docs = null;

public void Initialize()
{
...
m_docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
m_docs.DocumentCreated += new
Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r1);
m_docs.DocumentToBeDestroyed += new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r2);
}

void r1(object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
Document CurrentDoc = e.Document;
CurrentDoc.CommandEnded += new CommandEventHandler(prm_CommEnded);
}

void r2(object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
Document CurrentDoc = e.Document;
CurrentDoc.CommandEnded -= new CommandEventHandler(prm_CommEnded);
}

public void Terminate()
{
...
m_docs.DocumentCreated -= new
Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r1);
m_docs.DocumentToBeDestroyed -= new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r2);
}
Message 11 of 18
Anonymous
in reply to: Anonymous

Kevin
The problem with the event DocumentCreated is that it doesnt fire for the default dwg with which Autocad opens. So essentially you are not attaching the CommandEnded delegate to the very first default dwg. So at shut down you are tryng to remove a delegate you ahvent attached. Hence the exception.

private Autodesk.AutoCAD.ApplicationServices.DocumentCollection m_docs = null;

public void Initialize()
{
m_docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

foreach (Document doc in m_docs)
{ Attach(doc);
}

m_docs.DocumentCreated += new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r1);

m_docs.DocumentToBeDestroyed += new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r2);
}

public void Terminate()
{
m_docs.DocumentCreated -= new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r1);

m_docs.DocumentToBeDestroyed -= new Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventHandler(r2);
}

void r1 (object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
Attach(e.Document);
}

void r2 (object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
Detach(e.Document);
}

private void Attach (Document doc)
{
doc.CommandEnded += new CommandEventHandler(doc_CommandEnded);
}

private void Detach (Document doc)
{
doc.CommandEnded -= new CommandEventHandler(doc_CommandEnded);
}


void doc_CommandEnded (object sender, CommandEventArgs e)
{
/// your stuff
}
Message 12 of 18
Anonymous
in reply to: Anonymous

Thx... That did it - but u knew that already..
If you're ever in Pretoria, South Africa, pop over for a beer and a braai... I owe u big time, cheers...
Message 13 of 18
Anonymous
in reply to: Anonymous

🙂 will do mate

Jai
Message 14 of 18
Anonymous
in reply to: Anonymous

I was hoping that it wouldnt happen - but it did. The users are using the Publish command to plot drawings too. Jai - where is the publish event data provided?
This is getting complicated. Is it more complex than trying to capture print event information at operating system level?
Message 15 of 18
Anonymous
in reply to: Anonymous

Autodesk.AutoCAD.Publishing.Publisher has a bunch of relevant events. I am not sure if you can handle all publish/plots at one common location.

HTH
Jai
Message 16 of 18
Anonymous
in reply to: Anonymous

I stumbled at the first hurdle...
where we have...
private PlotReactorManager instance = new PlotReactorManager();

I tried (after including, using Autodesk.AutoCAD.Publishing;):
private Autodesk.AutoCAD.Publishing.Publisher PubThing = new Autodesk.AutoCAD.Publishing.Publisher();

error:
The type 'Autodesk.AutoCAD.Publishing.Publisher' has no constructors defined.

?
Kevin's lost at sea again...
Message 17 of 18
Anonymous
in reply to: Anonymous

You cannot create a new publisher. You have to get it from the application
ex:
Autodesk.AutoCAD.Publishing publisher = Autodesk.AutoCAD.ApplicationServices.Application.Publisher;

HTH
Jai
Message 18 of 18
Anonymous
in reply to: Anonymous


@Anonymous wrote:
Oops! The EndPlot event fires at the end of a plot preview as well as the End of a plot. So I will need to handle CommandEnded instead and check for the plot command being ended. Thanks for the Initialize and Terminate methods of IExtensionApplication. These will come in very handy in future. I could add the CommandEnded event handler ther too. But then the only drawing being watched would be the drawing active when the program was loaded. How do I add a Command event handler that will be applied to any drawing?
Thanks for your patience...
Kevin.

For people like me, who find and read this thread (although it is already old):

A (better) solution to the plot preview also fires plotting events problem can be found here:

http://forums.autodesk.com/t5/NET/Plotting-events-How-to-know-if-it-was-a-preview-or-the-actual/td-p/3223928

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