使用一些古老的代码尝试从Excel工作表在ACAD 2018中创建表
一切顺利进行,直到我尝试创建一行并显示错误消息;无效的过程调用或参数
oDBxDoc.PaperSpace。AddLine sp,ep创建oDbxDoc,并在监视窗口中显示它是有效的AxDbDocument
在剥离AutoCAD 2017 my PC之前,代码(我认为)是有效的……但这个项目已经进行了几个月,我的内存越来越差
我的测试模块:
- Sub ACADCreateDwg()
- On Error GoTo ErrorHandler
- ' Testing Variables
- Dim oDBx As cObjDbx
- Dim oDBxDoc As AxDbDocument ' Object ' Late binding!
- Dim OpenName As String
- Dim SaveName As String
- Dim sp(0 To 2) As Single
- Dim ep(0 To 2) As Single
- Set oDBx = New cObjDbx
- sp(0) = 0#: sp(1) = 0#: sp(2) = 0#
- ep(0) = 34#: ep(1) = 23#: ep(2) = 0#
- OpenName = "D:\Dropbox\AMCE Work Folders\Substation Spreadsheets\Sag-Tension Workbook\XML OUTPUT FROM PLS-CADD\Sag_Tables.dwt"
- SaveName = "TEST"
- ' Open the template file
- oDBx.xOpen OpenName
- ' Cast the Doc property object as an AxDbDocument Ojbect
- Set oDBxDoc = oDBx.Doc
- ' Add a line
- oDBxDoc.PaperSpace.AddLine sp, ep
- oDBx.xSaveAs oDBx.OrigPath, "Copy of ", "1"
- oDBx.xClose
- 'There 's no New method on an AxDbDocument.
- '
- 'If you want to create a new document that's derived
- 'from a template, just open the template (DWT) file
- 'in the AxDbDocument, and when you've done what you
- 'need, save it as a .DWG file.
- Exit Sub
- ErrorHandler:
- Debug.Print Err.Description
- Stop
- oDBx.xClose
来自Ed Jobe的课程模块(大约2006年)
- Option Explicit
- '=================================================================================================
- ' Purpose : Create an object class for access Autocad via the ObjectDBX
- '
- ' Date : 01/19/18
- ' Updated :
- '=================================================================================================
- ' Need code to differentiate the various versions of ACAD?
- ' 2018-01-19
- ' Replaced AXDBLib with AXDBLib
- '=================================================================================================
- ' References Requires
- ' AutoCAD C:\Program Files\Common Files\Autodesk Shared\acax22enu.tlb
- ' AXDBLib C:\Program Files\Common Files\Autodesk Shared\axdb22enu.tlb
- ' Scripting C:\Windows\SysWOW64\scrrun.dll
- '=================================================================================================
- 'copyright 2006, Ed Jobe
- ' Note: This requires ObjectDBX to be registered on each
- ' user's machine. This is done automatically on 2004 and up.
- ' In your AutoCAD folder, locate the file AxDb15.dll.
- ' This only needs to be done once at each machine. If you are using vb instead
- ' of vba, you will also need to set a reference to "ObjectDBX 1.0 Type library"
- ' and "Microsoft Scripting Runtime".
- ' This class auto-registers the dll, but here is the normal procedure---
- ' From the dos command line, type:
- ' C:\> cd Autodesk\Map200i
- ' C:\Autodesk\Map2000i> RegSvr32.exe AxDb15.dll
- 'This class unfortunately doesn't follow standards for objects due to the fact that
- 'I was unable to Implement the properties/methods of ObjectDbx. Normally, the Open,
- 'Close, Save and SaveAs methods would belong in the doc class. But since you can't use
- 'the Implements statement on ObjectDbx, I had to move them to this class. This class
- 'uses late binding to be able to handle versioning. In order to access all the
- 'methods/properties of an AxDbDocument in your project, you must Dim a variable as
- ' type AxDbDocument and then the object returned by the Doc property to cast it as
- ' an AxDbDocument object. Therefore, this class does not reference AxDb15.dll, so
- 'your project needs to.
- 'Last error number used: 1003
- 'Variable declarations for Properties
- Private oDoc As AxDbDocument ' Object
- Private strOrigPath As String
- Private strTempPath As String
- Private strExt As String
- Private bReadOnly As Boolean
- 'Property Declarations
- '*********************
- Public Property Get Doc() As Object
- Set Doc = oDoc
- End Property
- Public Property Get Ext() As String
- Ext = strExt
- End Property
- Public Property Get OrigPath() As String
- OrigPath = strOrigPath
- End Property
- Public Property Get TempPath() As String
- TempPath = strTempPath
- End Property
- Public Property Get ReadOnly() As Boolean
- ReadOnly = bReadOnly
- End Property
- 'Class Methods
- '*************
- Public Sub xClose()
- 'required for proper cleanup of temp files
- Set oDoc = Nothing
- End Sub
- Private Function acadVerNum() As String
- Dim verNum As String
- verNum = "HKEY_CLASSES_ROOT\AutoCAD.Drawing\CurVer"
-
- Dim wsh As Object
- ' Error trapping
- On Error GoTo ErrorHandler
-
- 'access Windows scripting
- Set wsh = CreateObject("WScript.Shell")
-
- 'read key from registry
- Dim resKey As String
- resKey = wsh.RegRead(verNum)
-
- acadVerNum = Right(resKey, 2)
-
- Set wsh = Nothing
- Exit Function
-
- ErrorHandler:
- acadVerNum = ""
- Set wsh = Nothing
-
- End Function
- Public Sub xOpen(FilePath As String)
- 'Sets the Doc property to an ObjectDBX Document
- 'late binding is used to avoid setting a reference.
- '
- On Error GoTo ErrHandler
-
- Dim dbxdoc As AxDbDocument 'Object
- Dim strTempName As String
- Dim fso As Scripting.FileSystemObject
- Dim fsoFile As Scripting.File
- Dim colPCs As AcadPlotConfigurations
- Dim objPC As AcadPlotConfiguration
- Dim varList As Variant
- Dim i As Integer
- Dim cnt As Integer
- Dim iActiveLayout As Integer
- Dim strObjDbxPath As String
- Dim ACAD As Object
-
- bReadOnly = False
- strOrigPath = FilePath
-
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- Cleanup:
|