CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

提示和技巧

2022-12-31 04:52| 发布者: admin| 查看: 900| 评论: 0|来自: AutoCAD

摘要: 本主题概述了在编写 ObjectARX 应用程序时应注意的事项。

本主题概述了在编写 ObjectARX 应用程序时应注意的事项。

开发者应选择退出客户参与计划

开发人员应选择退出客户参与计划,以防止在从调试器运行 AutoCAD 时导致此类崩溃。

通过网络使用 .NET 程序集文件

默认情况下,不能通过网络使用 .NET 程序集文件。只有在授予它们特殊权限的情况下,才能通过网络将它们加载到 AutoCAD 中。

递增的 AutoCAD 注册表号

对于基于 AutoCAD 的产品和 RealDWG主机应用程序的每个新版本,注册表号都将递增,以确保持续的并行安装支持。仅当引入与先前版本不兼容的 API 时,主内部版本号才会递增。当版本与以前的版本二进制兼容时,次要内部版本号将递增。

ObjectARX/ObjectDBX 加载机制仅检查与主机应用程序版本匹配的注册表部分。它不会在多个位置查找。因此,如果您的产品需要支持多个不同版本的需求加载,则必须将需求加载条目添加到每个版本的注册表部分。

理想情况下,注册表号的更改不应影响应用程序的代码,因为不应在任何地方硬编码此编号。相反,如果应用程序需要在运行时知道正确的注册表项,则应使用适当的 API。ObjectARX 应用程序(换句话说,扩展名为 .arx 的应用程序)应该使用 theandfunction 或 theglobal function。ObjectDBX 模块(换句话说,扩展名为 .dbx的模块)应使用全局函数来获取正确的注册表项。这些函数始终返回主机应用程序版本的正确注册表项。AcDbHostApplicationServices::getUserProductRegistryRootKey()AcDbHostApplicationServices::getMachineProductRegistryRootKey()acrxProductKey()acrxObjectDBXRegistryKey()

AcDbBlockReference::appendAttribute()派生类不支持

派生自的类不能追加属性。这是设计使然。调用派生类的对象将导致错误。AcDbBlockReferenceappendAttribute()AcDbBlockReferenceeIllegalEntityType

为工作空间和 CUI 对话框注册类

派生自的对象(包括选项板集和工具选项板集)可以编写一个注册表项,以确保工作区的安全操作,并使它们显示在“自定义用户界面”对话框中。有关详细信息,请参阅《ObjectARX 开发人员指南》中的“注册从 CAdUiDockControlBar 派生的对象”。CAdUiDockControlBar

自定义对象的所有权层次结构

在自定义对象的所有权层次结构中,请务必调用以正确建立每个对象的所有者后台指针。AutoCAD/ObjectDBX 的未来版本可能会停止在增量保存中写入具有空所有者 ID 的对象。setOwnerId()

发布对象启用程序

ADN 网站不再包含对象启用程序部分。开发人员应该在自己的网站上发布他们的对象启用码,并让客户知道它们在哪里可用。

标注文本和定义点行为

尺寸定义点和文本位置均受尺寸布局要求的约束。使用以下任一功能,可以更改传入的位置以适应尺寸的布局需求,该布局需求由尺寸类型和当前 dimvar 设置确定。

AcDbDimension::setTextPosition()
AcDbAlignedDimension::setDimLinePoint()
AcDbRotatedDimension::setDimLinePoint()
AcDb3PointAngularDimension::setArcPoint()
AcDb2LineAngularDimension::setArcPoint()

例如,当 DIMFIT = 3 时,对于具有定义点的径向尺寸,使得径向线与 X 轴成小于或等于 15 度,可以设置文本位置的 X 坐标,但始终会调整 Y 坐标以沿尺寸的径向线定位文本。

kLoadDwgMsg 和 aceedCommand()

在两个基本上下文中工作:在 RQXLOAD 和 RQSUBR 请求代码上操作时。但是,在 ObjectARX 中,它不适用于 ObjectARX 应用程序消息,该消息相当于 RQXLOAD 的 ObjectARX。它适用于消息,等效于 RQSUBR。acedCommand()AcRx::kLoadDwgMsgAcRx::kInvkSubr

对于许多应用程序来说,在每个图形编辑任务开始时执行一些 AutoCAD 命令非常重要。这可以通过对 AutoLISP 表达式进行排队来实现,包括使用函数,在编辑会话初始化期间执行,在执行之后。(command)ads_queueexpr()(s::startup)

请注意,在调用 to 期间不会执行排队的表达式。它们将在应用程序从其消息调用返回后发生。ads_queueexpr()kLoadDwgMsgacrxEntryPoint()

使用时,输入的字符串必须完全展开,并带有外括号。以前在 aschains 中传递的任何内容都必须转换为 ASCII 才能使用此机制。ads_queueexpr()resbuf

从回调多次调用是完全可以接受的。它们按呼叫顺序排队。ads_queueexpr()kLoadDwgMsg

请勿在任何其他上下文中使用。这样做会产生不可预知的结果,甚至可能是有害的,因为在活动的 AutoLISP 评估、MENU 项和/或 SCRIPT 执行都处于静止状态之前,可能不会查看队列。请谨慎使用此功能,因为一旦可以实现原始设计,它就会被删除。ads_queueexpr()

Do Not #define ACAD_OBJID_INLINE_INTERNAL

The header files acdb.h and dbidar.h contain an section which selects a header to based on . Applications should never this value. There are parallel headers for the lightweight ID types, some of which are for internal AutoCAD use only. Applications that attempt to will not compile successfully. #ifdef#includeACAD_OBJID_INLINE_INTERNAL#define#defineACAD_OBJID_INLINE_INTERNAL

Freeing Strings Returned as Non-const Pointers

When calling methods that return non-const string pointers (for example, ), you should free the memory occupied by the returned string. For example: AcDbSymbolTable::getName(char&* pName)

// The getName() call should be followed by a call to
acutDelString(pLtName);pLtTableRcd->getName(pLtName);

// ... other code
acutDelString(pLtName);

Note that some of the ObjectARX sample files are missing calls to free the memory, so they will exhibit memory leaks. When using the samples in your own code, make sure to free the memory properly.

ObjectARX Does Not Support Multi-Threaded Programming

If you spawn multiple threads in your application, make sure that no more than one of the threads at a time invokes anything in the ObjectARX system.

Remove Selections Before Aborting Transactions

Certain interactions between transactions, the UNDO command, and the Object Property Toolbar (OPT) can put AutoCAD in an unstable condition. To avoid such situations, your ObjectARX application should always remove the pickfirst selection prior to aborting transactions, as shown here:

acedSSSetFirst(NULL, NULL);
actrTransactionManager->abortTransaction();

MFC PropertySheets with ObjectARX

Tabbed dialog boxes should use the base classes defined in the acui24.lib MFC extension DLL library. Do not use the MFC classes and . Use and instead. See the ObjectARX Developer's Guide and ObjectARX Reference for details. CPropertySheetCPropertyPageCAcUiTabMainDialogCAcUiTabChildDialog

Using on Class Definitions is Hazardous__declspec(dllimport)

Using the construct on a class exported to other applications can cause vtables to reside in all DLLs that instantiate that class. If any of these instantiating DLLs is unloaded, all instances created by that DLL become invalid. Subsequent attempts to access virtual functions on these invalid instances triggers a memory fault. __declspec(dllimport)

Consequently, the only safe way to use this directive with classes derived from , for example, is to mandate that no application that instantiates the class may be unloadable. To enforce this mandate, you must either document it clearly and visibly, or supply a pseudo-constructor that resides in a DLL or application that cannot be unloaded. The best policy is to avoid using this construct altogether. AcDbObject

The only exception to this warning applies if the class exports a static data member. In this case, you must use on that data member only, but you should avoid applying the construct to the entire class. Exporting static data members is not recommended. __declspec(dllimport)

This warning applies only to . It does not apply to . __declspec(dllimport)__declspec(dllexport)

The recommended usage is as follows:

#pragma warning( disable: 4275 4251 )
#ifdef POLYSAMP
#define DLLIMPEXP __declspec( dllexport )
#else
#define DLLIMPEXP
#endif

// The "DLLIMPEXP" is only required for exporting a poly API or using
// the exported API.  It is not necessary for any custom classes that
// are not exporting an API of their own.
//
class DLLIMPEXP AsdkPoly: public  AcDbCurve
{
public:
    ACRX_DECLARE_MEMBERS(AsdkPoly);
//*****************************************************************
// Constructors and destructor
//*****************************************************************

在调试配置中构建 ObjectARX 应用程序时出现 PDB 警告

构建 ObjectARX 应用程序的调试版本时,您可能会看到类似于以下内容的 LNK4099 链接器警告:

rxapi.lib(libinit.obj) : 警告 LNK4099: PDB “acdbhdr.pdb” 未找到带有 “..\..\..\lib\rxapi.lib“ 或 ”C:\ObjectARX\samples\editor\mfcsamps\dynamic_dg\Debug\acdbhdr.pdb“;链接对象,就好像没有调试信息一样

出现此警告的原因是 ObjectARX 库是使用 ObjectARX SDK 未附带的 PDB 文件构建的。忽略这些警告是安全的。

标准C++标头和_DEBUG预处理器符号

如果在定义_DEBUG预处理器符号时包含任何标准C++标头,则通过杂注强制调试C++运行时。(查看Visual C++中的use_ansi.h。您不希望在 ObjectARX 应用程序中使用调试C++运行时。

若要避免这种情况,请应用以下解决方法:

#ifdef _DEBUG
#undef _DEBUG
#endif

不必要的需求加载活动

AutoCAD 有时可能会要求加载定义类的应用程序,即使正在加载的 DWG 或 DXF 文件中没有该类的对象也是如此。如果您观察到这一点并希望防止不必要的需求加载 .dbx.arx应用程序,只需将图形保存为 DWG 或 DXF 格式,然后重新打开该文件。此过程可以在有或没有可用应用程序的情况下完成。

在重新加载文件之前,先完全打开,然后完全保存。

AcGiGeometry::pline()功能支持代理图形

在以前的版本中,代理图形 DWG 数据结构无法处理折线(pline)基元的复杂性。此限制已从 AutoCAD 2004 中得到解决。因此,该函数现在支持代理图形上下文。AcGiGeometry::pline()


路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 14:38

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部