微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ActActDoc.Editor 未声明

如何解决ActActDoc.Editor 未声明

通过查看和学习他人的代码,我一直在自学如何在 AutoCAD 中创建自定义命令。在最近的一个示例中,我一直在查看我遇到的错误,即未声明“ActDoc”。我找不到任何关于此的文档,到处都是 0 结果。如果这是代码中的错字,有人知道它应该是什么吗?我已将相关行分开并加粗。

Imports System.Collections.Generic
Imports Autodesk.AutoCAD.applicationservices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DataExtraction
Imports PBHSDes.PBHSDClass
Public Class DataExtract
'Const path As String = "c:\Program Files\AutoCAD 2009\Sample\"
'Const fileName As String = "Visualization - Aerial.dwg"

<CommandMethod("extd")>
Public Sub extractData()
    'If Not System.IO.File.Exists(path + fileName) Then
    '   Dim doc As Document = Application.DocumentManager.MdiActiveDocument
    '   Dim ed As Editor = doc.Editor
    '   ed.WriteMessage(vbLf & "File does not exist.")
    '   Return
    'End If

Dim Ed 作为编辑器 = AcActDoc.Editor

    Dim fileRes As PromptFileNameResult
    Dim PrFileOpts As New PromptOpenFileOptions("Select File To Extract Data:")
    'PrFileOpts.SearchPath = True
    PrFileOpts.PreferCommandLine = False
    PrFileOpts.Filter = "AutoCAD Drawing files (*.dwg)|*.dwg"
    fileRes = Ed.GetFileNameForOpen(PrFileOpts)
    'you should check the status so if they cancel the dialog the method stops
    If fileRes.Status <> PromptStatus.OK Then Return
    Const outputXmlFile As String = "c:\temp\data-extract.xml"
    Dim Path As String = FileIO.FileSystem.GetParentPath(fileRes.StringResult)
    Dim filename As String = FileIO.FileSystem.GetName(fileRes.StringResult)
    MsgBox(Path & vbCrLf & filename)
    ' Create some settings for the extraction 
    Dim es As IDxExtractionSettings = New DxExtractionSettings()
    Dim de As IDxDrawingDataExtractor = es.DrawingDataExtractor
    de.Settings.ExtractFlags = ExtractFlags.ModelSpaceOnly Or ExtractFlags.XrefDependent Or ExtractFlags.nested
    ' Add a single file to the settings 
    Dim fr As IDxFileReference = New DxFileReference(Path,Path + filename)
    de.Settings.DrawingList.AddFile(fr)
    ' Scan the drawing for object types & their properties 
    de.discoverTypesAndProperties(Path)
    Dim types As List(Of IDxTypeDescriptor) = de.discoveredTypesAndProperties
    ' Select all the types and properties for extraction 
    ' by adding them one-by-one to these two lists 
    Dim selTypes As New List(Of String)()
    Dim selProps As New List(Of String)()
    For Each type As IDxTypeDescriptor In types
        selTypes.Add(type.GlobalName)
        For Each pr As IDxPropertyDescriptor In type.Properties
            If Not selProps.Contains(pr.GlobalName) Then
                selProps.Add(pr.GlobalName)
            End If
        Next
    Next
    ' Pass this information to the extractor 
    de.Settings.SetSelectedTypesAndProperties(types,selTypes,selProps)
    ' Now perform the extraction itself 
    de.ExtractData(Path)
    ' Get the results of the extraction 
    Dim dataTable As System.Data.DataTable = de.ExtractedData
    ' Output the extracted data to an XML file 
    If dataTable.Rows.Count > 0 Then
        dataTable.TableName = "My_Data_Extract"
        dataTable.WriteXml(outputXmlFile)
    End If
End Sub
End Class

解决方法

AcActDoc 不是内置对象。它应该是您复制了不完整摘录的代码中的变量。看你注释的上面代码,AcActDocEd应该声明并实例化为doced

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。