Frontiers in Computing and Intelligent Systems ISSN: 2832-6024 | Vol. 6, No. 3, 2023 41 Research on Secondary Development Method based on Haochen CAD Yongchuan Ren 2, Guofeng Xie 2, Feng Liu 2, Kaihuai Luo 1, Tianxing Chen 1, * 1 College of Mechanical Engineering, Southwest Jiaotong University, Chengdu, Sichuan, China 2 Civil Aviation Logistics Technology Co., Ltd., Chengdu, Sichuan, China * Corresponding author: Tianxing Chen (Email: txchen@swjtu.cn) Abstract: This article explores the methods and techniques of using Haochen CAD for secondary development in the fields of engineering design and drawing. By studying the secondary development method of Haochen CAD, the customizability and scalability of the software can be improved to meet specific design requirements in different industries and needs. Emphasis was placed on exploring the technical means of secondary development, including Object ARX, VB, and C # NET and other different programming languages and interfaces, and analyzed specific application cases of secondary development in engineering design. Keywords: Haochen CAD; Secondary Development; Scalability; Customization; Programming Interface. 1. Introduction With the rapid development of information technology, software, as one of the core driving forces of the information age, has a significant impact on the national economy, security, and technological strength. The localization of software, as a strategy to ensure information security, enhance technological autonomy and controllability, and promote technological innovation and industrial development, is valued and promoted by the country. Therefore, Haochen CAD is chosen as the secondary development object of this article. Haochen CAD has powerful graphics processing capabilities and is currently a popular computer-aided drawing software in China. In order to improve the efficiency of drawing and reduce human errors in the drawing process, it is particularly important to carry out secondary development of CAD drawing software to achieve intelligent generation of non- standard conveying equipment drawings [1]. 2. Research on the Secondary Development Method of Haochen CAD 2.1. The Method of Secondary Development of Haochen CAD Using VB The VB software package provides many extension modules called components. These components are reusable program code and data created by ActiveX technology, consisting of one or more objects. By utilizing these extension components, VB has gained powerful additional features that enable it to operate various application software, such as Excel, Word, etc. By using the Haochen CAD ActiveX component, VB can obtain control handles for operations on Haochen CAD, thereby directly controlling a series of operations on Haochen CAD [2]. To program for the secondary development of Haochen CAD using VB language, the first step is to connect and run VB with Haochen CAD. The following two steps are required: before writing the code, reference the object library in the programming environment; Write VB program code, create Haochen CAD objects, and start running Haochen CAD. Table 1. Creating a Line in Haochen CAD Using VB Number Operate Command 1 Create a reference to Haochen CAD in VB Dim acadApp As AcadApplication Set acadApp = GetObject(, "Grx CAD.Application") 2 Check if Haochen CAD has been opened If acadApp Is Nothing Then MsgBox Exit Sub End If 3 Create a new graphic file Dim acadDoc As AcadDocument Set acadDoc = acadApp.Documents.Add 4 Create a straight line in a drawing file Dim startPoint(0 To 2) As Double Dim endPoint(0 To 2) As Double startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0 endPoint(0)=100:endPoint(1) = 50: endPoint(2) = 0 Dim lineObj As AcadLine Set lineObj = acadDoc.ModelSpace.AddLine(startPoint, endPoint) 5 Save and Close Drawing Files acadDoc.Save acadDoc.Close 42 After connecting VB with Haochen CAD, you can use the properties and methods of the object and its subordinate objects to achieve graphic drawing and editing operations in the Haochen CAD environment using VB language [3]. Taking connecting to Haochen CAD in VB and creating a simple straight line as an example. 2.2. The Method of Using Object ARX for Secondary Development of Haochen CAD Object ARX is an object-oriented C++ application development mechanism that fully utilizes the inheritance, encapsulation, and polymorphism characteristics of C++ classes. Through these features, it significantly improves the security of applications and the reusability of code. In addition, Object ARX also supports MFC basic class libraries, allowing developers to efficiently implement many complex functions [4]. The graphic database of Haochen CAD is an object manager responsible for managing graphics and their attribute data. Developers can add new management and mechanisms according to the requirements of the application, and integrate them into this system. Creating a new Object ARX project in an integrated development environment is a common practice [5]. Firstly, select the appropriate project type, such as DLL or application, and then set the basic properties and configuration of the project. This process provides developers with a foundational framework that enables them to leverage the features of Object ARX to build customized CAD applications. 2.2.1. Basic Structure of the Program ARX applications typically exist in the form of dynamic link libraries. Haochen CAD uses acrxEntryPoint() to call the ARX program. This function is not only the entry point for communication between Haochen CAD and ARX, but also serves as a channel for ARX applications to send messages to the system and return status codes to Haochen CAD through it. All call requests implemented through the function ads_defun are processed through acrxEntryPoint(). This design allows acrxEntryPoint() to play a crucial role in the entire ARX application, responsible for managing and scheduling the interaction and communication between the ARX program and Haochen CAD[6]. 2.2.2. Message Transmission between ARX and Haochen CAD The message transmission process between ARX and Haochen CAD is almost entirely one-way (from Haochen CAD to ARX program). In the acrxEntryPoint() function definition, a switch statement interprets messages sent from Haochen CAD[7], performs appropriate operations on each message, and returns an integer state value. Write code in Object ARX to create a new Haochen CAD command and draw a straight line as an example: Table 2. Creating a Line in Haochen CAD Using Object ARX Number Operate Command 1 Define a new Haochen CAD command void drawLineCmd() { AcGePoint3d startPt(0, 0, 0); AcGePoint3d endPt(100, 50, 0); AcDbLine* pLine = new AcDbLine(startPt, endPt); 2 Add newly created lines to model space AcDbBlockTable* pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord* pSpace; pBlockTable->getAt(ACDB_MODEL_SPACE, pSpace, AcDb::kForWrite); pBlockTable->close(); pSpace->appendAcDbEntity(pLine); pSpace->close(); pLine->close(); } 3 Initialization function Extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) { switch (msg) { case AcRx::kInitAppMsg: acedRegCmds->addCommand(_T("MYCOMMANDS"), _T("MYLINE"),_T("MYLINE"), ACRX_CMD_TRANSPARENT, drawLineCmd); break; case AcRx::kUnloadAppMsg: acedRegCmds->removeGroup(_T("MYCOMMANDS")); break; } return AcRx::kRetOK; } 2.3. The Method of Using C#.NET for Secondary Development of Haochen CAD C# applications and Haochen CAD can run in the same process space, and communicate with the Haochen CAD system in a shared address space by obtaining an instance of the Haochen CAD application. This approach allows applications to use Windows messaging mechanisms to send messages to Haochen CAD objects and directly call the core 43 functions of Haochen CAD[8]. With the help of the core database structure, graphics system, geometric modeling core, and its code of Haochen CAD, new commands can be established that operate in the same way as the inherent commands of Haochen CAD, thereby improving operational efficiency and stability. In C# projects, it is usually necessary to reference the CAD software provided NET API library. These libraries are usually NET assemblies can access classes and methods in APIs by adding references[9]. By using CAD software provided NET API allows you to write code in C# projects to perform the required operations. These operations may involve creating, modifying, and deleting CAD objects, performing functions such as data processing, exporting, and importing. Through this approach, developers can leverage the interactivity between C# and CAD software to achieve various customized functions and operations. Using C# to interact with Haochen CAD and creating a straight line in Haochen CAD as an example: Table 3. Create a straight line using C# in Haochen CAD Number Operate Command 1 Add references in the form using System; using GrxCAD.Runtime; using GrxCAD.ApplicationServices; using GrxCAD.DatabaseServices; using GrxCAD.Geometry; using GcadVbaLib 2 Create Line Code namespace CADDevelopment { public class MyCommands { [CommandMethod("DrawLine")] public void DrawLine() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { BlockTable acBlkTbl; BlockTableRecord acBlkTblRec; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Line acLine = new Line(new Point3d(0, 0, 0), new Point3d(100, 50, 0)); acBlkTblRec.AppendEntity(acLine); acTrans.AddNewlyCreatedDBObject(acLine, true); acTrans.Commit(); } } } } 3. Conclusion The secondary development of Haochen CAD provides rich programming tools and interfaces, allowing users to expand and customize the functions of Haochen CAD according to their own needs, thereby improving work efficiency and design quality. Secondary development technology is widely used in automated annotation, customized commands, data exchange, and processing, providing engineers with more flexibility and convenience. With the continuous development of technology, we can expect to see more secondary development methods based on new technologies such as cloud computing and artificial intelligence in the field of software engineering, which will further enhance the customization and scalability of Haochen CAD. References [1] Chen Xiaoyan Research on the Application of CAD Technology in Mechanical Drawing [J]. China Equipment Engineering, 2023 (17): 241-244. [2] Wang Hongliang, Zhang Xiuyun, Zhang Lin. Drawing Batch Drawings Using VB and AutoCAD [J]. Tool Technology, 2019,53 (01): 112-116. [3] Chen Jiaxin, He Qiao. A motor model automatic drawing system based on VB for secondary development of AutoCAD [J]. Mechanical and Electrical Engineering Technology, 2021, 50 (11): 17-20. 44 [4] Liu Tongcheng, Lin Yu. AutoCAD Secondary Development and Application Example Based on Object ARX [J]. Automation Technology and Application, 2006, (05): 35-37. [5] Fan Lamei Research on the Design Method of End Boundary Map for Open pit Mines Based on AutoCAD Secondary Development [D]. Xi'an University of Architecture and Technology, 2023. DOI: 10.27393/d.cnki.gxazu.2022.001029. [6] Wang Chuanjun. Secondary Development of AutoCAD Dimensioning Testing System Based on Object ARX [J]. Digital Technology and Applications, 2013, (03): 195-196. DOI: 10.19695/j.cnki.cn12-1369.2013.03.136. [7] R. Wang, "Development of Parametric Drawing Program Based on AutoCAD VBA," 2010 International Conference on Computational Aspects of Social Networks, Taiyuan, China, 2010, pp. 757-760, doi: 10.1109/CASoN.2010.174. [8] X. Luo, S. Wu, D. Zhang, S. Yu, H. Ren and Y. Wu, "Research on the 3D visual rapid design platform of belt conveyor based on AutoCAD," 2010 International Conference on Mechanic Automation and Control Engineering, Wuhan, China, 2010, pp. 168-171, doi: 10.1109/MACE.2010.5535529. [9] Li Hong and Chun-Sheng Ma, "Development of common parts and standard parts database based on AutoCAD," 2010 International Conference on Computer Application and System Modeling (ICCASM 2010), Taiyuan, China, 2010, pp. V13- 467-V13-470, doi: 10.1109/ICCASM.2010.5622855. [10] Liu Xiaoguang Implementation Technology of CAD Software Secondary Development Platform [J]. Electronic Technology and Software Engineering, 2016 (05): 59-60.