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

查看: 553|回复: 0

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

[复制链接]

2014

主题

3196

帖子

6万

积分

管理员

PLM之家mildcat

Rank: 9Rank: 9Rank: 9

积分
60430
发表于 2017-12-7 11:22:15 | 显示全部楼层 |阅读模式

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

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

x
UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数常见的使用方法如下,不外乎就是找文件,找文件夹,创建文件,查询等操作。
  C  Q6 S  c5 ]6 C; T
0 X9 t- w- g9 |& }* G, i
[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;
}

* T) W; X: g& C9 H8 H. t7 L+ Y  J
上海点团信息科技有限公司,承接NX,CATIA,CREO等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施开发培训,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com
回复

使用道具 举报

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

本版积分规则


<

QQ|小黑屋|手机版|Archiver|PLM之家-工业软件数字化驱动之家-国产自主软件推进者 ( 沪ICP备13003373-3

GMT+8, 2018-7-17 13:35 , Processed in 0.125130 second(s), 26 queries .

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