找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 613|回复: 0

[ARX程序]:ARX教程,英文版的,怕english的莫进!

[复制链接]
发表于 2002-11-27 19:15:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Step 1 - Project Settings - Command Registration

--------------------------------------------------------------------------------
Introduction
In this step you will learn how to set up a new ObjectARX project in Visual C++ and you will build your first ObjectARX application.
Creating a New Project
From the "File" pull down menu of Visual C++ 6.0, select "New."
Select the "Projects" tab in the dialog that appears.
Select "Win32 Dynamic-Link Library" in the list of project types.
Enter the desired project name, for example "Project" in the Project name edit box.
Set the Location to the folder where you want your project to be stored, then click "OK."

Step 1 Figure 1 - Starting a New Project

In the new dialog (Step 1 of 1), choose "An empty DLL project."
Click "Finish" and then "OK."
Compiler Settings
From the "Project" pull down menu, select "Settings..." to display the "Project Settings" dialog.

Step 1 Figure 2 - Select Project Settings

NOTE: Initially the "Settings For:" list box on the left side of the dialog box (See Figure 3) should be set to "Win32 Debug." If you need to make changes to both the debug and release version of your application, choose "All Configurations" in the combo box. Unless explicitly specified, the settings below apply to both versions.
  

Select the C/C++ tab on the right side of the dialog box to access the compiler settings.
Make sure the project name itself is selected in the "Settings for:" window tree view (and not a sub item).
In the "Settings For:" list, choose "All Configurations."
In the "Category:" combo box, select "Code Generation."
In the "Use run-time library" edit box, choose "Multithreaded DLL."



Step 1 Figure 3 - Project Compiler Settings
  

In the "Category:" combo box, select "Preprocessor."
In the "Additional include directories:" field, add the path to your ObjectARX include files. Typically, this is: C:\ObjectARX 2000\inc.
Linker Settings
In the "Project settings" dialog box, select the "Link" tab to access the linker settings.
Make sure the "Category:" combo box is set to "General."
On the left side of the dialog box, select "Win32 Debug" in the "Settings For:" combo box.
In the "Output File Name:" edit box, you will see "Debug/<Project>.dll". Change the file name extension from .dll to .arx. It is recommended that you use the extension .arx because it is the default extension that AutoCAD expects for ARX applications.
     NOTE: This setting specifies the location and the name of the executable the linker will produce. It is the ObjectARX executable file for your application that will be loaded in AutoCAD.
On the left side of the dialog box, select "Win32 Release" in the "Settings For:" combo box.
In the "Output File Name:" edit box, you will see "Release/<Project>.dll." Change the file name extension from .dll to .arx.
On the left side of the dialog box, select "All Configurations" in the "Settings For:" combo box.
In the "Object/library modules" edit box, add the following library file names to the beginning of the list the following library file names: rxapi.lib acrx15.lib acutil15.lib acedapi.lib. These are the only ObjectARX libraries we need for this very basic ObjectARX application. More sophisticated applications may need to link to other ObjectARX libraries.

Step 1 Figure 4 - Project Linker Settings
  

Set the "Category:" combo box to "Input."
In the "Additional Library Path:" field, enter the path for your ObjectARX  library files. Typically, this is C:\ObjectARX 2000\lib.
Close the "Project Settings" dialog by clicking "OK."
Our Project Settings are now complete. Next we will add the code required to allow us to print "Hello World" on the AutoCAD command prompt.
Adding Code to the Project
From the "Project" pull down menu, select "Add to Project" and then "New...".
Make sure the "Files" tab is selected in the "New" dialog box.
Select "C++ Source File" as the file type and enter "Project" in the "File name:" edit box. Click "OK."

First, we need to include two ObjectARX header files: aced.h and rxregsvc.h. These are the header files for Rx application definitions and C access to AutoCAD Editor-specific services (aced.h) and the header for the acrxXXX utility functions (rxregsvc.h). Add them as follows:
  #include <aced.h>
#include <rxregsvc.h>


Next, we declare two functions:

initApp() - which will be called by AutoCAD when our application is loaded and
unloadApp() - which is called when our application is unloaded.

Please refer to the acrxEntryPoint() function below to see how these functions are being called by AutoCAD. Add the lines:
  void initApp();
void unloadApp();


Next, we declare our own function to print "Hello world!" on the AutoCAD command line. Add:
  void helloWorld();


Now we will define the initApp() function. This function registers a new command with the AutoCAD command mechanism. This new command will become an additional entry point into our application:
  void initApp()
{
    // register a command with the AutoCAD command mechanism
    acedRegCmds->addCommand("HELLOWORLD_COMMANDS",
                            "Hello",
                            "Bonjour",
                            ACRX_CMD_TRANSPARENT,
                            helloWorld);
}


For details regarding the acedRegCmds macro and the addCommand() method (of AcEdCommandStack class), please refer to the ObjectARX online help file. The first argument of addCommand() is the command group name (it includes only one command in our case). The second argument is the global/untranslated command name. The third argument is the local/translated name for the same command. The fourth argument is the command flag (note that here we define a transparent command, which means that the command can be invoked while another command is active). Finally, the last argument is the pointer to the function being called by our command. In C++ this is the function name itself.

Next we define the unloadApp() function. This function will remove our command group, which will also removes our command. Since commands registered with AutoCAD become additional entry points into our application, it is absolutely necessary to remove them when the application is unloaded. Add:
  void unloadApp()
{
    acedRegCmds->removeGroup("HELLOWORLD_COMMANDS");
}


Next we define our helloWorld() function; acutPrintf() is the equivalent of the C printf function redirected to the AutoCAD command line. Add:
  void helloWorld()
{
    acutPrintf("\nHello World!");
}


Pretty basic indeed!

Now we need to define the most important function for ObjectARX applications. All ObjectARX applications have one main entry point that is used for messaging: the acrxEntryPoint() function. Remember that an ObjectARX application is a DLL and thus does not have a  main() entry point. AutoCAD calls the ObjectARX module acrxEntryPoint() function to pass messages to the application.

The first parameter of acrxEntryPoint() is a data member of the AcRx class called msg which represents the message sent from the ObjectARX kernel to the application. Refer to the online help for details about the different messages an ObjectARX application can receive from AutoCAD.

In our very simple example, we need to be notified when the application is loaded and unloaded in order to register and "deregister" our "hello" command. In the first case we will call our initApp() function; in the second case we will call our unloadApp() function.

The second parameter of acrxEntryPoint() is an opaque handle to data passed to different functions, such as the lock and unlock functions (this data changes depending on the message passed by AutoCAD).

By default applications are locked, which means that once loaded they cannot be unloaded. Since our application is very simple (it does not define objects that AutoCAD and other applications refer to, except our command), we can safely unlock our application to make it unloadable, provided that we remove our command first, which is achieved in our unloadApp() function.

Also by default, ObjectARX applications are not MDI aware (again, please refer to the online help for detailed information on the MDI issues). Applications need to register themselves explicitly as being MDI aware using the acrxRegisterAppMDIAware() global function.

NOTE: Registering an application as being MDI aware is not in itself enough for the application to be effectively MDI aware. The criteria that need to be met are described in details in the ObjectARX online documentation.

Since our application is very simple (it does not use the concept of Document and does not interact with the AutoCAD drawing database), we can safely register it as being MDI aware using the acrxRegisterAppMDIAware() global function. Add:
  extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
    switch (msg)
    {
        case AcRx::kInitAppMsg:
            acrxDynamicLinker->unlockApplication(pkt);
            acrxRegisterAppMDIAware(pkt);
            initApp();
            break;
        case AcRx::kUnloadAppMsg:
            unloadApp();
            break;
        default:
            break;
    }
    return AcRx::kRetOK;
}


Finally, we need to export the acrxEntryPoint() function so that AutoCAD can access it. There are several ways to do so. One consists of creating a definition (.def) file.

Creating a Definition (.DEF) File
From the "Project" pull down menu, select "Add to Project" and then "New...".
Make sure the "Files" tab is selected in the "New" dialog box.
Select "Text File" as the file type and enter "Project.def" in the "File name:" edit box. Click "OK."

Add the following information to the new file. All ObjectARX applications have to export at least two functions: acrxEntryPoint and acrxGetApiVersion.
  LIBRARY      "Project"
EXPORTS
        acrxEntryPoint          PRIVATE
        acrxGetApiVersion       PRIVATE


Our project is ready to be built. If you have followed the tutorial correctly, you should get 0 errors and 0 warnings. Load hello.arx in AutoCAD and type "hello" to run our command.

To load hello.arx, choose one of these methods:

Simply drag the file from Explorer to the AutoCAD Window.
Use the AutoCAD "ARX" command, "Load" option at the command line prompt.
From the Tools pull down menu in AutoCAD, select the  "Load Application..." option.

Once the application is loaded, typing "hello" or "bonjour" on the command line will display the "Hello World!" message.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-6-27 07:29 , Processed in 0.364346 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表