You need to enable JavaScript to run this app. AutoCAD.NET二次开发AcActDoc未声明错误正确写法咨询
优惠活动
大模型
产品
解决方案
定价
更多

AutoCAD.NET二次开发AcActDoc未声明错误正确写法咨询

错误原因

AcActDoc不属于AutoCAD .NET API的标准内置对象,属于标识符误用,因此触发未声明报错。

正确替换代码

你标注的错误代码行:

Dim Ed As Editor = AcActDoc.Editor

替换为以下内容即可(你的代码已经导入了Autodesk.AutoCAD.ApplicationServices命名空间,可直接使用该简化写法):

Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

可选优化

为了避免未打开任何文档时调用命令触发空引用异常,可补充非空判断逻辑:

Dim activeDoc As Document = Application.DocumentManager.MdiActiveDocument
If activeDoc Is Nothing Then
    Return
End If
Dim Ed As Editor = activeDoc.Editor

内容的提问来源于stack exchange,提问作者Ryan Ponsell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 19:45:08