找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 800|回复: 4

[求助]:调用CAD系统命令后如何取得其命令执行完的信息?(有图片和代码)

[复制链接]
发表于 2003-7-10 10:11:33 | 显示全部楼层 |阅读模式

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

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

×

  1.   [FONT=courier new]
  2. //调用CAD系统命令函数
  3. void SendCommandToAcad(CString cmd)
  4. {
  5.         HWND hAcad=adsw_acadMainWnd();
  6.         if(!hAcad) return ;
  7.         COPYDATASTRUCT cmdMsg;
  8.         cmdMsg.dwData=(DWORD)1;
  9.         cmdMsg.cbData=(DWORD)_tcslen(cmd)+1;
  10.         cmdMsg.lpData=cmd.GetBuffer(cmd.GetLength()+1);
  11.         SendMessage(hAcad,WM_COPYDATA,(WPARAM)hAcad,(LPARAM)&cmdMsg);
  12. }

  13. //徒手画任意钢筋
  14. void HandleDraw()
  15. {
  16.        
  17.         AcDbLayerTable *pLyrTable;
  18.         AcDbLayerTableRecord *pLyrTblRecord;
  19.         AcDbObjectId LayerId,CurLayId;
  20.        
  21.         gCyz_ArxBegin();
  22.         //取得指定图层的id,如果该层不存在则创建
  23.         LayerId = gConfig.GetLayerId(LGANGJIN);
  24.        
  25.         //取得指定钢筋宽度
  26.         double nOut = 100;
  27.         double d = gConfig.GetReinMainWidth()*nOut;
  28.        
  29.         gCyz_ArxEnd();

  30.         acdbCurDwg()->getLayerTable(pLyrTable, AcDb::kForRead);
  31.        
  32.         //获取当前层表ID
  33.         CurLayId = acdbCurDwg()->clayer();
  34.        
  35.         pLyrTable->close();

  36.         //设置当前层为钢筋层
  37.     acdbCurDwg()->setClayer(LayerId);

  38.         //图形数据库指针
  39.         AcDbDatabase *pCurDb = NULL;
  40.        
  41.         //获取当前图形数据库
  42.         pCurDb = acdbCurDwg();

  43.         //取得当前的Plinewid
  44.         double b = pCurDb->plinewid();
  45.         pCurDb->setPlinewid(d);
  46.        
  47.         //调用CAD系统PLine函数
  48.         SendCommandToAcad("_pline\n");

  49.         //此处的返回原层并还原原Plinewid         
  50.         //pCurDb->setPlinewid(b);
  51.         //acdbCurDwg()->setClayer(CurLayId);

  52. }

  53.   [/FONT]
复制代码



上面代码的功能是想实现在指定层上用指定宽度的Pline画钢筋,调用系统的PLine命令完成画钢筋以后,想还原到系统原层和PLine的原宽度,但结果是代码后面的2行在Pline命令没有结束的时候就执行了。。。请问有没有方法在PLine命令执行完成以后再执行代码的最后2行呢? 请高手指点。。。。。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
 楼主| 发表于 2003-7-10 11:13:38 | 显示全部楼层
这里我主要的目的不是为了实现上面的功能。。因为ARX的SAMELP里面有关于PLine的完整的源代码。。。在那里更改相关的设置都可以实现。。。。

我主要是想知道,调用CAD命令之后如何获取其命令执行完毕的信息。。。请高手指点指点。。。谢谢了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2003-7-10 11:29:55 | 显示全部楼层
最初由 Echoyin 发布
[B]这里我主要的目的不是为了实现上面的功能。。因为ARX的SAMELP里面有关于PLine的完整的源代码。。。在那里更改相关的设置都可以实现。。。。

我主要是想知道,调用CAD命令之后如何获取其命令执行完毕的信息。。。?.. [/B]


在ARX里面为什么还要用PLINE命令去画PLINE呢,这时候控制权交给了ACAD,会很不好控制的,为什么你不用ads_getpoint 等先交互获得点,然后用ARX生成PLINE实体? PLINE命令的所有功能都可以用ARX实现的。


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

使用道具 举报

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

使用道具 举报

发表于 2003-7-11 00:16:42 | 显示全部楼层

Re: [求助]:调用CAD系统命令后如何取得其命令执行完的信息?(有图片和代码)

最初由 Echoyin 发布
[B][CODE]
  
//调用CAD系统命令函数
void SendCommandToAcad(CString cmd)
{
        HWND hAcad=adsw_acadMainWnd();
        if(!hAcad) return ;
        COPYDATASTRUCT cmdMsg;
        cmdMsg.dwData=(DWORD)1;
        ... [/B]


在ApplicationContext中,你的SendCommandToAcad()函数以及acedCommand() 和 sendStringToExecute()都会以异步的方式执行Acad命令( 就是你说的这种情况).  
然而,你可以利用AutoCAD Automation API 提供的'SendCommand'方法来同步执行.(翻译太累,直接看英文吧)

Question
How can I call a command from the application context synchronously? acedCommand
seems to work properly from the document context but it does not work in the
application context.
Answer
See DevNote #35993. If you want to call a built-in AutoCAD command from the
application context, use the sendStringToExecute API. Note that this API is
asynchronous in a sense that the Sent command won't be executed until the
current message handler returns.

However, the AutoCAD Automation API provides another method 'SendCommand' that
immediately executes the sent command when called from the application context.
However, if the command you send to AutoCAD prompts the user for any input, the
Sent command may not fully execute, particularly if SendCommand is not invoked
at the end of an ARX function. In this degenerate case, the command string will
be output on the command line, but not all prompts will be issued (as in the
case of an AutoLISP expression) and the program will move on to executing any
lines of code following the call to SendCommand.

If your application needs to execute some code when an interactive command
finishes, you should consider moving that code to the commandEnded() reactor
notification. Do not place any lines of code in a function after the call to
SendCommand as this will prematurely terminate the command execution.

The attached sample shows how to use Automation API to execute the LINE command
synchronously from a modeless dialog.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-23 16:30 , Processed in 0.438217 second(s), 40 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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