首页 > 解决方案 > 如何在 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)));

请指教。非常感谢

标签: nullreferenceexception

解决方案


推荐阅读