【问题标题】:AcActDoc.Editor not declaredActActDoc.Editor 未声明
【发布时间】:2021-08-04 20:00:08
【问题描述】:

我一直在通过查看和学习其他人的代码来自学在 AutoCAD 中创建自定义命令。在我最近查看的一个示例中,我遇到了一个错误,即“AcActDoc”未声明。我找不到任何关于此的文档,我到处都找不到 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 As Editor = ActActDoc.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

【问题讨论】:

    标签: vb.net visual-studio-2019 autocad autocad-plugin


    【解决方案1】:

    AcActDoc 不是内置对象。它应该是您复制不完整提取的代码中的一个变量。看上面你注释的代码,AcActDocEd应该被声明和实例化为doced

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

    【讨论】:

      猜你喜欢
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 2010-12-19
      • 2011-02-06
      • 2021-11-21
      • 2013-05-07
      • 2019-03-21
      相关资源
      最近更新 更多