Archicad插件开发-项目事件回调

在AC中如果我们需要知道当前楼层切换、项目关闭、打开等事件,则可以设置项目事件回调函数来处理。

//回调函数
static GSErrCode __ACENV_CALL ProjectEventCallback(API_NotifyEventID notifID, Int32 param)
{
    GSErrCode err;
    switch (notifID)
    {
        case APINotify_ChangeFloor://当前楼层切换时触发
        {               
            API_StoryInfo storyInfo;
            err = ACAPI_Environment(APIEnv_GetStorySettingsID, &storyInfo, nullptr);  
            if (err == NoError)
                storyInfo.actStory;    //当前楼层索引       
        }
        break;
        case APINotify_ChangeProjectDB://楼层信息更改时触发(比如更改楼层名)
        {
            //获取楼层数据
            API_StoryInfo    storyInfo;
 
            err = ACAPI_Environment(APIEnv_GetStorySettingsID, &storyInfo, nullptr);
            if (err != NoError) {
                ErrorBeep("APIEnv_GetStorySettingsID", err);
                return err;
            }

            for (Int32 i = storyInfo.lastStory - storyInfo.firstStory; i >= 0; i--)
            {
                int nIdex = (*storyInfo.data)[i].index;  //楼层索引
                std::string strName = GS::UniString((*storyInfo.data)[i].uName).ToCStr().Get();    //楼层名
                double dLevel = (*storyInfo.data)[i].level;    //楼层标高
                double dHeight = (*storyInfo.data)[i + 1].level - (*storyInfo.data)[i].level;    //层高

            }
            BMKillHandle(reinterpret_cast<GSHandle*> (&storyInfo.data));        
        }
        break;
        case  APINotify_Open:    //项目打开时触发(新建项目时也会触发)
        {
            //TODO:可在此处做一些新项目初始化工作        
        }
        break;
        case  APINotify_New: //新建项目时触发
        {
            //TODO:可在此处做一些新项目初始化工作         
        }
        break;
        case  APINotify_Close:   //项目关闭时触发
        {
            //TODO:可在此处做一些数据清理工作        
        }
        break;
        default:
        break;    
    }
    return NoError;
}

//在初始化时 设置回调
GSErrCode __ACENV_CALL Initialize    (void)
{
    //参数1设置通知过滤
    //如果只需要监测楼层更改则传APINotify_ChangeFloor
    //如果只需要项目关闭跟项目打开则传APINotify_Open | APINotify_Close即可
    GSError err = ACAPI_Notify_CatchProjectEvent(API_AllNotificationMask, ProjectEventCallback); //项目事件回调(当前楼层切换、项目关闭、打开等)
}

事件类型由API_NotifyEventID枚举所定义。

typedef enum {
    APINotify_New                                = 0x00000001,
    APINotify_NewAndReset                        = 0x00000002,
    APINotify_Open                                = 0x00000004,
    APINotify_PreSave                            = 0x00000008,
    APINotify_Save                                = 0x00000010,
    APINotify_Close                                = 0x00000020,
    APINotify_Quit                                = 0x00000040,
    APINotify_TempSave                            = 0x00000080,
    APINotify_ConvertUnId                        = 0x00000100,
    APINotify_ConvertGuid                        = 0x00000200,
    APINotify_ConvertLinkId                        = 0x00000400,
    APINotify_ConvertDrwGuid                    = 0x00000800,

    APINotify_SendChanges                        = 0x00008000,
    APINotify_ReceiveChanges                    = 0x00010000,

    APINotify_ChangeProjectDB                    = 0x00040000,
    APINotify_ChangeWindow                        = 0x00080000,
    APINotify_ChangeFloor                        = 0x00100000,
    APINotify_ChangeLibrary                        = 0x00200000,

    APINotify_AllInputFinished                    = 0x00400000,                // Open, Merge or Drag-and_Drop finished, everything is in PLANDB/currDBRef

    APINotify_UnitChanged                        = 0x00800000,                // notifies that the working units or calculation units have changed on Preferences dialogs

    APINotify_SideviewCreated                    = 0x01000000,
    APINotify_SideviewRebuilt                    = 0x02000000,
    APINotify_PropertyDefinitionChanged            = 0x04000000,
    APINotify_ClassificationItemChanged            = 0x08000000,

    APINotify_PropertyVisibilityChanged            = 0x10000000,
    APINotify_ClassificationVisibilityChanged    = 0x20000000,

    APINotify_ShowIn3DChanged                    = 0x40000000
} API_NotifyEventID;

#define    API_AllProjectNotificationMask    0x00000FFF                // APINotify_New..APINotify_ConvertGuid
#define    API_AllTeamWorkNotificationMask    0x00018000                // APINotify_Share..APINotify_ChangeWorkspace
#define    API_AllChangeNotificationMask    0x033C0000                // APINotify_ChangeProjectDB..APINotify_ChangeFloor

#define    API_AllNotificationMask            0xFFFFFFFF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值