0 Members and 1 Guest are viewing this topic.
/// <summary> /// Checks if the block definition is in the active drawing, if not, pull it from the template and add it /// </summary> /// <param name="blockName">Name of the block.</param> /// <returns></returns> public static ObjectId AddBlockDef(String blockName) { using (Transaction acTr = Active.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)acTr.GetObject(Active.Database.BlockTableId, OpenMode.ForNotify); ObjectId blockId; if (!bt.Has(blockName)) { ObjectIdCollection ids = new ObjectIdCollection(); // get the template drawing using (Database dwtDb = new Database(false, true)) { string dllPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); String dwtPath =dllPath + @"\AID-Template.dwt"; dwtDb.ReadDwgFile(dwtPath, System.IO.FileShare.ReadWrite, true, ""); using (Transaction tr = dwtDb.TransactionManager.StartTransaction()) { BlockTable dwtBt = (BlockTable)tr.GetObject(dwtDb.BlockTableId, OpenMode.ForRead); // does it exist if (dwtBt.Has(blockName)) { ids.Add(dwtBt[blockName]); } tr.Commit(); } } if (ids.Count > 0) // add it to active drawing { IdMapping iMap = new IdMapping(); Active.Database.WblockCloneObjects(ids, Active.Database.BlockTableId, iMap, DuplicateRecordCloning.Ignore, false); //<-- eWasOpenForNotify Error here } else { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("\nBlock: " + blockName +" not found."); } } blockId = acTr.GetObject(bt[blockName], OpenMode.ForRead).ObjectId; acTr.Commit(); return blockId; } }