Layout eNullObjectID

Layout eNullObjectID

bherber
Contributor Contributor
1,003 Views
1 Reply
Message 1 of 2

Layout eNullObjectID

bherber
Contributor
Contributor

I have a very wierd issue that i have been battling with.

I currently had a C# method that i was using for Plotting.  the method works fine when i call it from a CommandMethod (off of the base class)but when i try calling it from a usercontrol i get an exception of NullObjectID. it crashes on

"Layout layout = Tx.GetObject(layoutMgr.GetLayoutId(layoutMgr.CurrentLayout), OpenMode.ForWrite) as Layout;"

 

i have used user contols and PalleteSets and they both crash out.  HELP

 

public void SimplePlot(string Pc3PrinterName)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;


using (Transaction Tx = doc.Database.TransactionManager.StartTransaction())
{
PlotSettingsValidator psvc = PlotSettingsValidator.Current;
LayoutManager layoutMgr = LayoutManager.Current;
Layout layout = Tx.GetObject(layoutMgr.GetLayoutId(layoutMgr.CurrentLayout), OpenMode.ForWrite) as Layout;
psvc.RefreshLists(layout);
Tx.Commit();
}

...

 

 

}

 

0 Likes
Accepted solutions (1)
1,004 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

Based your description of the problem, it is very likely that you need to lock the document before accessing drawing database/starting transaction, that is, wrap up the operation in 

 

using (var lk=doc.LockDocument())

{

  //Do your work here

 

}

Norman Yuan

Drive CAD With Code

EESignature

0 Likes