马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
在alisp中这样写两个这样的反应器
- (vlr-dwg-reactor nil '((:vlr-beginsave . _beginsave) (:vlr-enddwgopen . _enddwgopen)))
- (defun _beginsave (o e)
- (setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
- (vla-addtext ms "bbs.xdcad.net" (vlax-3d-point '(0 0 0)) 100.0)
- (princ)
- )
- (defun _enddwgopen (o e)
- (princ (getvar "dwgname"))
- (princ)
- )
ARX 的反应器就是自己写一个类,继承自那些 AcXXXXReactor类 , 以上两个反应器ARX代码如下,采用 ObjectARX 向导类生成
自定义类 .h
- //-----------------------------------------------------------------------------
- //----- CDwgReactors.h : Declaration of the CDwgReactors
- //-----------------------------------------------------------------------------
- #pragma once
- #ifdef ARXPROJECT2_MODULE
- #define DLLIMPEXP __declspec(dllexport)
- #else
- #define DLLIMPEXP
- #endif
- //-----------------------------------------------------------------------------
- #include "aced.h"
- //-----------------------------------------------------------------------------
- //----- Note: Uncomment the DLLIMPEXP symbol below if you wish exporting
- //----- your class to other ARX/DBX modules
- class /*DLLIMPEXP*/ CDwgReactors : public AcEditorReactor2 {
- protected:
- //----- Auto initialization and release flag.
- bool mbAutoInitAndRelease ;
- public:
- CDwgReactors (const bool autoInitAndRelease =true) ;
- virtual ~CDwgReactors () ;
- virtual void beginSave(AcDbDatabase* pDb, const ACHAR* pIntendedName);//反应器事件
- virtual void beginDwgOpen(ACHAR* filename);//反应器事件
- virtual void Attach () ;//
- virtual void Detach () ;
- virtual AcEditor *Subject () const ;
- virtual bool IsAttached () const ;
- } ;
自定义类 .cpp
- //-----------------------------------------------------------------------------
- //----- CDwgReactors.cpp : Implementation of CDwgReactors
- //-----------------------------------------------------------------------------
- #include "StdAfx.h"
- #include "CDwgReactors.h"
- //-----------------------------------------------------------------------------
- //自定义一个反应器类
- CDwgReactors::CDwgReactors (const bool autoInitAndRelease) : AcEditorReactor2(), mbAutoInitAndRelease(autoInitAndRelease) {
- if ( autoInitAndRelease ) {
- if ( acedEditor )
- acedEditor->addReactor (this) ;
- else
- mbAutoInitAndRelease =false ;
- }
- }
- //-----------------------------------------------------------------------------
- CDwgReactors::~CDwgReactors () {
- Detach () ;
- }
- //-----------------------------------------------------------------------------
- void CDwgReactors::Attach () {
- Detach () ;
- if ( !mbAutoInitAndRelease ) {
- if ( acedEditor ) {
- acedEditor->addReactor (this) ;
- mbAutoInitAndRelease =true ;
- }
- }
- }
- void CDwgReactors::Detach () {
- if ( mbAutoInitAndRelease ) {
- if ( acedEditor ) {
- acedEditor->removeReactor (this) ;
- mbAutoInitAndRelease =false ;
- }
- }
- }
- AcEditor *CDwgReactors::Subject () const {
- return (acedEditor) ;
- }
- bool CDwgReactors::IsAttached () const {
- return (mbAutoInitAndRelease) ;
- }
- //回调函数
- void CDwgReactors::beginDwgOpen( ACHAR* filename )
- {
- acedAlert(_T("This is beginDwgOpen test."));
- }
- //回调函数
- void CDwgReactors::beginSave( AcDbDatabase* pDb, const ACHAR* pIntendedName )
- {
- AcDbBlockTable *pBlkTbl=NULL;
- if (acdbOpenObject(pBlkTbl,pDb->blockTableId(),AcDb::kForRead)==Acad::eOk)
- {
- AcDbBlockTableRecord *pBlkRcd=NULL;
- if (pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkRcd,AcDb::kForWrite)==Acad::eOk)
- {
- AcDbExtents ext;
- ext.addBlockExt(pBlkRcd);
- AcGePoint3d pt(ext.minPoint()+(ext.minPoint()+ext.maxPoint().asVector()).asVector()/2);
- double height=ext.maxPoint().y-ext.minPoint().y;
- AcDbText *pText=new AcDbText;
- pText->setTextString(_T("bbs.xdcad.net"));
- pText->setVerticalMode(AcDb::kTextVertMid);
- pText->setHorizontalMode(AcDb::kTextCenter);
- pText->setPosition(pt);
- pText->setColorIndex(1);
- pText->setHeight(height/5);
- pBlkRcd->appendAcDbEntity(pText);
- pText->close();
- pBlkRcd->close();
- }
- pBlkTbl->close();
- }
- }
在初始化中加载这个反应器
- virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
- // TODO: Load dependencies here
- // You *must* call On_kInitAppMsg here
- AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
-
- // TODO: Add your initialization code here
- CDwgReactors *mDwgReactor=new CDwgReactors;//加载反应器
- return (retCode) ;
- }
复制代码
|