Warning: file(datafile/online) [function.file]: failed to open stream: No such file or directory in /home/all2one/public_html/bbs/topic.php on line 200
阳光精品论坛 > 『 CAD 专栏 』 > [二次开发] create part family template(UF functio
 
欢迎您,客人:高级登录 | 注册 | 取回密码 新贴 | 发帖 | 会员 | 搜索 | 帮助

阳光精品论坛 >> 『 CAD 专栏 』 >> [二次开发] create part family template(UF functio本主题已阅读4138次,回复0
发表一个新主题 回复贴子
批量引用回复把本贴加入论坛收藏夹向管理员报告帖子问题
作者 | 本页主题: [二次开发] create part family template(UF functio 上一个主题:用proe做的机器猫 下一个主题:[二次开发] Creating a part family template  
even2004 

 
 究级天王 [荣誉]
信息:坛主标志 该用户目前离线
来自:未填 align=absmiddle
发贴:1239 贴 查找所有我发的帖子
积分:244
货币:5814 阳光币
注册时间:2008/12/31
 查看会员个人资料资料 将其加入好友列表好友 发短信息消息 引用回复这个贴子引用直接回复贴子回复

[二次开发] create part family template(UF functio


[二次开发] create part family template(UF function)

#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_fam.h>
#include <uf_part.h>
#include <uf_assem.h>
#include <uf_ugmgr.h>
#include <uf_modl.h>

#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))

static int report_error( char *file, int line, char *call, int irc)
{
   if (irc)
   {
       char err[133],
            msg[133];

       sprintf(msg, "*** ERROR code %d at line %d in %s:n+++ ",
           irc, line, file);
       UF_get_fail_message(irc, err);

   /*  NOTE:  UF_print_syslog is new in V18 */

       UF_print_syslog(msg, FALSE);
       UF_print_syslog(err, FALSE);
       UF_print_syslog("n", FALSE);
       UF_print_syslog(call, FALSE);
       UF_print_syslog(";n", FALSE);

       if (!UF_UI_open_listing_window())
       {
           UF_UI_write_listing_window(msg);
           UF_UI_write_listing_window(err);
           UF_UI_write_listing_window("n");
           UF_UI_write_listing_window(call);
           UF_UI_write_listing_window(";n");
       }
   }

   return(irc);
}

#define WRITE(X)   UF_UI_open_listing_window(); UF_UI_write_listing_window(X)

#define WRITE_S(X) (write_string_to_listing_window(#X, X))

void write_string_to_listing_window(char *title, char *string)
{
   char
       msg[UF_UI_MAX_STRING_LEN+1];

   UF_CALL(UF_UI_open_listing_window());
   sprintf(msg, "%s = "%s"n", title, string);
   UF_CALL(UF_UI_write_listing_window(msg));
}

#define WRITE_D(X) (write_integer_to_listing_window(#X, X))

static void write_integer_to_listing_window(char *title, int n)
{
   char
       msg[UF_UI_MAX_STRING_LEN+1];

   UF_CALL(UF_UI_open_listing_window());
   sprintf(msg, "%s = %dn", title, n);
   UF_CALL(UF_UI_write_listing_window(msg));
}

static int allocate_string_array(int n_elements, int n_chars, char ***where)
{
   int
       ii,
       resp;

   *where = UF_allocate_memory(n_elements * sizeof(char *), &resp);

   for (ii = 0; ii < n_elements; ii++)
   {
       (*where)[ii] = UF_allocate_memory(n_chars * sizeof(char), &resp);
       if (resp) return resp;
   }

   return 0;
}

static void do_it(void)
{
   logical
       is_template,
       modifiable,
       nxman;
   int
       ii,
       index;
   tag_t,
       attributes[2],
       family,
       part = UF_ASSEM_ask_work_part();
   char
       family_name[MAX_FSPEC_SIZE+1],
       partname[MAX_FSPEC_SIZE+1],
       part_number[UF_UGMGR_PARTNO_SIZE+1],
       part_revision[UF_UGMGR_PARTREV_SIZE+1],
       part_file_type[UF_UGMGR_FTYPE_SIZE+1],
       part_file_name[UF_UGMGR_FNAME_SIZE+1],
       **values;
   UF_FAM_attribute_data_t
       attribute_data;
   UF_FAM_family_data_t
       family_data;
   UF_FAM_member_data_t
       member_data;

   UF_CALL(UF_PART_is_family_template(part, &is_template));
   if (is_template)
   {
       uc1601("Part is already a part family template!", TRUE);
       return;
   }

   UF_CALL(UF_PART_ask_part_name(part, partname));
   UF_CALL(UF_is_ugmanager_active(&nxman));
   if (nxman)
   {
       UF_CALL(UF_UGMGR_decode_part_file_name(partname, part_number,
           part_revision, part_file_type, part_file_name));
       strcpy(family_name, part_number);
   }
   else
       UF_CALL(uc4574(partname, 2, family_name));

   UF_CALL(UF_is_ugmanager_active(&nxman));
   attribute_data.subtype = UF_fam_attr_name_subtype;
   attribute_data.base_object = NULL_TAG;
   attribute_data.rules = NULL;
   attribute_data.value = family_name;
   attribute_data.name = "DB_PART_NO";
   UF_CALL(UF_FAM_create_attribute(&attribute_data, &attributes[0]));
   attribute_data.name = "OS_PART_NAME";
   UF_CALL(UF_FAM_create_attribute(&attribute_data, &attributes[1]));

   family_data.subtype = UF_fam_part_subtype;
   family_data.attribute_count = 2;
   family_data.member_count = 0;
   family_data.attributes = attributes;
   family_data.name = family_name;
   UF_CALL(UF_FAM_create_family(&family_data, &family));
   WRITE("Created ");
   WRITE_S(family_name);

   member_data.value_count = 2;
   allocate_string_array(2, MAX_FSPEC_SIZE+1, &values);
   member_data.values = values;

   for (ii = 0; ii < 2; ii++)
   {
       if (nxman)
       {
           UF_CALL(UF_UGMGR_assign_part_number(family_name, part_file_type,
               part_number, &modifiable));
       }
       else
       {
           sprintf(part_number, "%s_%d", family_name, ii+1);
       }
       strcpy(values[0], part_number);
       strcpy(values[1], part_number);

       UF_CALL(UF_FAM_add_member(family, &member_data, &index));
       WRITE("Added family member at ");
       WRITE_D(index);
   }

   UF_CALL(UF_MODL_update());
   UF_CALL(UF_FAM_check_family_status(family));

}

/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
   if (UF_CALL(UF_initialize())) return;
   do_it();
   UF_terminate();
}

int ufusr_ask_unload(void)
{
   return (UF_UNLOAD_IMMEDIATELY);
}


修改贴子编辑 |  发表于 2009/10/08/08:51  |  1 层 

发表一个新主题 回复贴子 推荐给朋友 可打印版本 文章模式 
论坛跳转:


  快速回复  

文章内容:

HTML 代码不可用


BMB代码选项:
[img] - 开启
[flash] - 开启
[size] - 开启

上传附件[还可传0个]:
开启

最大字节: 200000 字节
最少发帖: 20 篇

标题:


  [使用 Ctrl+Enter 直接提交贴子]

你的用户名  你的密码: 忘了密码?

阳光精品论坛 >> 『 CAD 专栏 』 >> [二次开发] create part family template(UF functio本主题已阅读4138次,回复0



本论坛言论纯属发表者个人意见,与 阳光精品论坛 立场无关 联系我们
Powered by BMForum v5.0 Skin by Bob Shen