通过Objectd能获得对象吗
Autodesk.AutoCAD.EditorInput.Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;Database db = HostApplicationServices.WorkingDatabase;
PromptSelectionResult pkf = ed.SelectImplied();
if (pkf.Status != PromptStatus.OK) return;
ObjectId[] objIds = pkf.Value.GetObjectIds();
if (objIds.Length > 1)
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("\n请选择一个对象");
else
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId id = objIds;
Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
ent.ColorIndex = 1;
trans.Commit();
}
}
选择一个对象后,知道该对象的ObjectID,能获取该对象的一些属性吗?每次执行都出错在Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;这句话。希望大侠帮忙看看。不要因为太简单不理我哦 但我这么写,就能得到这个对象实体
public void OpenEnt()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("通过ObjectId打开对象\n");
PromptEntityOptions entOps = new PromptEntityOptions("选择要打开的对象\n");
PromptEntityResult entRes;
entRes = ed.GetEntity(entOps);
if (entRes.Status != PromptStatus.OK)
{
ed.WriteMessage("选择对象失败,退出");
return;
}
ObjectId objId = entRes.ObjectId;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = trans.GetObject(objId, OpenMode.ForWrite) as Entity;
ent.ColorIndex = 1;
trans.Commit();
}
}
方法都是一样的啊,就连得到的ObjectID的值也是一样的,为什么楼上的写法就出错呢
页:
[1]