我正在尝试使用WblockCloneObjects从模板绘图中添加块,但不断收到
eWasOpenForNotify
错误。
- ///
- /// Checks if the block definition is in the active drawing, if not, pull it from the template and add it
- ///
- /// Name of the block.
- ///
- 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;
- }
- }
有什么想法吗?
我从这里获得了代码的基础。也许我以错误的方式去做了?理论上,模板 dwt 文件将位于支持路径中。WblockCloneObjects看起来确实是一种绕开的方式,但我知道什么......
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |