I have been teaching myself to make custom commands in AutoCAD by looking at and learning from others' code. In a recent example I've been looking at I am encountering an error that "AcActDoc" is not declared. I cannot find any documentation on this, 0 results everywhere I look. If this is a typo in the code, does anyone know what it is supposed to be? I've separated and made bold the line in question.
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 = 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
is not a built-in object. It should be a variable in the code of which you have copied an incomplete extract. Look at the upper code you commented, AcActDoc
and Ed
should be declared and instantiated as doc
and ed
:
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor