Message 1 of 7
Not applicable
04-08-2018
07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to insert a DWG file into a drawing. Most of what I can find for reference deals with existing blocks already defined in the block table. I did find this code and I'm getting an 'Unreferenced object' error (but not crashing, I can continue). Locking the document was the last thing I tried. Can someone direct me to a good reference. I've tested the filepath and it is correct. Thank you.
public void InsertEquipment(string file)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
using (DocumentLock docLock = doc.LockDocument())
{
Database sourceDb = new Database(false, true); //Temporary database to hold data for block we want to import
try
{
sourceDb.ReadDwgFile(file, System.IO.FileShare.Read, true, ""); //Read the DWG into a side database
db.Insert(file, sourceDb, false);
ed.WriteMessage("\nSUCCESS: " + file);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sourceDb.Dispose();
}
}
tr.Commit();
}
}
Solved! Go to Solution.