C ++ Builder to develop AutoCAD applications

zhaozj2021-02-12  132

※ Programming skill application practice ※

C Builder to develop AutoCAD applications

Zhou Yongjun (Water Conservancy Department Shanxi Water Resources Hydraulic Survey and Design Institute 030024)

Abstract: The programming method for AutoCAD secondary development is numerous. This paper focuses on a general method for developing AutoCAD applications with C Builder methods. The application developed by this method is better, and there is no need for other auxiliary system support, and the application is convenient and fast. The programming method introduced in this article is currently a more popular ActiveX component method, also called component object model in C Builder.

[Keywords] COM program design ActiveX interface type library C Builder AutoCAD

1 C Builder Development Platform

C Builder is an excellent visual programming environment in Borland, USA, launched in 1997. It provides us with a very attractive fast application development system (RAD) in the 32-bit Windows environment; it is based on the most popular object-oriented programming language C , and has a wide range of programmers; it provides Support for ActiveX impeccable, full packing for Windows API and DirectX. C Builder is far more than Visual C and Borland C and other development environments, but its powerful development features have not weakened, it can be said that C Builder has a bridge between functionality and ease of use of software development. .

C Builder has developed on Borland C and Delphi. It uses the world-leading Borland C compiler and highly visual graphics platform to develop very efficient and independent procedures. Compared to other development tools of AutoCAD, the programmer can get the player to get rid of AUTOLISP's brackets and the inefficiency of the execution of the execution, and can also develop binary code than the VBA program more efficient and confidential.

C Builder has a representative version of 3.0 and 5.0. The version 6.0 introduced in February 2002 is the current latest version. The program development introduced herein is based on version 5.0.

2 development of AutoCAD version

AutoDesk launched the AutoCAD R14 version in 1996, making AutoCAD a standard Windows application. The AutoCAD 2000 version begins to formally become a multi-document management program for Microsoft standards. Another feature is embedded in VBA (Visual Basic Application), which enhances AutoCAD development and customization. The 2002 and 2003 versions are mainly to enable AutoCAD to be strengthened in terms of ease of use and network function.

3 Why use C Builder to develop AutoCAD applications

This article recommends using C Builder to develop AutoCAD applications. The main reasons are as follows.

(1) The C Builder development platform is very easy to use and powerful, and there are numerous graphical components that meet the needs of our daily programming, which can greatly improve programmer programming efficiency.

(2) Applications developed by C Builder can be run independently from the C Builder development platform and the AutoCAD application platform. It is not like a VBA program to rely on an AutoCAD graphics file. It is necessary to load and uninstall.

(3) The C Builder application is a real compiler. The execution program is short, the execution efficiency is high, and it is convenient to transfer between networks and strong confidentiality.

Another external reason, people currently learning and using C / C language are very common, while the use of Lisp language and VBA language is not very popular, so developing AutoCAD applications with C Builder is very advantageous. 4 C Builder Development AutoCAD Application Basic Method

The basic way to develop the AutoCAD app is based on Microsoft's ActiveX Automation technology. This technology is a technique that can control another or several programs from one program internal, where the program is called an Automation customer or controller as a program, and the program is called an Automation server. The application we have developed here is a client program, and the AutoCAD program is a server program.

The development platform used herein is based on C Builder 5, requiring AutoCAD to 2,000 or more. In addition, there is an acad.tlb file in the AutoCAD software installation directory (default "C: / Program Files / AutoCAD 2002 /"), which is the type library file of AutoCAD. The program design described in this article is dependent on this file.

This article introduces a simple program, its function is just a circle in the AutoCAD model space. Although this program is relatively simple, it almost includes all ideas and methods designed by AutoCAD ActiveX program. You can make readers with an intuitive and fast understanding of AutoCAD's ActiveX Automation program.

Figure 1 Imports Type Libray dialog

Figure 2 Programming Form Interface

(1) Start C Builder.

(2) Save the project. Save the form file as cadu1.cpp and save the item as CADP. At this time, the name of the project is saved in the C Builder IDE window title bar.

(3) Introduced type library. Select the "Import Type Libray" submenu in the Project menu, the dialog box appears (Figure 1).

All registered type libraries are listed in the dialog, and AutoCAD 2000 TYPE LIBRAY [VERSION 1.1] (AutoCAD2000's type library, 2002, and version of the type library are also applicable). If there is no autocad type library in the list, it has not been registered yet, click the [Add] button, find the acad.tlb file in the AutoCAD program directory, select the [OK] button, then add increasing in the list "AutoCAD 2000 Type Library".

Select the AutoCAD2000 type library, click the [CREATE UNIT] button, and wait for the system will automatically generate the jacket file and its header files of the AutoCAD type library, the default file name is AutoCAD_TLB.CPP and AutoCAD_TLB.H. And automatically add the jacket file to the CADP project.

(4) Design in the form. The form of Form1 is designed according to Figure 2. Select the button button in the toolbar, place it in the appropriate location of Form1, the system automatically names button1, then change the CAPTION attribute to "Start CAD"; placed a Button button in the form, the system is automatically named Button2 , Change its CAPTION attribute to "draw round". Finally, change the CAPTION attribute of Form1 to "AutoCAD ActiveX Automation". The formation of the setup completed is shown in Figure 2.

(5) Add code. Select menu [View] → [Toggle Form / Unit], or press the F12 button directly to jump to the code editing window, add the following code before the member function is defined.

IACADAPPLICATIONDISP ICAD; // Declaration Program Object

Double-click Button1, the system automatically generates the name of the Button1Click member function, the cursor is positioned in the blank place of the function body, continue to add the following code: icad.binddefault (); // Connect to the server program

Icad.visible = true; // Setting the program object is visible

Double-click Button2, the system automatically generates the blank place named the Button2Click member function, the cursor is positioned in the blank place of the function body, here is added as follows:

IACADDocumentDisp Doc = icad.activeDocument; // Pass the activity document to the document object

IACADMODELSPACEDISP MDS = doc.modelspace; // Pass the model space to its object

ACAD_POINT CEN; / / Define Centrifugal Point

Variant Pt1; / / Define Variant Temporary Variables

Double TMP; // Define temporary variables

Pt1 = varRaycreate (OpenArray); // Create a Variant type array, data type is Double

TMP = 200.0;

Pt1.putelement (TMP, 0); / / assigning the first component to the array

TMP = 200.0;

Pt1.putelement (TMP, 1); // assign a value for the second component of the array

TMP = 0.0;

Pt1.putelement (TMP, 2); // Assign a value to the third component of the array

Cen = pt1; // set the number of temporary variables to the center point

Mds.addcircle (CEN, 100.0); // Call the discoction method in the model space

Icad.zoomall (); // Update program object

(6) Contains the header file. In the File menu, select the "Use Unit" dialog box, select AutoCAD_TLB, select AutoCAD_TLB, click the [OK] button, and the system automatically adds a line in the unit file of TForm1:

#include "autocad_tlb.h"

(7) Compile and connect. Select the Make option in the Project menu, the system makes a series of compile, connection work, if there is no error, the execution file CADP.EXE will be created.

(8) Run the program. CADP can be run in the C Builder IDE environment or from the IDE environment. We choose to get from the IDE environment. Find the CADP.EXE file in the Windows Explorer (the default path is the directory where the project file is located), and double-click to run the program. Click the [Start CAD] button, will start the AutoCAD program later, then click the [Discoller] button, the program will draw a circle in its model space.

5 other questions

When performing a professional program design, you can assign a value for the point component of the ACAD_POINT type in the above instance to be designed as a function, which is very convenient to use.

The author has applied the programming method introduced in this article to the development of multiple professional drawings, good application.

Readers who are interested in the programming methods described herein can write to the author or the engineering geological computer application cooperation network (GEOCOM.HHCC.NET.CN) and the author discussed together, the author's electronic mailbox address: zzyyjj @ sina. COM.

转载请注明原文地址:https://www.9cbs.com/read-7211.html

New Post(0)