Archicad插件开发-右侧树操作事件

在AC中如果我们需要知道右侧项目导航、视图映射、图册、发布树节点增、删、改、点击等事件时,则可以设置项目导航事件回调函数来处理。

//回调函数
static GSErrCode ProjectMapNotificationCallback(const API_NotifyViewEventType* viewEvent)
{
    GSErrCode err;
    API_NavigatorItem item;
    BNZeroMemory(&item, sizeof(API_NavigatorItem));
    API_Guid guid = viewEvent->itemGuid;
    GSErrCode err = ACAPI_Navigator(APINavigator_GetNavigatorItemID, &guid, &item);
    
    switch (viewEvent->notifID)
    {
        case APINotifyView_Inserted:
        {               
            //TODO:    
        }
        break;
        case APINotifyView_Modified:
        {
            //TODO:    
        }
        break;
        case  APINotifyView_Deleted:
        {
            //TODO:     
        }
        break;
        case  APINotifyView_Opened:
        {
            //TODO: 打开
            //以下为演示更改打开的项目导航中的详图比例示例代码
            if (item.itemType != API_DetailDrawingNavItem)
                break;
        double dScale = 25;
        bool bUpdate = true;
        err = ACAPI_Database(APIDb_ChangeDrawingScaleID, &dScale, &bUpdate);     
        }
        break;
        default:
        break;    
    }
    return NoError;
}

//在初始化时 设置回调
GSErrCode __ACENV_CALL Initialize    (void)
{
    //参数1设置通知过滤
    //参数2设置树过滤 可设置API_ProjectMap、API_PublicViewMap、API_LayoutMap、API_PublisherSets对应为项目导航、视图映射、图册、发布
    GSError err = ACAPI_Notify_CatchViewEvent(API_AllViewNotificationMask, API_ProjectMap, ProjectMapNotificationCallback); //项目导航
    //err = ACAPI_Notify_CatchViewEvent(API_AllViewNotificationMask, API_PublicViewMap, PublicViewMapNotificationCallback);        //视图映射
    //err = ACAPI_Notify_CatchViewEvent(API_AllViewNotificationMask, API_LayoutMap, LayoutMapNotificationCallback);            //图册
    //err = ACAPI_Notify_CatchViewEvent(API_AllViewNotificationMask, API_PublisherSets, PublisherSetsNotificationCallback);        //发布
}

树操作类型由API_NotifyViewEventID枚举所定义。

typedef enum {
    APINotifyView_Inserted            = 0x00000001,
    APINotifyView_Modified            = 0x00000002,
    APINotifyView_Deleted            = 0x00000004,
    APINotifyView_Opened            = 0x00000008,
    APINotifyView_Begin                = 0x00000010,
    APINotifyView_End                = 0x00000020
} API_NotifyViewEventID;

#define    API_AllViewNotificationMask        0x000000FF

typedef struct {
    API_NotifyViewEventID            notifID;                // type of the notification
    API_NavigatorMapID            mapId;                    // which navigator organizer
    API_Guid                itemGuid;                // guid of the item in string format
} API_NotifyViewEventType;

以下是更改打开页面的设置下方页面设置相关代码

static GSErrCode  PublicViewMapNotificationCallback(const API_NotifyViewEventType* viewEvent)
{
    GSErrCode err;
    //获取被操作的item
    API_NavigatorItem item;
    BNZeroMemory(&item, sizeof(API_NavigatorItem));
    API_Guid guid = viewEvent->itemGuid;
    err = ACAPI_Navigator(APINavigator_GetNavigatorItemID, &guid, &item);
    
    //获取被操作的item的view
    API_NavigatorView    view;
    BNZeroMemory(&view, sizeof(view));
    err = ACAPI_Navigator(APINavigator_GetNavigatorViewID, &item, &view);
    switch (viewEvent->notifID)
    {
        case APINotifyView_Inserted:
        {
            //        
        }
        break;
        case APINotifyView_Modified:
        {
            //        
        }
        break;
        case APINotifyView_Deleted:
        {
            //        
        }
        break;
        case APINotifyView_Opened:
        {
            //设置翻新过滤器
            GS::UniString strTmp = u8"00 显示所有元素"; 
            API_Guid    guid, actualGuid; 
            GS::Array<API_Guid> arrRens;   
            err = ACAPI_Database(APIDb_GetRenovationFiltersID, &arrRens);    //获取所有翻新过滤器
            if (err == NoError)
            {
                GS::USize nRenSize = arrRens.GetSize();  
                for (GS::UIndex i = 0; i < nRenSize; ++i)
                {
                    GS::UniString sstrName;  
                    API_Guid guidTmp = arrRens[i]; 
                    err = ACAPI_Goodies(APIAny_GetRenovationFilterNameID, &guidTmp, &sstrName);      //获取翻新过滤器的name
                    if (CHEqualASCII(sstrName.ToCStr().Get(), strTmp.ToCStr().Get(), CS_CaseSensitive))
                    {
                        guid = guidTmp;  
                        break;                 
                    }          
                }         
            }
            err = ACAPI_Database(APIDb_GetActualRenovationFilterID, &actualGuid);    //获取当前项的翻新过滤器
            if (actualGuid != guidTmp)
            {
                err = ACAPI_Database(APIDb_SetActualRenovationFilterID, &guidTmp);      //更改当前项的翻新过滤器    
            }
            
            //设置画笔集
            sprintf(view.penSetName, "%s", u8"05 深化设计画笔集");
            err = ACAPI_Navigator(APINavigator_ChangeNavigatorViewID, &item, &view);    //改变画笔集合
            
            //设置图形覆盖组合
            
            //设置模型视图选项
            
            //设置复合层部分结构显示
            
            //设置图层
            
            //设置比例
            
            //设置旋转角度
        }
        break;
        default:
        break;    
    }
    return NoError;
}

你可能感兴趣的:(Archicad二开,c++,Archicad,windows)