PLM之家 UG NX11.0二次开发(ufun和NXOpen C++)网络培训火热报名

PLM之家-上海点团信息科技有限公司工业4.0数字化软件官方知识管理平台

查看: 95|回复: 0

[二次开发源码] NX二次开发源码分享: 获取当前Reference Component的通用方法

[复制链接]
  • TA的每日心情
    无聊
    前天 09:37
  • 签到天数: 103 天

    连续签到: 9 天

    [LV.6]常住居民II

    1919

    主题

    3193

    帖子

    5万

    积分

    管理员

    PLM之家mildcat

    Rank: 9Rank: 9Rank: 9

    积分
    57837
    发表于 2018-1-10 17:48:41 | 显示全部楼层 |阅读模式

    请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

    您需要 登录 才可以下载或查看,没有帐号?QQ关联注册

    x

    / X1 H1 r! i% n5 o) @6 X
    & w2 D; ?) m; l9 \5 b" E$ }( ~NX二次开发源码分享: 获取当前Reference Component的通用方法; ^1 S8 Z: T" s5 R3 r

    * a, P" G: Z9 R: {) M
    $ A% e% _& [3 F( D2 s+ U0 L6 w6 N* e4 y. _- B$ @
    / U" l! m( @5 n7 f: }; \- X/ \+ V

    ' h6 Q2 Y1 K2 ~. p
    [C] 纯文本查看 复制代码
    static logical attribute_exists(Component cmpnt, char *title)
    {
    
    //  The traditional method of asking for all of the components recursively//  does not work if you are looking for reference-only components,//  because they are not retured when you ask for the children.////  Also, asking for the AssembliesGeneralPropertiesBuilder.ReferenceComponent //  Property  does not work in versions earlier than NX12.////  The workaround is to cycle for components the old-fashioned way,//  and then ask whether each one has the REFERENCE_COMPONENT attribute.////  If you have multiple occurrences of a given component in the assembly,//  each one will be reported.
        
        logical
            hasRefAttr = FALSE;
    
        hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
    
        if(hasRefAttr == TRUE)
        {
            return TRUE;
        }
    
        return FALSE;
    
    }
    
    static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
    {
        UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
        return (object);
    }
    
    static void do_it(void)
    {
        // Assumes that the display part is the top of the assembly
    
        tag_t
            dispPart = UF_PART_ask_display_part();
    
        if(NULL_TAG == dispPart) 
        {
            ECHO("Program requires an active displayed part");
            return;
        }
    
        tag_t
            compTag = NULL_TAG;
    
        while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
        {
            char
                msg[512] = {""},
                fSpec[256] = {""};
    
                tag_t
                    protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
    
                UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
    
                // uncomment to see all component names:
                //sprintf(msg, "Component Part: %s\n", fSpec);
                //ECHO(msg);
    
                Component *theComponent = (Component *)NXObjectManager::Get(compTag);
                if (attribute_exists(*theComponent, RO))
                {
                    sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
                    ECHO(msg);
                }
        }
    }
    # j: @# x% Q5 C
    上海点团信息科技有限公司,承接NX,CATIA,CREO等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施开发培训,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | QQ关联注册

    本版积分规则

    <

    QQ|小黑屋|手机版|Archiver|PLM之家-工业4.0数字化驱动之家 ( 沪ICP备13003373-3

    GMT+8, 2018-1-21 06:37 , Processed in 0.119354 second(s), 28 queries .

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