Hi guys,
I am working in project that purge and audit a bunch of file selected in listview control, the code shows the code generates errors cannot write in the memory and stopes in the red line.
DocumentCollection acdMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
string strFullPath;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
app.ActiveDocument.SendCommand("regen ");
app.ActiveDocument.PurgeAll();
app.ActiveDocument.PurgeAll();
app.ActiveDocument.AuditInfo(true);
app.ActiveDocument.SendCommand("regen ");
RegAppTable table = Tx.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable;
ObjectIdCollection regIds = new ObjectIdCollection();
foreach (ObjectId id in table)
{
regIds.Add(id);
}
//this function will remove all
//app names which are used in the drawing file
db.Purge(regIds);
foreach (ObjectId id in regIds)
{
DBObject obj = Tx.GetObject(id, OpenMode.ForWrite);
// the program stops here, cannot write on the memory
obj.Erase();
}
Tx.Commit();
}
}
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Hi,
I would verify if the id is valid and is not erased before open it for write.
- alfred -
thank you very much fo your support and time.
would you please clarify what you mean.
Hi,
>> would you please clarify what you mean.
Before opening objects for read/write I meant to verify the validity of the ObjectID:
if (Id.IsValid) andalso (not Id.IsErased) then
...now you can access the object in read/write mode.
HTH, - alfred -
@Anonymous wrote:
Hi guys,
I am working in project that purge and audit a bunch of file selected in listview control, the code shows the code generates errors cannot write in the memory and stopes in the red line.
Do I understand correctly that you open many files sequentially? Appropriately you work in the context of the application and must lock document.
using(DocumentLock docLock = doc.LockDocument()) { using (Transaction Tx = db.TransactionManager.StartTransaction()) { // your's code ... } }
I also moved code using app.ActiveDocument before the transaction...
Also I checked id before add it to regIds:
ObjectIdCollection regIds = new ObjectIdCollection(); foreach (ObjectId id in table) { if (!id.IsErased && !id.IsEffectivelyErased) regIds.Add(id); }
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
//string strTextFileName = SaveDialog.FileName; foreach (ListViewItem itemRow in this.lstView.Items) { ListViewItem item = lstView.Items[itemRow.Index]; string lines = item.SubItems[0].Text; string col = item.SubItems[1].Text; strFullPath = col + "\\" + lines; AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication; app.Documents.Open(strFullPath); if (chkBoxUnregApp == true) { app.ActiveDocument.SendCommand("regen "); app.ActiveDocument.PurgeAll(); app.ActiveDocument.PurgeAll(); app.ActiveDocument.AuditInfo(true); app.ActiveDocument.SendCommand("regen "); using (Transaction Tx = db.TransactionManager.StartTransaction()) { RegAppTable table = Tx.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable; ObjectIdCollection regIds = new ObjectIdCollection(); foreach (ObjectId id in table) { if (!id.IsErased && !id.IsEffectivelyErased) regIds.Add(id); } //this function will remove all //app names which are used in the drawing file db.Purge(regIds); if (regIds != null) { foreach (ObjectId id in regIds) { DBObject obj = Tx.GetObject(id, OpenMode.ForWrite); // the program stops here, cannot write on the memory obj.Erase(); } } Tx.Commit(); } }
Dear Alexander,
I changed the code as you see above but the error appear like the attached image shows it cannot write in the file eLockViolation.
Thanks for all of you for your time
Osayed
You did not read my post carefully. I wrote that you should wrap your code in:
using(DocumentLock docLock = doc.LockDocument()) { // your's code here! }
But you ignore me... Sorry... 😞 That is why exception eLockViolation occur!
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Yeaaa it works now thanks guys for your time and support,
but unfortunatly when the current file finishes and when openning another file from the listview it bring Fatal error message that always happen at the second dwg file.
Am I have to dispose or somthing like this
the code here and also the fatal erroe image attached.
thanks alot guys.
//string strTextFileName = SaveDialog.FileName; foreach (ListViewItem itemRow in this.lstView.Items) { ListViewItem item = lstView.Items[itemRow.Index]; string lines = item.SubItems[0].Text; string col = item.SubItems[1].Text; strFullPath = col + "\\" + lines; AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication; app.Documents.Open(strFullPath); if (chkBoxUnregApp == true) { app.ActiveDocument.SendCommand("regen "); app.ActiveDocument.PurgeAll(); app.ActiveDocument.PurgeAll(); app.ActiveDocument.AuditInfo(true); app.ActiveDocument.SendCommand("regen "); using (Transaction Tx = db.TransactionManager.StartTransaction()) { RegAppTable table = Tx.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable; ObjectIdCollection regIds = new ObjectIdCollection(); foreach (ObjectId id in table) { if (!id.IsErased && !id.IsEffectivelyErased) regIds.Add(id); } //this function will remove all //app names which are used in the drawing file db.Purge(regIds); if (regIds != null) { using (DocumentLock docLock = doc.LockDocument()) { foreach (ObjectId id in regIds) { DBObject obj = Tx.GetObject(id, OpenMode.ForWrite); // the program stops here, cannot write on the memory obj.Erase(); } } Tx.Commit(); } } }
hi Guys i checked but I found the fatal error has been produced at using transaction line but when i use the Tx.Dispose()
thanks alot
Can't find what you're looking for? Ask the community or share your knowledge.