admin 发表于 2017-12-7 11:22:15

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

UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数常见的使用方法如下,不外乎就是找文件,找文件夹,创建文件,查询等操作。


#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_ ) \
{ intifail_ = 0; \
char message; \
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[])
{
intifail = 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;
tag_t                   part_tag;
UF_UGMGR_tag_t          db_part_tag;
UF_UGMGR_tag_t          root_folder;
char                  root_folder_name;
int                     i, count;
UF_UGMGR_tag_t          *folder_contents;
UF_UGMGR_object_type_tobject_type;
char                  folder_name;
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,
   &object_type));
    if (object_type == UF_UGMGR_type_folder)
    {
      CHECK(UF_UGMGR_ask_folder_name(folder_contents, 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));
      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;
tag_t            work_part_tag;
char             part_number;
char             part_revision;
char             part_file_type;
char             part_file_name;
UF_UGMGR_tag_t   db_tag;
char             part_name;
char             part_desc;
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;
}
页: [1]
查看完整版本: UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数