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

Read/Write Protected Memory

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
vince1327
523 Views, 2 Replies

Read/Write Protected Memory

Hey Everyone,

 

Yet another question. With help from "jeff" i managed to get my code up and running. It's essentially a function that creates a new paperspace, however when i run it, it generates the new paperspace, but a few seconds laters it crashes with an error saying that i'm attempting to read/write protected memory. I'm new to AutoCAD development and this is driving me crazy. Any assistance would be hugely appreciated. Below is my code.

 

Thanks again

Vince

 

namespace CHPaperSpace
{
public class CHPaperSpace
{
[Autodesk.AutoCAD.Runtime.CommandMethod("CHPAPERSPACE")]

// This will be the function associated with my command
public void CHPAPERSPACECOMMAND()
{
int i = 1;

Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager trm = db.TransactionManager;
using (DocumentLock acLckDoc = doc.LockDocument())


try
{
Transaction tr = trm.StartTransaction();
LayoutManager oLayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;

try
{
ObjectId oLayoutObjectId;
oLayoutObjectId = oLayoutManager.CreateLayout("CHPaperSpace" + i++);
Layout oLayout = (Layout)tr.GetObject(oLayoutObjectId, OpenMode.ForWrite);

oLayout.Initialize();
ed.Regen();
}



catch
{
tr.Commit();
acLckDoc.Dispose();
tr.Dispose();

}
}
catch{

}

}
}
}

 

2 REPLIES 2
Message 2 of 3
Alfred.NESWADBA
in reply to: vince1327

Hi,

 

first idea after 'flying over your code-snippet'

 

if your code does not have an error it does not dispose the transaction because you have the tr.Dispose it only within the catch.

And if you use the "using" for the documentlock ==> the .Dispose is done automatically.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 3
vince1327
in reply to: Alfred.NESWADBA

That was it, thanks very much for your help!

 

Cheers

Vince

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