System.NullReferenceException: 未将对象引用设置到对象的实例
namespace Select{
public class ssa
{
public void Command1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptEntityOptions peo = new PromptEntityOptions("\n请选择直线");
PromptEntityResult per = ed.GetEntity(peo);
ObjectId id = per.ObjectId;
Entity ent = (Entity)id.GetObject(OpenMode.ForRead);
Line line = (Line)ent;
PromptSelectionResult psr = ed.SelectOnLine(line);
SelectionSet ss = psr.Value;
using (Transaction tr2 = db.TransactionManager.StartTransaction())
{
ed.WriteMessage("实体个数为:{0}",ss.Count);
foreach (ObjectId idi in ss.GetObjectIds())
{
// Entity enti = (Entity)idi.GetObject(OpenMode.ForWrite);
Entity enti = (Entity)tr2.GetObject(idi, OpenMode.ForWrite);
enti.ColorIndex = 1;
}
tr2.Commit();
}
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
}
}SelectOnLine(line) 函数原型为:
public static PromptSelectionResult SelectOnLine(this Editor ed, Line line);
在CAD里运行后,老是提示:“请选择直线: System.NullReferenceException: 未将对象引用设置到对象的实例。
在 Select.ssa.Command1_Method() 位置 D:\CS文件夹\选择集\Select\ssa.cs:行号 59”,
指明的行号内容为:“ed.WriteMessage("实体个数为:{0}",ss.Count); ”
请各位大侠看看到底是哪里出错了,谢谢大家!
看 看ss 是否为 null 雪山飞狐_lzh 发表于 2014-7-7 23:38 static/image/common/back.gif
看 看ss 是否为 null
可能是我的 SelectOnLine函数有问题,但是我也看不出来哪里有问题,麻烦您给看看
public static PromptSelectionResult SelectOnLine(this Editor ed, Lined line)
{
Point3d p1 = line.StartPoint;
Point3d p2 = line.EndPoint;
Point3d[] ps = { p1, p1, p2, p2 };
Point3dCollection pts = new Point3dCollection(ps);
return ed.SelectCrossingPolygon(pts);
}
========================================== 用selectfence试试 还要保证选择区域可见
页:
[1]