How can VC automatically notify AutoCAD to uninstall the ARX program when compiling the ARX project, and automatically load the newly compiled ARX program after compilation?

Source: Internet
Author: User

Compile ARXProgramWhen re-compiling the ARX project, you must manually uninstall the previously loaded and debugged ARX program, compile the program, and then load the new program, although the process is not complex, it is often annoying to do so. Is there a way for VC to automatically notify AutoCAD to uninstall this plug-in (the old ARX program) before starting compilation, and then start compilation. After compilation, then we will automatically notify AutoCAD to load the new ARX plug-in?

 

After checking the discussions of some friends in the QQ group, I finally found a feasible solution based on some of their ideas. This solution includes the following parts:

1. Add two custom commands for loading and detaching ARX programs

AutoCAD comes with several commands, such as appload and ARX, which can be used for loading and detaching ARX programs, but are all Gui-based operations, arx cannot be loaded or detached by using command lines. Therefore, we need to write two commands to load and uninstall the ARX program through the command line. This is easy to implement:

Create an ARX project called arxloader and add two commands, arxload and arxunload, respectivelyLoad and uninstall the ARX program specified by path:

Static void wdarxloader_arxload (void) {Achar arxpath [2, 134]; acedgetstring (1, null, arxpath); acrxdynamiclinker * plinker = acrxdynamiclinker; # ifdef ndebug // release versionplinker-> loadmodule (arxpath, false); # else // debug versionacedprompt (arxpath); plinker-> loadmodule (arxpath, true ); # endif} static void wdarxloader_arxunload (void) {Achar arxpath [134]; acedgetstring (1, null, arxpath); acrxdynamiclinker * plinker = acrxdynamiclinker; # ifdef ndebug // release versionplinker-> unloadmodule (arxpath); # else // debug versionacedprompt (arxpath); plinker-> unloadmodule (arxpath); # endif}

This project will generate a plug-in named wdarxloader. ARX, which contains the arxload and arxunload commands.

2. implement external programs to send AutoCAD commands to the AutoCAD main program

This step is critical, and the implementation method is also "odd ". Here is an articleArticleDescribes how to send commands to AutoCAD in various ways:

Techniques for calling AutoCAD commands programmatically

I used the method described in this article to send ANSYS commands to AutoCAD from our own external program.

Create a Win32 console project and add the followingCode:

#include 
  
   #include 
   
     bool callback enumwindowsproc (hwnd, lparam) {copydatastruct * pcmdmsg = (copydatastruct *) lparam; const int max_len = 256; tchar caption [max_len]; Assert (hwnd! = NULL);: getwindowtext (hwnd, caption, max_len); STD: wstring captionstr (Caption); If (captionstr. substr (2008) = _ T ("AutoCAD") {: sendmessage (hwnd, wm_copydata, null, (lparam) pcmdmsg);} return true ;} void senddomaintoacad (lpctstr cmd) {copydatastruct initialize MSG; then MSG. dwdata = (DWORD) 1; then MSG. cbdata = (DWORD) (_ tcslen (CMD) + 1) * sizeof (tchar); parse MSG. lpdata = (pvoid) cmd;: enumdesktopwindows (null, enumwindowsproc, (lparam) & 1_msg);} int _ tmain (INT argc, tchar * argv []) {If (argc> 1) {STD: wstring unloadcmd (argv [1]); unloadcmd + = _ T ("\ r"); sendmediatoacad (unloadcmd. c_str ();} return 0 ;}
   
  

The code used to send messages to the main AutoCAD window is similar to that used in references, but the method used to obtain the handle of the main AutoCAD window is different. In the original article, the adsw_acadmainwnd () function can only be used to obtain the handle of the main window from the ARX plug-in, it cannot be used in "external independent programs", so it can only be obtained through other indirect methods. For example, I use the method of enumerating all top-level windows here.

This project will generate a command line tool named senddesktoacad.exe.

3. Set the ARX project we want to compile.

In the properties page dialog box of the project, under the "All configuration" configuration, select "Build Events> pre-build event", and enter:

D: \ CPP \ ObjectARX \ acadtoansys \ release \ sendcmdtoacad.exe "arxunload $ (targetpath )"

Where, "d: \ CPP \ ObjectARX \ acadtoansys \ release \ send?toacad.exe" is the complete path of the command line tool we prepared in the previous step 2nd, "arxunload $ (targetpath) "is the command to be sent to AutoCAD for execution, used to notify AutoCADUninstallWe want to re-compile the ARX program.

Select "Build Events> pre-build event" and enter the following in "command line:

D: \ CPP \ ObjectARX \ acadtoansys \ release \ sendcmdtoacad.exe "arxload $ (targetpath )"

Where, "d: \ CPP \ ObjectARX \ acadtoansys \ release \ send?toacad.exe" is the complete path of the command line tool we prepared in the previous step 2nd, "arxload $ (targetpath) "is the command to be sent to AutoCAD for execution, used to notify AutoCADLoadWe have just re-compiled the ARX program.

4. Usage

Enter appload in AutoCAD to manually load the wdarxloader prepared in step 1. arx. Since then, we no longer need to manually load and uninstall the ARX program when re-compiling our ARX project. This process will be automatically notified to AutoCAD by VC to help us complete, all we need to do is simply reproduce and compile it,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.