请教高手:vs2010开发cad批量改图层名称程序,怎样实现
本人正在学习c#开发autocad,请教高手:vs2010开发cad批量改图层名称程序,怎样实现,谢谢赐教! // 请教大师,下面的程序没有通过,帮忙看看怎样解决,谢谢!using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using DotNetARX;
public static void RenameLayer2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
foreach (ObjectId id in lt)
{
LayerTableRecord ltr = id.GetObject(OpenMode.ForRead) as LayerTableRecord;
if (ltr.Name !="0")
{
ltr.Name = ltr.Name + "NEW";
trans.Commit();
}
}
}
}
//此程序也不行,
public static void RenameLayer2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
foreach (ObjectId id in lt)
{
LayerTableRecord ltr = id.GetObject(OpenMode.ForRead) as LayerTableRecord;
if (ltr.Name !="0")
{
ltr.Name = ltr.Name + "NEW";
lt.Add(ltr);
trans.AddNewlyCreatedDBObject(ltr, true);
}
trans.Commit();
}
}
}
版主有空帮忙看看可以吗?先谢谢了! LayerTableRecord ltr = id.GetObject(OpenMode.ForRead) as LayerTableRecord;
------------------------
LayerTableRecord ltr = id.GetObject(OpenMode.ForWrite) as LayerTableRecord;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
foreach (ObjectId id in lt)
{
LayerTableRecord ltr = id.GetObject(OpenMode.ForWrite) as LayerTableRecord;//写打开
if (ltr.Name !="0")
{
ltr.Name = ltr.Name + "NEW";
}
}
trans.Commit();//事务只能提交一次
} trans.AddNewlyCreatedDBObject(ltr, true);
-----------------------
已在库里面的对象不能再添加 谢谢 sieben ,学习了。
页:
[1]