找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1954|回复: 8

[ARX函数]:请问XDSOFT:如何在arx中让cad不关闭当前图形而打开另外一张图形

[复制链接]
发表于 2002-4-20 03:27:21 | 显示全部楼层 |阅读模式

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

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

×
如何在arx中让cad不关闭当前图形而打开另外一张图形?
而且不能在内存中同时启动两个autocad 2000.


是向cad发命令吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-4-20 03:40:51 | 显示全部楼层

Re: [ARX函数]:请问XDSOFT:如何在arx中让cad不关闭当前图形而打开另外一张图形

最初由 hotgirl 发布
[B]如何在arx中让cad不关闭当前图形而打开另外一张图形?
而且不能在内存中同时启动两个autocad 2000.


是向cad发命令吗? [/B]


使用命令应该行,但既然用了ARX,就应该用ARX的方法直接去实现而不比绕过一层命令来执行,下面是在MDI模式下的OPEN一个图形的代码。



  1. 在你的ARX程序里面使用 ActiveX Automation interfaces 。
  2. 下面的代码是关闭打开时候缺省的DRAWING1.DWG文件,另外打开新文件,你参考下。

  3. #include <acad15.h>
  4. #include <acad15_i.c>

  5. //
  6. // 注册你的命令的时候,要确保设置 ACRX_CMD_SESSION bit
  7. //
  8. // minimal error check for code brevity
  9. //
  10. void openDwg()
  11. {
  12.         CWinApp* pWinApp = acedGetAcadWinApp();
  13.         if(!pWinApp)
  14.                 return;
  15.         CComPtr<IDispatch> pDisp = pWinApp->GetIDispatch(TRUE);
  16.         if(!pDisp)
  17.                 return;

  18.         CComPtr<IAcadApplication> pComApp;
  19.         HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,
  20. (void**)&pComApp);
  21.         if(FAILED(hr))
  22.                 return;

  23.         CComPtr<IAcadDocument> pDoc;
  24.         hr = pComApp->get_ActiveDocument(&pDoc);
  25.         if(FAILED(hr))
  26.                 return;
  27.        
  28.         BSTR fName;
  29.         hr = pDoc->get_Name(&fName);

  30.         _bstr_t dwg1("Drawing1.dwg");
  31.         _bstr_t dwg2(fName);
  32.         if(SUCCEEDED(hr) && dwg1 == dwg2)
  33.         {
  34.                 _variant_t vb(VARIANT_FALSE);
  35.                 _variant_t vnam(dwg1);
  36.                 hr = pDoc->Close(vb, vnam);
  37.                 if(FAILED(hr))
  38.                 {
  39.                         acutPrintf("\nFailed to close drawing1.dwg.");
  40.                         return;
  41.                 }
  42.         }

  43.         _bstr_t fileName("c:\\test.dwg");

  44.         CComPtr<IAcadDocuments> pDocs;
  45.         hr = pComApp->get_Documents(&pDocs);
  46.         if(FAILED(hr))
  47.                 return;

  48.         _variant_t b(VARIANT_FALSE);
  49.         CComPtr<IAcadDocument> pDoc1;
  50.         hr = pDocs->Open(fileName, b, &pDoc1);
  51.         if(FAILED(hr))
  52.                 acutPrintf("\nFailed to open the dwg file.");
  53. }
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-4-20 03:42:52 | 显示全部楼层
如果你使用SDI模式,那么代码用下面的


  1. Note that in SDI mode, the code is changed as follows:
  2. //
  3. // minimal error check for code brevity
  4. //
  5. void openDwg()
  6. {
  7.     CWinApp* pWinApp = acedGetAcadWinApp();
  8.     if(!pWinApp)
  9.           return;
  10.     CComPtr<IDispatch> pDisp = pWinApp->GetIDispatch(TRUE);
  11.     if(!pDisp)
  12.           return;

  13.     CComPtr<IAcadApplication> pComApp;
  14.     HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication, (void**)&pComApp);
  15.     if(FAILED(hr))
  16.           return;

  17.     CComPtr<IAcadDocument> pDoc;
  18.     hr = pComApp->get_ActiveDocument(&pDoc);
  19.     if(FAILED(hr))
  20.           return;

  21.     _bstr_t fileName("c:\\test.dwg");
  22.     hr = pDoc->Open(fileName, &pDoc);
  23.     if(FAILED(hr))
  24.           acutPrintf("\nFailed to open the dwg file.");
  25. }
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-4-20 03:44:59 | 显示全部楼层

定义你自己的NEW命令


  1. There is no API exposed directly for the NEW command, but you can simulate it
  2. fairly closely. The idea is to copy the DWT file you want to use as a template
  3. into your destination file (for example, "Drawing.dwg"), and then open it using
  4. acedSyncFileOpen().

  5. The disadvantage of this approach is that the drawing will have a file name
  6. (if you create a NEW drawing normally, it will actually perform a SAVEAS when
  7. you first have to SAVE it - this new way of defining your NEW command means
  8. the drawing has a name when it is opened).


  9. #include "StdAfx.h"
  10. #include "StdArx.h"
  11. #include "resource.h"HINSTANCE _hdllInstance =NULL ;// This command registers an ARX command.
  12. void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
  13.     const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);// NOTE: DO NOT edit the following lines.
  14. //{{AFX_ARX_MSG
  15. void InitApplication();
  16. void UnloadApplication();
  17. //}}AFX_ARX_MSG// NOTE: DO NOT edit the following lines.
  18. //{{AFX_ARX_ADDIN_FUNCS
  19. //}}AFX_ARX_ADDIN_FUNCS
  20. /////////// NewDwg.cpp : Initialization functions
  21. ////////////////////////////////////////////////////////////////////
  22. // DLL Entry Point
  23. extern "C"
  24. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  25. {
  26.    if (dwReason == DLL_PROCESS_ATTACH){
  27.       _hdllInstance = hInstance;
  28.    }
  29.    else if (dwReason == DLL_PROCESS_DETACH) {
  30.    }
  31.    return TRUE;    // ok
  32. } /////////////////////////////////////////////////////////////////////////////
  33. // ObjectARX EntryPoint
  34. extern "C" AcRx::AppRetCode
  35. acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
  36. {
  37.    switch (msg) {
  38.       case AcRx::kInitAppMsg:
  39.          // Comment out the following line if your
  40.          // application should be locked into memory
  41.          acrxDynamicLinker->unlockApplication(pkt);
  42.          acrxDynamicLinker->registerAppMDIAware(pkt);
  43.          InitApplication();
  44.          break;
  45.       case AcRx::kUnloadAppMsg:
  46.          UnloadApplication();
  47.          break;
  48.    }
  49.    return AcRx::kRetOK;
  50. }// Init this application. Register your
  51. // commands, reactors...
  52. void InitApplication()
  53. {
  54.    // NOTE: DO NOT edit the following lines.
  55.    //{{AFX_ARX_INIT
  56.    AddCommand("ASDKMYNEW", "MYNEW", "MYNEW", ACRX_CMD_MODAL, mynewmynew);
  57.    //}}AFX_ARX_INIT   // TODO: add your initialization functions}// Unload this application. Unregister all objects
  58. // registered in InitApplication.
  59. void UnloadApplication()
  60. {
  61.    // NOTE: DO NOT edit the following lines.
  62.    //{{AFX_ARX_EXIT
  63.    acedRegCmds->removeGroup("ASDKMYNEW");
  64.    //}}AFX_ARX_EXIT   // TODO: clean up your application
  65. }// This functions registers an ARX command.
  66. // It can be used to read the localized command name
  67. // from a string table stored in the resources.
  68. void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
  69.   const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
  70. {
  71.    char cmdLocRes[65];   // If idLocal is not -1, it's treated as an ID for
  72.    // a string stored in the resources.
  73.    if (idLocal != -1) {      // Load strings from the string table and register the command.
  74.       ::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
  75.       acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);   }
  76.    else
  77.       // idLocal is -1, so the 'hard coded'
  78.       // localized function name is used.
  79.       acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
  80. } // NewDwgCommands.cpp
  81. // ObjectARX defined command#include "StdAfx.h"
  82. #include "StdArx.h"// This is command 'MYNEW'
  83. void mynewmynew()
  84. {
  85.    // TODO: Implement the command
  86.    const TCHAR newFile[] = "Drawing.dwg";
  87.    const TCHAR dwtFile[] = "Template\\Acad.dwt";
  88.    TCHAR dwtPath [ MAX_PATH ], *pLastSlash = NULL;
  89.    HMODULE hAcad = NULL;
  90.    // Get the Template file/pathname by:
  91.    //     get the pathname of the AutoCAD executable
  92.    //     find the final backslash
  93.    //     copy the template directory name and the template filename (e.g."Template\\Acad.dwt")
  94.    //       onto this path after the final backslash
  95.    // Copy this file to the destination path
  96.    // Open this file in the AutoCAD editor
  97.    if ( NULL == ( hAcad = ::GetModuleHandle (_T("acad.exe"))))
  98.       acutPrintf( "\nCannot get handle to AutoCAD's executable!" );
  99.    else if ( !::GetModuleFileName( hAcad, dwtPath, MAX_PATH ))
  100.       acutPrintf( "\nCannot get AutoCAD's location!" );
  101.    else if ( NULL == ( pLastSlash = strrchr( dwtPath, '\\' )))
  102.       acutPrintf( "\nCannot extract AutoCAD's path!" );
  103.    else if ( (pLastSlash - dwtPath) + strlen( dwtFile ) > MAX_PATH )
  104.       acutPrintf( "\nPath too long to get template path!" );
  105.    else {
  106.       strcpy( pLastSlash + 1, dwtFile );
  107.       // Do not overwrite file if it already exists (could do further checking here)
  108.       if ( !::CopyFile( dwtPath, newFile, TRUE )){
  109.          // Cannot copy file for one reason or another (if error 80 then file exists)
  110.          DWORD dwErr = GetLastError();
  111.          acutPrintf( "\nCannot copy template file, failed with error %d",dwErr );
  112.          return;
  113.       }
  114.       // See solution 3615 if you need to clear the DBMOD system variable
  115.       if ( /*Adesk::kFalse == */acedSyncFileOpen( newFile ))
  116.          // Opening the newly copied file has failed/been cancelled
  117.          ::DeleteFile( newFile );
  118.    }
  119. }
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-4-20 03:59:59 | 显示全部楼层

打开一个图形在新的窗口

//打开一个图形在新的窗口
        acDocManager->newDocument();
        acDocManager->appContextOpenDocument("图形文件");
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-4-24 02:38:16 | 显示全部楼层

acedSyncFileOpen(const char* pszFileToOpen)

如果新的图形不融入原图形中(不保留原图形信息),那么有更简单的办法,用下面的函数:
acedSyncFileOpen(const char* pszFileToOpen);

Note:
    acedSyncFileOpen() only works in SDI mode. In MDI mode, it returns eNotApplicable. This function will not be present in the next release of ObjectARX.(别怕,AcadR14~Acad2002中都适用)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-8-5 17:20:40 | 显示全部楼层
xiner :)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2008-7-30 10:19:30 | 显示全部楼层
下不了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2008-10-30 09:25:40 | 显示全部楼层
如何获取用户打开一个新的dwg的事件通知呢,
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-3 16:34 , Processed in 0.305552 second(s), 47 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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