CAD-objectArx development notes (two) --- command registration, table structure

table of Contents

One, register AutoCAD commands

  • method:
  1. Use the macro definition method: For example, the first part
  2. Use acedRegCmds class definition: as follows
  • Location: in the acrxEntryPoint.cpp file
  • Code sample ( / ----This area is written by the user ---- / )
/*  ------定义函数:后续会封装到自定义类中-----*/
void show() {

class CCtestApp : public AcRxArxApp {

	// 构造函数:空的
	CCtestApp () : AcRxArxApp () {}

	// 加载注册的命令:重写虚成员函数 On_kInitAppMsg ,返回状态码 AcRx::AppRetCode
	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
		// 需添加的依赖区(有则写)

		// 向导写的On_kInitAppMsg 函数,CAD传入指针与arx交互
		AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
		// 注册命令处
		// acedRegCmds类:Register command 封装注册命令:连接命令与函数
		/* ---addCommand函数:
		acedRegCmds->addCommand(L"CHU", L"hello", L"你好", ACRX_CMD_MODAL, show);
		// 返回状态码:按Ctrl点函数的返回类型AppRetCode,可跳转到返回类型列表
		return (retCode) ;

	// 卸载注册的命令:重写虚成员函数 On_kLoadDwgMsg,返回状态码
	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
		/*  ------删除命令组------	*/
		// removeGroup函数:
		//		删除一个组命令,还有removeCmd删除单一命令
		//		组名与addCommand对应即可,不用管下面的宏啥的

		// 向导写得:最后调用 On_kUnloadAppMsg 函数释放内存
		AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;

		// 卸载依赖区
		// 返回
		return (retCode) ;
	// 以下区不要动,包括静态函数static void CHUMyGroupMyCommand
} ;
// 宏定义区不要动

2. CAD table structure

  • CAD essence: the essence of a file in dwg format is onedatabase, Which stores the value of each block table
  • The following is enough, and we will introduce in depth later

2.1 ObjectARX class

Library prefix nameParaphrase
AcRxClasses used for registration and identification of binding applications and runtime classes
AcEdClass for registering local AutoCAD commands and AutoACD event notifications
AcDbAutoCAD database class
AcGiGraphical class showing AutoACD entities
AcGeCommon linear mathematics and geometry object application class

2.2 Specific explanation

2.2.1 AcRx library

  • Positioning: Provides some system-level classes for DLL initialization and linking and runtime class registration and identification. The base class is AcRxObject
  • Features:
  • Object runtime class identification and inheritance analysis
  • Add new protocol, object comparison test, object copy to existing class at runtime
  • The runtime type identification is that each subclass of AcRxObject has a related class descriptor object (AcRxClass type), which is used to identify the runtime type
  • The most commonly used functions:
  • AcRxObject::isA(); is used for class identification. The identified class must be able to test its type.
  • AcRxObject::isKindOf(); is also used for class identification, but the class here can be tested for its type, or for its derived class.
  • AcRxObject::desc(); returns the class name
  • AcRxObject::cast(); Attempts to convert a base class into a more advanced class. If the conversion is successful, the pointer of the base object will be the pointer of the converted type
  • AcRxObject::acrxUnlockApplication(); Make the application not uninstallable, and lock or unlock the application

2.2.2 AcEd library

  • Positioning: Provide classes for defining and registering new AutoCAD commands. The operating performance of the new commands is exactly the same as the AutoCAD internal commands
  • Function: Provide editor, reactor and a set of global functions for communicating with AutoCAD
  • Features: An important class in the library is AcEditorReactor, which monitors the status of the AutoCAD editor and notifies the application when a specified event occurs (such as shape start, stop, and delete commands)

2.2.3 AcDb library

Positioning: Provides the classes that make up the AutoCAD database


  • Storage: AutoCAD database is used to store all graphic objects and non-objects;
  • Graphic objects: called entities, composing AutoCAD drawings; non-graphic objects (such as layers, line styles and fonts) are also part of the graphics
  • Management: Use the AcDb library to query and manage the entity objects of AutoCAD entities, and you can also create new database object instances

The AutoCAD database contains the following main elements:

  • Environment variables: about 200 environment variables whose values ​​are set by AutoCAD
  • Named object dictionary (class AcDbDictionary): Provides a table of contents of AutoCAD drawings. For the new map, the catalog table contains four other dictionary IDs used by AutoCAD, and our application can add other objects to the dictionary at will
  • Nine symbol tables: each table has a unique command symbol table entry object
Symbol table nameSymbol table function
AcDbViewTable (view table)Applies to the AcDbViewTableRecord class, which represents the view stored in the database, and the view is associated with the CAD "VIEW" command
AcDbViewportTable (viewport table)Applies to the AcDbViewportTableRecord class, which represents the viewport setting when the value of the current system variable TILEMODE is 1 in CAD. The viewport configuration is created by CAD's VPORTS command. Not to be confused with the MVIEW command, when the value of the system variable TILEMODE is 0, this command creates a viewport entity
AcDbLinetypeTable (Linear Table)Applies to the AcDbLinetypeTableRecord class, which represents the linearity in the graph database
AcDbLayerTable (layer table)Applies to the AcDbLayerTableRecord class, representing the layer
AcDbTextStyleTable (text style table)Applies to the AcDbTextStyleTable class, which represents the text style
AcDbUCSTable (User Coordinate System Table)Applies to the AcDbUCSTableRecord class, which represents the user coordinate system stored in the graphics database
AcDbRegAppTable (application name registry)Applies to the AcDbRegAppTableRecord class, which represents the application name registered for the extended entity data of the object in the graph database
AcDbDimStyleTable (dimension style table)Applies to the AcDbDimStyleTableRecord class, which represents the dimensioning style in the graphics database
AcDbBlockTable (block table)Applies to the AcDbDimStyleTableRecord class, which represents the block defined in the graph database. This table contains two very important records: model space and paper space. All entities (visible objects) are placed in the block table AcDbBlockTable

2.2.3 AcGi library

  • Function: Provides a graphical interface for drawing AutoCAD entities
  • Functions: AcDbEntity member functions worldDraw(), viewportDraw() and saveAs(), all standard entity protocol components use this library

2.2.4 AcGe library

  • Positioning: Provides application classes, such as vectors and matrices, to complete two-dimensional and three-dimensional geometric operations. It also provides basic geometric objects such as points, curves and surfaces
  • Classification: AcGe also contains two main subsets: 2D and 3D geometry classes. The main abstract base classes are AcGeEntity2d and AcGeEntity3d.
  • Function: Provides 2D and 3D geometric calculations and mathematical calculation functions for mathematical calculations

Previous: CAD-objectArx Development Notes (1)—Environment Configuration
Next: CAD-objectArx Development Notes (3)—Line Objects