DBX 修改块名报错 (已解决)
本帖最后由 慢慢来吧 于 2018-1-9 09:57 编辑public void DrawingPretreatment()//String fileFullName, String curNumber)
{
String fileFullName = @"E:\001.dwg";
String curNumber = "1";
string progid = "ObjectDBX.AxDbDocument.16";
AxDbDocument objDbx = (AxDbDocument)acadApp.GetInterfaceObject(progid);
objDbx.Open(fileFullName, null);
foreach (AcadEntity entity in objDbx.ModelSpace)
{
switch (entity.EntityName)
{
case "AcDbBlockReference":
AcadBlockReference blkRef;
blkRef = (AcadBlockReference)entity;
try
{
blkRef.Name = blkRef.Name + curNumber;//这里出错
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
throw new System.Exception(ex.Message);
}
break;
case "AcDbOrdinateDimension":
break;
}
}
objDbx.SaveAs(fileFullName, null);
objDbx = null;
}
AutoCAD 2005& vs2008
神啊,救救我吧!
换成.net 模式解决。
tempDb.ReadDwgFile(curFileName, System.IO.FileShare.ReadWrite, true, null);using (Transaction curTrans = tempDb.TransactionManager.StartTransaction())
{
BlockTable curBt = (BlockTable)curTrans.GetObject(tempDb.BlockTableId, OpenMode.ForRead);
int i = 1;
foreach (ObjectId acObjId in curBt)
{
BlockTableRecord br = curTrans.GetObject(acObjId, OpenMode.ForWrite) as BlockTableRecord;
if (br.Name.StartsWith("_OPEN") || br.Name.StartsWith("DimnDraft"))
{
br.Name = spStr.Remove(0, 3) + "-" + i.ToString();
i++;
}
}
// 以写模式打开块表记录ModelSpace(模型空间)
BlockTableRecord acBlkTblRec;
acBlkTblRec = curTrans.GetObject(curBt, OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId acObjId in acBlkTblRec)
{
Entity cc = curTrans.GetObject(acObjId, OpenMode.ForWrite) as Entity;
if (cc.GetType().Name == "OrdinateDimension")
{
OrdinateDimension od = cc as OrdinateDimension;
od.DimensionText = "";
//od.UpgradeOpen();
}
if (cc.GetType().Name == "RotatedDimension")
{
RotatedDimension rd = cc as RotatedDimension;
rd.DimensionText = "";
//rd.UpgradeOpen();
}
}
curTrans.Commit();
}
页:
[1]