nullreferenceexception - 如何在 C# autocad 中修复 System.NullReferenceException
问题描述
我正在为 Autocad 开发一个插件,但是有一个关于 NullReferenceException 的问题,如下代码:
public void Aba(int Width)
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
//PromptEntityResult selRes = ed.GetEntity("\nPick a Curve entity:");
PromptSelectionOptions selOp = new PromptSelectionOptions();
PromptSelectionResult selRes = ed.GetSelection(selOp);
PromptKeywordOptions chRes = new PromptKeywordOptions("\nVuong hay khong?[Y/N]:", "Y N");
chRes.Keywords.Default = "Y";
PromptResult pStrRes = ed.GetKeywords(chRes);
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
if (selRes.Status == PromptStatus.OK)
{
SelectionSet acSSet = selRes.Value;
// Step through the objects in the selection set
foreach (SelectedObject acSSObj in acSSet)
{
Entity ent = (Entity)tr.GetObject(acSSObj.ObjectId, OpenMode.ForRead);
double angle = GetAngle(ent as Curve);
int CurLenght = Convert.ToInt32((GetLength(ent as Curve)));
请指教。非常感谢
解决方案
推荐阅读
- python-2.7 - 如何在 python 2.7.4 中随机化字典?
- c# - 如何在C#中实现模板之类的功能
- hadoop - 猪场未显示所有数字
- c# - Revit 中的对话框
- python - 将任意(未使用的)关键字参数传递给 matplotlib
- javascript - 在 React Native 中访问对象项时出错
- scheme - 在这种情况下,“下一步”是什么意思?
- c# - 如何在 Unity3d 上没有滞后的情况下在场景中生成敌人 AI?
- tensorflow - Tensorflow: is there a way to load a pretrained model without having to redefine all the variables?
- java - java多线程在不同的操作系统上是否不同?