遍历组件
递归遍历组件
static int cycle_components(
/* Component to cycle I/O */
tag_t component,
/* for formatting I/O */
char *indentation)
{
int i;
int ifail = 0;
int component_count = 0;
int check_number = 0;
tag_t parent = NULL_TAG;
tag_t member = NULL_TAG;
tag_t *child_components = NULL;
char p_name[MAX_FSPEC_SIZE];
char r_name[MAX_ENTITY_NAME_SIZE];
char c_name[MAX_ENTITY_NAME_SIZE];
double origin[3];
double csys_matrix[9];
double transform[4][4];
char sql_string[1024];
char buff[100];
if (component == NULL_TAG)
return 0;
ifail = UF_ASSEM_ask_component_data( component,p_name,r_name,
c_name,origin,csys_matrix,
transform);
if (ifail != 0)
{
return ifail;
}
query_iman(p_name);
component_count = UF_ASSEM_ask_part_occ_children(component,&child_components);
for (i=0; i<component_count; i++)
{
ifail = cycle_components(child_components[i], indentation);
}
UF_free(child_components);
return ifail;
}
遍历所有组件
static void find_all_components(void)
{
char
color[UF_DISP_MAX_NAME_SIZE+1],
part_fspec[MAX_FSPEC_SIZE+1];
int
i,
n;
tag_t
comp = NULL,
part;
n = UF_PART_ask_num_parts();
for (i=0; i<n; i++)
{
part = UF_PART_ask_nth_part(i);
UF_PART_ask_part_name(part, part_fspec);
printf("Part tag %d - %s\n", part, part_fspec);
do
{
UF_CALL(UF_OBJ_cycle_objs_in_part(part, UF_component_type, &comp));
if (comp)
{
ask_obj_color(comp, color);
printf(" component tag %d is %s\n", comp, color);
}
} while (comp);
}
}
组件遍历
static int ask_all_components(tag_t part, tag_t **components)
{
int
err,
ii,
n;
tag_t
component = NULL_TAG;
uf_list_p_t
comp_list;
UF_CALL(UF_MODL_create_list(&comp_list));
while ((component = ask_next_component(part, component)) != NULL_TAG)
UF_CALL(UF_MODL_put_list_item(comp_list, component));
UF_CALL(UF_MODL_ask_list_count(comp_list, &n));
*components = (tag_t *)UF_allocate_memory(n * sizeof(tag_t), &err);
if (UF_CALL(err)) return 0;
for (ii = 0; ii < n; ii++)
UF_CALL(UF_MODL_ask_list_item(comp_list, ii, *components+ii));
UF_CALL(UF_MODL_delete_list(&comp_list));
return n;
}
遍历目录
Date: 11-OCT-2001
Subject: Sample API program to list all parts in directory tree
/*HEAD LIST_ALL_PARTS_IN_DIRECTORY_TREE CCC UFUN */
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_cfi.h>
#include <uf_part.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];
UF_get_fail_message(irc, err);
sprintf(msg, "error %d at line %d in %s", irc, line, file);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n\n");
}
else
{
#ifdef _USRDLL
uc1601(err, TRUE);
uc1601(msg, TRUE);
#else
fprintf(stderr, "%s\n", err);
fprintf(stderr, "%s\n", msg);
fprintf(stderr, "%s;\n\n", call);
#endif
}
}
return(irc);
}
int main( void )
{
int
cnt,
type,
resp;
char
dirspec[MAX_FSPEC_SIZE+1] = { "" },
fspec[MAX_FSPEC_SIZE+1];
if (UF_CALL(UF_initialize())) return 1;
while (printf("Enter directory path:\n") && gets(dirspec))
{
cnt = 0;
uc4508(dirspec, (1<<10)|(1<<11)|(1<<13), 0, "*.prt");
while ((resp = uc4518()) < 2)
{
switch (resp)
{
case 0:
type = uc4601();
if (type == 100)
UF_CALL(uc4509());
else
{
UF_CALL(uc4519(fspec));
printf("%d. %s\n", ++cnt, fspec);
}
break;
case 1:
UF_CALL(uc4549());
break;
default:
UF_CALL(resp);
break;
}
}
UF_CALL(uc4548());
printf("\nFound %d parts.\n", cnt);
}
UF_CALL(UF_terminate());
return 0;
}
评论区