这个例子是一位网友从西门子官网支持中心里面下载分享的
- 代码
//Sample CAM API program : report geom provider /***************************************************************************** ** ** report_geom_provider.c ** ** Description: ** Contains Unigraphics entry points for the application. ** *****************************************************************************/ /* Include files */ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <uf.h> #include <uf_assem.h> #include <uf_disp.h> #include <uf_modl.h> #include <uf_part.h> #include <uf_object_types.h> #include <uf_obj.h> #include <uf_sc.h> #include <uf_ui.h> #include <uf_view.h> #include <uf_ui_ont.h> #include <uf_ui_param.h> #include <uf_oper.h> #include <uf_so.h> #include <uf_cam.h> #include <uf_cam_errors.h> #include <uf_camgeom.h> #include <uf_param.h> #include <uf_param_indices.h> static void ECHO(char *format, ...) { char msg[UF_UI_MAX_STRING_BUFSIZE]; va_list args; va_start(args, format); vsnprintf_s(msg, sizeof(msg), _TRUNCATE, format, args); va_end(args); UF_UI_open_listing_window(); UF_UI_write_listing_window(msg); UF_print_syslog(msg, FALSE); } #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]; UF_get_fail_message(irc, err); ECHO("*** ERROR code %d at line %d in %s:/n", irc, line, file); ECHO("+++ %s/n", err); ECHO("%s;/n", call); } return(irc); } static void ask_part_shortname(tag_t part, char *shortname) { logical nxman; char partname[MAX_FSPEC_SIZE + 1]; UF_CALL(UF_PART_ask_part_name(part, partname)); UF_CALL(UF_is_ugmanager_active(&nxman)); if (nxman) UF_CALL(UF_PART_name_for_display(partname, shortname)); else UF_CALL(uc4574(partname, 2, shortname)); } #define RX(X) report_object_info(#X, X) static void report_object_info(char *what, tag_t object) { logical is_occ; int status, subtype, type; tag_t owning_part, part = UF_PART_ask_display_part(); char owning_part_name[UF_CFI_MAX_FILE_NAME_SIZE], msg[133]; status = UF_OBJ_ask_status(object); UF_CALL(UF_OBJ_ask_type_and_subtype(object, &type, &subtype)); is_occ = UF_ASSEM_is_occurrence(object); ECHO("%s = %d, type=%d, subtype=%d, status=%d, occ=%d", what, object, type, subtype, status, is_occ); if (is_occ) { ECHO(", occurrence"); owning_part = UF_ASSEM_ask_part_occurrence(object); if (owning_part != UF_ASSEM_ask_root_part_occ(part)) { if (!UF_OBJ_ask_name(owning_part, msg)) ECHO(" (from %s)", msg); else ECHO(" (from root occ of)", msg); } } else { int num_occs; tag_t *occurrences; ECHO(", prototype"); num_occs = UF_ASSEM_ask_occs_of_entity(object, &occurrences); for (int ii = 0; ii < num_occs; ++ii) { ECHO(" (occ=%d)", occurrences[ii]); } UF_free(occurrences); } if (!UF_CALL(UF_OBJ_ask_owning_part(object, &owning_part))) { UF_CALL(UF_PART_ask_part_name(owning_part, owning_part_name)); ECHO(", owned by: %s", owning_part_name); } ECHO("/n/n"); } static void report_container_objects(tag_t container) { int n_rules; int *rule_types; UF_SC_input_data_t* rules; int n_entities; tag_t* entities; UF_MODL_ask_container(container, &n_rules, &rule_types, &rules, &n_entities, &entities); for (int ii = 0; ii<n_entities; ii++) { RX(entities[ii]); } } static void select_from_ONT(void) { tag_t *objects, provider_tag; int object_count, type, subtype; char msg[MAX_LINE_SIZE + 1], provider_name[33]; logical is_initialized; if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE))return; /* Get the highlighted/selected objects from Navigation Tool. */ UF_UI_ONT_ask_selected_nodes(&object_count, &objects); if (object_count > 0) { UF_CALL(UF_OBJ_ask_type_and_subtype(objects[0], &type, &subtype)); if (type == UF_machining_geometry_grp_type || type == UF_machining_operation_type) { if (type == UF_machining_geometry_grp_type) { ECHO("Object is a UF_machining_geometry_grp_type/n"); } else { ECHO("Object type is a UF_machining_operation_type/n"); } /* Note: UF_CAMGEOM_ask_geom_provider() will return the provider tag of the 1) Geometry parent if the operation is highlighted ( and is using inherted geom ) 2) Geometry parent if the Geometry parent is highlighted ( self ) 3) Operation tag if the operation is highlighted ( and geom is in operation - self ) */ UF_CALL(UF_CAMGEOM_ask_geom_provider(objects[0], UF_CAM_part, &provider_tag)); UF_CALL(UF_OBJ_ask_name(provider_tag, provider_name)); ECHO("Provider name is %s and the tag is %u/n", provider_name, provider_tag); int GeomCount = 0; UF_CAMGEOM_item_t * items; UF_CALL(UF_CAMGEOM_ask_items(provider_tag, UF_CAM_part, &GeomCount, &items)); for (int i = 0; i < GeomCount; i++) { tag_t entity; UF_CALL(UF_CAMGEOM_ask_item_entity(items[i], &entity)); RX(entity); report_container_objects(entity); } } else { ECHO("Object is neither UF_machining_geometry_grp_type nor UF_machining_operation_type/n"); } UF_free(objects); } else { ECHO("No objects selected in ONT."); } return; } extern DllExport void ufusr(char *parm, int *returnCode, int rlen) { if (UF_CALL(UF_initialize())) return; select_from_ONT(); UF_CALL(UF_terminate()); } extern int ufusr_ask_unload(void) { return(UF_UNLOAD_IMMEDIATELY); }
- 演示
阿飞
2022年4月17日
原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/245459.html