After running the following code block, the drawing becomes unusable, as every time I run ReadDwgFile after a successful run I get "ENoInputFiler."
foreach (ObjectId attributeObjId in anotherBlkTableRecord)
{
AttributeDefinition attributeDefinition = (trans.GetObject(attributeObjId, OpenMode.ForRead).GetType() == typeof(AttributeDefinition) ?
(AttributeDefinition)trans.GetObject(attributeObjId, OpenMode.ForRead) : null);
if (attributeDefinition != null)
{
if (string.Compare(attributeDefinition.Prompt, attributePrompt, true) == 0)
{
return GetAttributeValueStep2(activeDb, workingBlock, attributeDefinition.Tag);
}
}
}
Am I doing something wrong?
Hi,
Look at the 'as' operator.
foreach (ObjectId attributeObjId in anotherBlkTableRecord) { AttributeDefinition attributeDefinition = trans.GetObject(attributeObjId, OpenMode.ForRead) as AttributeDefinition; if (attributeDefinition != null) { if (attributeDefinition.Prompt == attributePrompt) { return GetAttributeValueStep2(activeDb, workingBlock, attributeDefinition.Tag); } } }
Or, more efficient, check the underlying type of the ObjectId
RXClass attDefClass = RXClass.GetClass(typeof(AttributeDefinition)); foreach (ObjectId attributeObjId in anotherBlkTableRecord) { if (attributeObjId.ObjectClass == attDefClass) { AttributeDefinition attributeDefinition = (AttributeDefinition)trans.GetObject(attributeObjId, OpenMode.ForRead); if (attributeDefinition.Prompt == attributePrompt) { return GetAttributeValueStep2(activeDb, workingBlock, attributeDefinition.Tag); } } }
I've re-written the code as you suggested. I still get the error when trying to read a drawing, though.
using (Autodesk.AutoCAD.DatabaseServices.Database acDb = new Autodesk.AutoCAD.DatabaseServices.Database(false, false))
{
acDb.ReadDwgFile(fileToProcess, FileShare.ReadWrite, false, string.Empty);
....
}
The bolded line is throwing the error.
we need a buildable sample to look at with sample dwg - as far as I can tell, your code doesn't show anything wrong
I'm trying to attach a zip file with the program and sample drawing, but it keeps telling the file is corrupted.
I had a similar problem in attaching files to another post.
Please try again and if does not work, you can share it using dropbox or mail it to me.
Hi Neil,
Thanks for mailing the sample project to reproduce the behavior.
Iam posting the code snippet that I sent in my reply to you for future reference.
To resolve it, you need to lock the document or create the database without associating with the current document.
Document doc = Application.DocumentManager.MdiActiveDocument; using (DocumentLock docLock = doc.LockDocument()) { using (Autodesk.AutoCAD.DatabaseServices.Database acDb = new Autodesk.AutoCAD.DatabaseServices.Database(false, false)) { acDb.ReadDwgFile(fileToProcess, FileShare.ReadWrite, false, string.Empty); //... } } Or create the database without associating it with the active document as : using (Autodesk.AutoCAD.DatabaseServices.Database acDb = new Autodesk.AutoCAD.DatabaseServices.Database(false, true)) { acDb.ReadDwgFile(fileToProcess, FileShare.ReadWrite, false, string.Empty); //... }
Can't find what you're looking for? Ask the community or share your knowledge.