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

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

查看: 64|回复: 0

[二次开发源码] UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数

[复制链接]
  • TA的每日心情

    5 天前
  • 签到天数: 77 天

    [LV.6]常住居民II

    1834

    主题

    3494

    帖子

    5万

    积分

    管理员

    PLM之家mildcat

    Rank: 9Rank: 9Rank: 9

    积分
    56726
    发表于 4 天前 | 显示全部楼层 |阅读模式
    UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数常见的使用方法如下,不外乎就是找文件,找文件夹,创建文件,查询等操作。
    9 v+ P3 v4 V4 ]5 b! S& h  ~
    2 k$ L& r4 L9 V* O' X! X: G
    [C] 纯文本查看 复制代码
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <uf.h>
    #include <uf_ugmgr.h>
    #include <uf_part.h>
    #include <uf_assem.h>
    #define CHECK( func_ ) \
    { int  ifail_ = 0; \
      char message[133]; \
      ifail_ = (func_); 
      if ( ifail_ != 0 ) { \
        UF_get_fail_message( ifail_, message ); \
        printf("ERROR: %s returned from %s\n", message, # func_); \
        return ifail_; } }
    static int create_part( void );
    static int print_work_part_info( void );
    /*---------------------------------------------------------------*/
    int main(int argc, char *argv[])
    {
      int  ifail = 0;
      ifail = UF_UGMGR_initialize(argc,(const char**)argv);
      if (ifail != 0)
      {
        printf("ERROR: Failed to initialize with error code %d", ifail);
        exit(1);
         }
     create_part();
      print_work_part_info();
      UF_PART_close_all();
      UF_UGMGR_terminate();
      return 0;
    }
    /*---------------------------------------------------------------*/
    static int create_part( void )
    {
      char*                   part_number = "600-A-wej-mk1-eng";
      char*                   part_revision = "A";
      char*                   part_file_type = "master";
      char*                   part_file_name = "";
      char                    encoded_name[MAX_FSPEC_SIZE + 1];
      tag_t                   part_tag;
      UF_UGMGR_tag_t          db_part_tag;
      UF_UGMGR_tag_t          root_folder;
      char                    root_folder_name[UF_UGMGR_NAME_SIZE];
      int                     i, count;
      UF_UGMGR_tag_t          *folder_contents;
      UF_UGMGR_object_type_t  object_type;
      char                    folder_name[UF_UGMGR_NAME_SIZE];
      logical                 folder_exists = false;
      CHECK(UF_UGMGR_ask_root_folder(&root_folder));
      CHECK(UF_UGMGR_ask_folder_name(root_folder, root_folder_name));
      printf("Root folder is %s\n", root_folder_name);
      /* Scan through the root folder, looking for a folder called
         "Test Set Default Folder". If this folder exists, set it to be
         the default folder into which newly created parts are
         placed.
      */
      CHECK(UF_UGMGR_list_folder_contents(root_folder, &count, &folder_contents));
      for ( i=0; i<count; i++ )
      {
        CHECK(UF_UGMGR_ask_object_type(folder_contents[i],
       &object_type));
        if (object_type == UF_UGMGR_type_folder)
        {
          CHECK(UF_UGMGR_ask_folder_name(folder_contents[i], folder_name));
          if ( strcmp( folder_name, "Test Set Default Folder" ) == 0 )
          {
            printf("Test Set Default Folder exists\n");
            CHECK(UF_UGMGR_set_default_folder(folder_contents[i]));
            folder_exists = true;
            printf("Set default folder to %s\n", folder_name);
          }
        }
      }
      /* If the folder "Test Set Default Folder" doesn't exist, set the
         default folder to be the root folder.
      */
      if (!folder_exists)
      {
        printf("Test Set Default Folder does not exist\n");
        CHECK(UF_UGMGR_set_default_folder(root_folder));
        printf("Set default folder to %s\n", root_folder_name);
      }
      printf("Encoding UG/Manager part filename...\n");
      CHECK(UF_UGMGR_encode_part_filename( part_number, part_revision,
     part_file_type,
     part_file_name,
     encoded_name ));
      CHECK(UF_PART_new( encoded_name, 1, &part_tag ));
      printf("Created part...\n");
      CHECK(UF_PART_save());
      printf("Saved part...\n");
      CHECK(UF_UGMGR_ask_part_tag( part_number, &db_part_tag ));
      CHECK(UF_UGMGR_set_part_name_desc( db_part_tag, "engine",
    "Mk3 Engine" ));
      printf("Set part name and description...\n");
      return 0;
    }
    /*---------------------------------------------------------------*/
    static int print_work_part_info( void )
    {
      char             work_part_name[MAX_FSPEC_SIZE+1];
      tag_t            work_part_tag;
      char             part_number[UF_UGMGR_PARTNO_SIZE+1];
      char             part_revision[UF_UGMGR_PARTREV_SIZE+1];
      char             part_file_type[UF_UGMGR_FTYPE_SIZE+1];
      char             part_file_name[UF_UGMGR_FNAME_SIZE+1];
      UF_UGMGR_tag_t   db_tag;
      char             part_name[UF_UGMGR_NAME_SIZE+1];
      char             part_desc[UF_UGMGR_DESC_SIZE+1];
      work_part_tag = UF_ASSEM_ask_work_part();
      UF_PART_ask_part_name( work_part_tag, work_part_name );
      CHECK(UF_UGMGR_decode_part_filename( work_part_name,
      part_number,
      part_revision,
      part_file_type,
      part_file_name ));
      printf( "For the current Work Part\n\n" );
      printf( "  Part Number      : %s\n", part_number );
      printf( "  Part Revision    : %s\n", part_revision );
      printf( "  Part File Type   : %s\n", part_file_type );
      printf( "  Part File Name   : %s\n", part_file_name );
     CHECK(UF_UGMGR_ask_part_tag( part_number, &db_tag ));
      CHECK(UF_UGMGR_ask_part_name_desc( db_tag, part_name, part_desc ));
      printf( "  Part Name        : %s\n", part_name );
      printf( "  Part Description : %s\n", part_desc );
      return 0;
    }
    ' q. B% I  h  X5 ^- O
    PLM之家,专业的NX,Teamcenter学习视频网。PLM之家科技,承接二次开发,视频定制,实施培训等业务。www.plmhome.com; && www.plmhome.net-->-->点团信息科技-->-->欢迎联系我们--QQ 939801026
    回复

    使用道具 举报

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

    本版积分规则



    <

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

    GMT+8, 2017-12-11 12:15 , Processed in 0.129624 second(s), 31 queries .

    Powered by PLM之家科技! X3.2

    © 2001-2013 PLMHome Inc.

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