WblockCloneObjects 写块的问题
public static void WblockFromDwg(ObjectIdCollection IdCollection,ref Database newDataBase){
Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
Editor editor = document.Editor;
newDataBase = new Database(true, true);
ObjectId oid = new ObjectId();
IdMapping map = new IdMapping();
using (Transaction trans = newDataBase.TransactionManager.StartTransaction())
{
BlockTable blocktable = trans.GetObject(newDataBase.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord modelSpace = trans.GetObject(blocktable, OpenMode.ForRead) as BlockTableRecord;
oid = modelSpace.ObjectId;
trans.Commit();
}
database.WblockCloneObjects(IdCollection, oid, map, DuplicateRecordCloning.Replace, false);
//newDataBase.SaveAs(fileName, DwgVersion.Current);
}
如上图代码 做了一个写块的方法,但是在运行时 部分图形会出现如下错误:
eDuplicateRecordName: at Autodesk.AutoCAD.DatabaseServices.Database.WblockCloneObjects(ObjectIdCollection identifiers, ObjectId id, IdMapping mapping, DuplicateRecordCloning cloning, Boolean deferTranslation) at DataProcess.ClsAppMethod.WblockFromDwg(ObjectIdCollection IdCollection, Database& newDataBase)
求教 是什么原因
Dim NewDb As Database = New Database(True, True) '目标数据库对象
Dim NewBtrId As New ObjectId() '目标数据库的块表Id
Using NewTrans As Transaction = NewDb.TransactionManager.StartTransaction()
Dim NewBt As BlockTable = NewTrans.GetObject(NewDb.BlockTableId, OpenMode.ForRead)
Dim NewBtr As BlockTableRecord = NewTrans.GetObject(NewBt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
NewBtrId = NewBtr.ObjectId
NewTrans.Commit()
End Using
db.WblockCloneObjects(blockIds, NewBtrId, New IdMapping(), DuplicateRecordCloning.Replace, False)
NewDb.SaveAs(strBlockName, DwgVersion.Current)
'NewDb.SaveAs(strBlockName,DwgVersion.AC1800) 这是我测试成功的代码
Document doc = Env.Document;
var db = doc.Database;
var r1 = doc.Editor.GetSelection();
if (r1.Status != PromptStatus.OK) return;
ObjectIdCollection oidc = new(r1.Value.GetObjectIds());
var newdb = new Database(true, true);
using var tr = newdb.TransactionManager.StartTransaction();
var bt = tr.GetObject(newdb.BlockTableId, OpenMode.ForRead) as BlockTable;
IdMapping idm = new();
db.WblockCloneObjects(oidc, bt!, idm, DuplicateRecordCloning.Replace, false);
newdb.SaveAs(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\123.dwg",DwgVersion.AC1800);
也可以直接用这个
NewDb = db.Wblock(blockIds, db.Ucsorg)
'以当前正使用的CAD版本格式保存数据库
NewDb.SaveAs(strBlockName, DwgVersion.Current) 重复记录名称错误的信息,估计是重复的块名或者文件名导致错误吧。 看看ifox内有没有注释 可能是没锁定文档
DocumentCollection acDocMgr = Application.DocumentManager;
using (DocumentLock acLckDoc = acNewDoc.LockDocument()) 是不是你的图层 冻结 隐藏 没有隐藏图层 也没有冻结图层 文档也是锁定状态,我从一个大图上 批量分割300个小图,出错跳过输出一个文档看,有20个多个图形输出不了 其他的270多个正常 挺奇怪的
也可以直接用这个
NewDb = db.Wblock(blockIds, db.Ucsorg)
'以当前正使用的CAD版本格式保存数据库
NewDb.SaveAs(
页:
[1]
2