找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 874|回复: 2

[分享] [学习笔记]ARX反应器

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2017-5-13 22:34:19 | 显示全部楼层 |阅读模式

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

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

×
在alisp中这样写两个这样的反应器

  1. (vlr-dwg-reactor nil '((:vlr-beginsave . _beginsave) (:vlr-enddwgopen . _enddwgopen)))
  2. (defun _beginsave (o e)
  3.   (setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  4.   (vla-addtext ms "bbs.xdcad.net" (vlax-3d-point '(0 0 0)) 100.0)
  5.   (princ)
  6. )
  7. (defun _enddwgopen (o e)
  8.   (princ (getvar "dwgname"))
  9.   (princ)
  10. )

ARX 的反应器就是自己写一个类,继承自那些 AcXXXXReactor类 , 以上两个反应器ARX代码如下,采用 ObjectARX 向导类生成
自定义类 .h

  1. //-----------------------------------------------------------------------------
  2. //----- CDwgReactors.h : Declaration of the CDwgReactors
  3. //-----------------------------------------------------------------------------
  4. #pragma once

  5. #ifdef ARXPROJECT2_MODULE
  6. #define DLLIMPEXP __declspec(dllexport)
  7. #else
  8. #define DLLIMPEXP
  9. #endif

  10. //-----------------------------------------------------------------------------
  11. #include "aced.h"

  12. //-----------------------------------------------------------------------------
  13. //----- Note: Uncomment the DLLIMPEXP symbol below if you wish exporting
  14. //----- your class to other ARX/DBX modules
  15. class /*DLLIMPEXP*/ CDwgReactors : public AcEditorReactor2 {

  16. protected:
  17.         //----- Auto initialization and release flag.
  18.         bool mbAutoInitAndRelease ;

  19. public:
  20.         CDwgReactors (const bool autoInitAndRelease =true) ;
  21.         virtual ~CDwgReactors () ;

  22.         virtual void beginSave(AcDbDatabase* pDb, const ACHAR* pIntendedName);//反应器事件
  23.         virtual void beginDwgOpen(ACHAR* filename);//反应器事件

  24.         virtual void Attach () ;//
  25.         virtual void Detach () ;
  26.         virtual AcEditor *Subject () const ;
  27.         virtual bool IsAttached () const ;
  28. } ;

自定义类 .cpp

  1. //-----------------------------------------------------------------------------
  2. //----- CDwgReactors.cpp : Implementation of CDwgReactors
  3. //-----------------------------------------------------------------------------
  4. #include "StdAfx.h"
  5. #include "CDwgReactors.h"

  6. //-----------------------------------------------------------------------------
  7. //自定义一个反应器类
  8. CDwgReactors::CDwgReactors (const bool autoInitAndRelease) : AcEditorReactor2(), mbAutoInitAndRelease(autoInitAndRelease) {
  9.         if ( autoInitAndRelease ) {
  10.                 if ( acedEditor )
  11.                         acedEditor->addReactor (this) ;
  12.                 else
  13.                         mbAutoInitAndRelease =false ;
  14.         }
  15. }

  16. //-----------------------------------------------------------------------------
  17. CDwgReactors::~CDwgReactors () {
  18.         Detach () ;
  19. }

  20. //-----------------------------------------------------------------------------
  21. void CDwgReactors::Attach () {
  22.         Detach () ;
  23.         if ( !mbAutoInitAndRelease ) {
  24.                 if ( acedEditor ) {
  25.                         acedEditor->addReactor (this) ;
  26.                         mbAutoInitAndRelease =true ;
  27.                 }
  28.         }
  29. }

  30. void CDwgReactors::Detach () {
  31.         if ( mbAutoInitAndRelease ) {
  32.                 if ( acedEditor ) {
  33.                         acedEditor->removeReactor (this) ;
  34.                         mbAutoInitAndRelease =false ;
  35.                 }
  36.         }
  37. }

  38. AcEditor *CDwgReactors::Subject () const {
  39.         return (acedEditor) ;
  40. }

  41. bool CDwgReactors::IsAttached () const {
  42.         return (mbAutoInitAndRelease) ;
  43. }
  44. //回调函数
  45. void CDwgReactors::beginDwgOpen( ACHAR* filename )
  46. {
  47.       acedAlert(_T("This is beginDwgOpen test."));
  48. }
  49. //回调函数
  50. void CDwgReactors::beginSave( AcDbDatabase* pDb, const ACHAR* pIntendedName )
  51. {
  52.         AcDbBlockTable *pBlkTbl=NULL;
  53.         if (acdbOpenObject(pBlkTbl,pDb->blockTableId(),AcDb::kForRead)==Acad::eOk)
  54.         {
  55.                 AcDbBlockTableRecord *pBlkRcd=NULL;
  56.                 if (pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkRcd,AcDb::kForWrite)==Acad::eOk)
  57.                 {
  58.                         AcDbExtents ext;
  59.                         ext.addBlockExt(pBlkRcd);
  60.                         AcGePoint3d pt(ext.minPoint()+(ext.minPoint()+ext.maxPoint().asVector()).asVector()/2);
  61.                         double height=ext.maxPoint().y-ext.minPoint().y;
  62.                         AcDbText *pText=new AcDbText;
  63.                         pText->setTextString(_T("bbs.xdcad.net"));
  64.                         pText->setVerticalMode(AcDb::kTextVertMid);
  65.                         pText->setHorizontalMode(AcDb::kTextCenter);
  66.                         pText->setPosition(pt);
  67.                         pText->setColorIndex(1);
  68.                         pText->setHeight(height/5);
  69.                         pBlkRcd->appendAcDbEntity(pText);
  70.                         pText->close();
  71.                         pBlkRcd->close();
  72.                 }
  73.                 pBlkTbl->close();
  74.         }
  75. }

在初始化中加载这个反应器

  1.         virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
  2.                 // TODO: Load dependencies here

  3.                 // You *must* call On_kInitAppMsg here
  4.                 AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
  5.                
  6.                 // TODO: Add your initialization code here
  7.                 CDwgReactors *mDwgReactor=new CDwgReactors;//加载反应器

  8.                 return (retCode) ;
  9.         }
复制代码


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

已领礼包: 1268个

财富等级: 财源广进

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

使用道具 举报

已领礼包: 2409个

财富等级: 金玉满堂

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-28 04:29 , Processed in 0.370492 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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