|
|
[二次开发] create part family template(UF functio
(这条文章已经被阅读了 4174 次) 时间:2009/10/08/08:51
来源:even2004
[二次开发] 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); }
|
|