【问题标题】:Why does AutoCAD throw a fatal error when I try to read line start and end points?当我尝试读取行的起点和终点时,为什么 AutoCAD 会引发致命错误?
【发布时间】:2015-02-18 17:57:57
【问题描述】:

我正在编写一个插件来尽可能多地从 CAD 中提取数据。我现在遇到的主要问题是当我尝试访问 StartPoint.X 时,例如,脚本失败而没有捕获异常,“致命错误:d8e176b4h 处未处理的访问冲突读取 0xffffffff”。根据我尝试访问的内容,内存位置和第二个数字的变化。示例:

    foreach (Objects o in globalListOfObjs)
        {
            string type = o.obj.GetType().ToString().Split('.').Last();

            if (type == "Line")
            {
                try
                {
                    Line l = (Line)o.obj;
                    if (l != null)
                    {
                        MessageBox.Show("Not Null!");
                        MessageBox.Show(l.StartPoint.X.ToString());
                    }
                    //listOfLines.Add(new LinkLines(lx1, ly1, lx2, ly2, Guid.NewGuid()));
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    MessageBox.Show(ex.StackTrace);
                }

            }
       }

【问题讨论】:

  • 你检查o.obj.GetType().ToString().Split('.').Last();了吗?可能某些数据出了问题。
  • 我已经取出了 l.startpoint.X,它会一直运行。我不知道它是否希望我解冻图层或将 obj 设置为可读或其他什么以便阅读?
  • 您需要打开一个事务,然后打开行对象(用于读取或写入),然后才能看到 StartPoint 值。
  • 我将对象从一个打开的事务中拉到一个列表中,然后访问它们。这可能是原因吗? @JamesDowthwaite
  • 尝试锁定文档using(var docloc = doc.LockDocument ())。把它放在你的 foreach 上面

标签: c# fatal-error autocad autocad-plugin


【解决方案1】:

仅当用于打开对象的事务仍处于活动状态时,才能安全地访问对象。如果您需要存储对对象的引用,请存储 ObjectId 并在需要访问对象属性时启动新事务。

【讨论】:

  • 我没有收集所有对象,然后翻译它们,而是翻译事务中的对象,然后使用自定义对象存储它们。感谢您的建议,效果很好。
【解决方案2】:

您的代码是否在主线程中运行? AutoCAD 不支持多线程。

【讨论】:

    【解决方案3】:

    试试这样的:

    public void getStartPoint(Transaction oTr, ObjectId oId)
    {
        try {
            Line oLn = (Line)oTr.GetObject(oId, OpenMode.ForRead);
    
            if (oLn != null) {
                Interaction.MsgBox(oLn.StartPoint.X.ToString);
            }
    
        } catch (System.Exception ex) {
            Interaction.MsgBox(ex.StackTrace, (MsgBoxStyle)MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, ex.Message);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2012-10-12
      • 2012-06-14
      • 1970-01-01
      相关资源
      最近更新 更多