标题: [二次开发] align component csys to component or a [打印本页]
作者: even2004 标题:[二次开发] align component csys to component or a 时间: 2009/12/17/10:41
[二次开发] align component csys to component or assembly csys
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#include <uf_assem.h>
#include <uf_disp.h>
#include <uf_modl.h>
#define ECHO(X) (printf("%s = %dn", #X, X)).
#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);7 G* G3 l {# w
/* 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);2
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);
}
static int mask_for_csys(UF_UI_selection_p_t select, void *type)
{
UF_UI_mask_t
mask = { UF_coordinate_system_type, 0, 0 };
if (!UF_CALL(UF_UI_set_sel_mask(select,"
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, 1, &mask)));
return (UF_UI_SEL_SUCCESS);
else
return (UF_UI_SEL_FAILURE);
}
static tag_t select_a_csys(char *prompt)
{
int
resp;
double
cp[3];
tag_t
object,5
view;
UF_CALL(UF_UI_select_with_single_dialog("Select a coordinate system",
prompt, UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_for_csys, NULL, &resp,
&object, cp, &view));
if (resp == UF_UI_OBJECT_SELECTED || resp == UF_UI_OBJECT_SELECTED_BY_NAME)
{
UF_CALL(UF_DISP_set_highlight(object, 0));
return object;#
}:
else return NULL_TAG;
}
static void report_mc_status(UF_ASSEM_mc_status_t stat)
{
switch(stat)
{
case UF_ASSEM_mc_solved:
printf("UF_ASSEM_mc_solven");
break;
case UF_ASSEM_mc_not_solved:
printf("UF_ASSEM_mc_NOT_solvedn");
break;
case UF_ASSEM_mc_no_mating_specified:
printf("UF_ASSEM_mc_no_mating_specifiedn");
break;
default:
printf("Unknown status came backn");
}
}
static void do_it(void)
{
tag_t
from_occ,
to_occ,
invalid_tag,
work_part = UF_ASSEM_ask_work_part();
UF_ASSEM_mating_condition_t
mc_data;
UF_ASSEM_mc_structure_state_t
struct_status;
UF_ASSEM_mc_status_t
status;
/* New function - Required in NX */
UF_CALL(UF_ASSEM_init_mc(&mc_data));
while (((from_occ = select_a_csys(
"Select csys FROM component to be mated")) != NULL_TAG) &&
((to_occ = select_a_csys(
"Select csys TO align with")) != NULL_TAG))
{
mc_data.mated_object = UF_ASSEM_ask_inst_of_part_occ(
UF_ASSEM_ask_part_occurrence(from_occ));
mc_data.name = NULL;
mc_data.user_name = FALSE;
mc_data.num_constraints = 1;
mc_data.suppressed = FALSE;
mc_data.constraints[0].from_status = UF_ASSEM_ok;
mc_data.constraints[0].to_status = UF_ASSEM_ok;
mc_data.constraints[0].mate_type = UF_ASSEM_v16_align;
mc_data.constraints[0].from_type = UF_ASSEM_csys;
mc_data.constraints[0].to_type = UF_ASSEM_csys;
mc_data.constraints[0].from =:
UF_ASSEM_ask_prototype_of_occ(from_occ);
mc_data.constraints[0].from_part_occ =
UF_ASSEM_ask_part_occurrence(from_occ);
// Check whether TO object is in component or in assembly work part
if (UF_ASSEM_is_occurrence(to_occ))
{
mc_data.constraints[0].to = UF_ASSEM_ask_prototype_of_occ(to_occ);
mc_data.constraints[0].to_part_occ =
UF_ASSEM_ask_part_occurrence(to_occ);
}
else
{
mc_data.constraints[0].to = to_occ;
mc_data.constraints[0].to_part_occ =)
UF_ASSEM_ask_root_part_occ(UF_ASSEM_ask_work_part());
}
mc_data.constraints[0].offset = NULL_TAG;
mc_data.constraints[0].name = NULL;
mc_data.constraints[0].user_name = FALSE;
mc_data.constraints[0].has_help_point = FALSE;
mc_data.part_occurrence = work_part;
UF_CALL( UF_ASSEM_check_mc_structure ( &mc_data, &struct_status, &invalid_tag ) );
UF_CALL(UF_ASSEM_apply_mc_data(&mc_data, &struct_status, &status));
report_mc_status(status);
UF_CALL(UF_MODL_update());
}
}
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();7
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
阳光精品论坛 - Powered By BMForum v5.0