CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于迁移自动化项目 (VBA/ActiveX)

2023-1-5 05:43| 发布者: admin| 查看: 1039| 评论: 0|来自: AutoCAD

摘要: 通常,在 VBA IDE 中创建或使用 Visual Studio 创建的 AutoCAD 自动化项目可能需要一些更新才能在 AutoCAD 2021。

通常,在 VBA IDE 中创建或使用 Visual Studio 创建的 AutoCAD 自动化项目可能需要一些更新才能在AutoCAD 2021 中使用。

有关对 ActiveX API 所做的更改的一般历史记录,请参阅“ActiveX API 历史记录”。

ActiveX 库引用

在 AutoCAD 绘图环境或其他支持 VBA 的应用程序(如 Microsoft Word 或 Excel)中创建的 VBA 项目中,可能需要更新对 AutoCAD ActiveX API 的引用。使用 AutoCAD ActiveX API 的托管 .NET 和 ObjectARX 应用程序可能也需要更新。

下表列出了基于 AutoCAD 的产品版本支持的 AutoCAD 对象库的文件名。

释放 发布编号 AutoCAD 类型库 AutoCAD/ObjectDBX 类型库
AutoCAD 2021 R24,0 acax24<language>.tlb axdb24<language>.tlb
AutoCAD 2020 23.1 acax23<language>.tlb axdb23<language>.tlb
AutoCAD 2019 23.0 acax23<language>.tlb axdb23<language>.tlb
AutoCAD 2018 22.0 acax22<language>.tlb axdb22<language>.tlb
AutoCAD 2017 21.0 acax21<language>.tlb axdb21<language>.tlb
AutoCAD 2016 20.1 acax20<language>.tlb axdb20<language>.tlb
AutoCAD 2015 20.0 acax20<language>.tlb axdb20<language>.tlb
AutoCAD 2014 19.1 acax19<language>.tlb axdb19<language>.tlb
AutoCAD 2013 19.0 acax19<language>.tlb axdb19<language>.tlb
AutoCAD 2012 18.2 acax18<language>.tlb axdb18<language>.tlb
AutoCAD 2011 18.1 acax18<language>.tlb axdb18<language>.tlb
AutoCAD 2010 18.0 acax18<language>.tlb axdb18<language>.tlb
AutoCAD 2009 17.2 acax17<language>.tlb axdb17<language>.tlb
AutoCAD 2008 17.1 acax17<language>.tlb axdb17<language>.tlb
AutoCAD 2007 17.0 acax17<language>.tlb axdb17<language>.tlb
AutoCAD 2006 16.2 acax16<language>.tlb axdb16<language>.tlb
AutoCAD 2005 16.1 acax16<language>.tlb axdb16<language>.tlb
AutoCAD 2004 16.0 acax16<language>.tlb axdb16<language>.tlb
AutoCAD 2002 15.2 acax15.tlb axdb15.tlb
AutoCAD 2000i 15.1 acax15.tlb axdb15.tlb
AutoCAD 2000 15.0 acax15.tlb axdb15.tlb
注意:<语言>表示对象库的语言。例如,<language>在英语装置上可能是enu,在法语装置上可能是fra

下面列出了早期版本使用的其他 AutoCAD ActiveX API 的文件名以及它们已替换为最新版本的对象库文件:

  • acETransmit17.tlbvia acETransmit19.tlb– 更改为acETransmit20.tlb
  • AcSmComponents17.tlb to AcSmComponents23.tlb– 更改为 AcSmComponents24.tlb
  • cao16<language>.tlb– 更改为cao20<language>.tlb

最新版本中的新增对象和更改对象

新对象

未添加新对象。

更改的对象

The following table describes the changes made to existing objects.

AutoCAD 2020 AutoCAD 2021 Description of change

AutoCAD.AcadLayerStateManager.23

AutoCAD.AcadLayerStateManager.24

Use to create an instance of the AutoCAD Layer States Manager based on the latest library installed. AutoCAD.AcadLayerStateManager

AutoCAD.AcCmColor.23

AutoCAD.AcCmColor.24

Use to create an instance of an AutoCAD color object based on the latest library installed. AutoCAD.AcCmColor

AutoCAD.Application.23 or AutoCAD.Application.23.1

AutoCAD.Application.24

Use to create an instance of the AutoCAD application based on the latest library installed. AutoCAD.Application

If you want to ensure an instance of AutoCAD 2021 is created, use . AutoCAD.Application.24

AutoCAD.SecurityParams.23

AutoCAD.SecurityParams.24

Use to create an instance of an AutoCAD security parameters object based on the latest library installed. AutoCAD.SecurityParams

General Changes from an Earlier Release

In addition to updating COM library references, the following changes might need to be made to migrate a program from an earlier release:

  • The methods and properties used for 64-bit support must be revised. These changes are outline in the "64-bit Migration" section.
  • Starting with AutoCAD 2015-based products, the method sends a command string to an object and executes it asynchronously. The execution of the VBA project is suspended until the last command executed by the command string is completed or terminated and returns the document to an idle state. In earlier releases, the command string was sent to the object without suspending the VBA and you to pass values to the current command using the method. SendCommandAcadDocumentAcadDocumentSendCommand

    For example, the following worked in AutoCAD 2014-based products and earlier:

    ThisDrawing.SendCommand "._LINE "
    ThisDrawing.SendCommand "0,0 5,5 "

    In AutoCAD 2015-based products and later, the previous code would execute the LINE command and then wait for the user to provide points. After the LINE command was completed or terminated the second method would be executed. You would change the previous code to the following to execute correctly: SendCommand

    ThisDrawing.SendCommand "._LINE 0,0 5,5 "

    If you need to break your code statements up across multiple lines, you might be able to utilize the method which posts a command string to the object and executes the string synchronously. Synchronous execution of the command string means that it is executed when the outermost procedure is executed and the object is in an idle state. PostCommandAcadDocumentAcadDocument

  • The method no longer supports the ability to assign a password to a drawing. Password protection is no longer supported. Remove the object from the parameter of the method to update the code statement for use in the latest release. SaveAsAcadSecurityParamsvSecurityParamsSaveAs

64-bit Migration

Starting with AutoCAD 2014, AutoCAD supports VBA 7.1 which offers native 64-bit support. This change will require you to maintain two versions of your VBA projects: 32-bit and 64-bit. In releases prior to AutoCAD 2014, VBA ran as an out-of-process component, accessed through a 32-bit-to-64-bit “thunking” layer which allowed existing 32-bit VBA projects to function as expected in AutoCAD 64-bit.

VBA 64-bit requires the use of different libraries and controls for forms. Not all VBA libraries and form controls are available in 64-bit yet, and you might need to adjust some of your code to work correctly on both Windows 32-bit and Windows 64-bit.

If your VBA projects were developed for AutoCAD 2009 through AutoCAD 2013, you need to take the following into consideration when migrating VBA projects to the latest release:

  • Controls used on forms originally created for Windows 32-bit might need to be updated or replaced with a 64-bit alterative to execute correctly on Windows 64-bit.
  • Methods and properties created specifically to allow VBA 32-bit to work with AutoCAD 64-bit are now obsolete and have been removed. Replace the use of the obsolete method and property with the correct method and property, often removing "32" from the name of the method or property is enough.
Handling ObjectId

Beginning with AutoCAD 2009 64-bit through AutoCAD 2013 64-bit, object IDs were represented by a 64-bit integer datatype (). Accessing those values in 32-bit VBA caused a compilation error. As a resolution, a new set of method names suffixed with "32" corresponding to the old methods were created (e.g. , ). Those methods used the data type, which internally mapped to the 64-bit integer data type. __int64ObjectID32()OwnerID32()LONG

To be more precise, a 32-bit Object ID was created internally for each object ID required in VBA. This ID was mapped to its 64-bit actual ID, so that if the 32-bit ID was passed back to AutoCAD from VBA code, then the 64-bit object ID could be returned and used internally for all purposes.

The following sample gives an example of ported 32-bit Object ID code:

Original code 64-bit (AutoCAD 2009 through AutoCAD 2013)

Dim splineObj As AcadSpline
Dim objectID As Long
objectID = splineObj.objectID32
Dim tempObj As AcadObject
Set tempObj = ThisDrawing.ObjectIdToObject32(objectID)

Code ported for AutoCAD 2014 64-bit and later compatibility

Dim splineObj As AcadSpline
Dim objectID As Long
objectID = splineObj.objectID
Dim tempObj As AcadObject
Set tempObj = ThisDrawing.ObjectIdToObject(objectID)

VBA applications can also use an object’s handle instead of its object ID. The following sample shows how to use the handle instead of the object ID:

Original code using an object's Object ID

Dim splineObj As AcadSpline
Dim objectID As Long
objectID = splineObj.objectID
Dim tempObj As AcadObject
Set tempObj = ThisDrawing.ObjectIdToObject(objectID)

Revised code using an object's handle

Dim splineObj As AcadSpline
Dim objectHandle As String
objectHandle = splineObj.Handle
Dim tempObj As AcadObject
Set tempObj = ThisDrawing.HandleToObject(objectHandle)
Appendix of 32-bit Methods (Obsolete with AutoCAD 2014 64-bit and Later)
Note: Object IDs are no longer converted to the data type for AutoCAD 32-bit. LONG

The following table lists the methods that were used in AutoCAD 2009 64-bit through AutoCAD 2013 64-bit as 32-bit substitutions:

VBA Methods for a 64-bit System
Method - AutoCAD 2009 through 2013 Method - AutoCAD 2014 and Later Use
GetBlockAttributeValue32 GetBlockAttributeValue Returns the attribute value from the specified block cell for the attribute definition object contained in the block using its 32-bit object ID.
GetBlockTableRecordId32 GetBlockTableRecordId Gets the 32-bit object ID of the block table record associated to the block-type cell and nContent.
GetFieldId32 GetFieldId Returns the 32-bit object ID of the field object associated to the specified cell.
获取网格线型32 获取网格线类型 返回网格线型对象的 32 位对象 ID。
键32 钥匙 指定 64 位系统操作中源对象的对象 ID。CopyObjects
对象ID32 对象标识 获取 64 位系统的对象 ID。
对象ID到对象32 对象ID到对象 获取与 64 位系统的给定对象 ID 对应的对象。
所有者ID32 所有者编号 获取 64 位系统的所有者(父)对象的对象 ID。
设置块属性值32 设置块属性值 使用块和 nContent 的 32 位对象 ID 为块和nContent中包含的属性定义对象设置指定块单元中的属性值。
SetBlockTableRecordId32 SetBlockTableRecordId 设置与块类型单元格和nContent 关联的 32 位对象 ID 块表记录。
SetFieldId32 SetFieldId 设置与指定单元格和nContent 关联的字段对象的 32 位对象 ID。
设置网格线型32 设置网格线类型 设置网格线类型对象的 32 位对象 ID。
值32 价值 为 64 位系统指定属性的当前值或新创建的克隆对象的对象 ID。

路过

雷人

握手

鲜花

鸡蛋

最新评论

AutoLISP AutoCAD二次开发

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-7 05:31

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部