Sample API program to create top view jpeg for all parts in directory /*HEAD CREATE_TOP_VIEW_JPEG_FOR_ALL_PARTS_IN_DIRECTORY CCC UFUN */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #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); } static void check_load_status(UF_PART_load_status_p_t status) { char msg[133]; int ii; for (ii=0; iin_parts; ii++) { UF_get_fail_message(status->statuses[ii], msg); printf(" %s - %s\n", status->file_names[ii], msg); } UF_free(status->statuses); UF_free_string_array(status->n_parts, status->file_names); } static tag_t ask_next_body(tag_t part, tag_t body) { int subtype, type; while (! UF_CALL(UF_OBJ_cycle_objs_in_part(part, UF_solid_type, &body)) && (body != NULL_TAG)) { UF_CALL(UF_OBJ_ask_type_and_subtype(body, &type, &subtype)); if (subtype == UF_solid_body_subtype) return body; } return NULL_TAG; } static void change_view_in_layout(char * view) { UF_CALL(uc6464("", "", view)); } static void batch_shade(char * fspec) { UF_CALL(UF_DISP_batch_shade(fspec, 512, 512, UF_DISP_gouraud)); } static void turn_off_drawing_display() { UF_CALL(UF_DRAW_set_display_state(1)); } static void fit_view(char * viewname) { UF_CALL(uc6432(viewname,1)); } static void build_similar_filespec(char *fspec, int ftype) { tag_t part = UF_PART_ask_display_part(); char dspec[MAX_FSPEC_SIZE+1], part_name[MAX_ENTITY_NAME_SIZE+1], part_fspec[MAX_FSPEC_SIZE+1]; UF_PART_ask_part_name(part, part_fspec); UF_CALL(uc4576(part_fspec, 2, dspec, part_name)); UF_CALL(uc4578(part_name, 2, part_name)); UF_CALL(uc4575(dspec, ftype, part_name, fspec)); } static void do_it(void) { tag_t body = NULL_TAG, part = UF_PART_ask_display_part(); char view[MAX_ENTITY_NAME_SIZE+1] = "TOP", fspec[MAX_FSPEC_SIZE+1] = ""; build_similar_filespec(fspec, 4); strcat(fspec, "_top.jpg"); if ((body = ask_next_body(part, body)) != NULL_TAG) { turn_off_drawing_display(); change_view_in_layout(view); fit_view(view); batch_shade(fspec); } else printf(" NO SOLIDS FOUND to shade\n\n"); } /*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); } int main( void ) { int cnt = 0, resp; tag_t part; char dirspec[MAX_FSPEC_SIZE+1] = { "" }, fname[MAX_FSPEC_SIZE+1], part_name[MAX_FSPEC_SIZE+1]; UF_PART_load_status_t status; if (UF_CALL(UF_initialize())) return 1; while (printf("Enter directory path:\n") && gets(dirspec)) { uc4508(dirspec, (1<<13)|(1<<11), 0, "*.prt"); while ((resp = uc4518()) == 0) { UF_CALL(uc4600(fname)); UF_CALL(uc4575(dirspec, 2, fname, part_name)); printf("%d. %s\n", ++cnt, part_name); UF_CALL(UF_PART_open(part_name, &part, &status)); if (status.n_parts > 0) check_load_status(&status); if (!status.failed) { printf("\topened OK.\n"); do_it(); UF_PART_close_all(); } } UF_CALL(uc4548()); printf("\nProcessed %d parts.\n", cnt); } UF_CALL(UF_terminate()); return 0; }