标签:include items ECHO UFUN ask part 二次开发 UF type
这个例子是一位网友从西门子官网支持中心里面下载分享的
- 代码
//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日
标签:include,items,ECHO,UFUN,ask,part,二次开发,UF,type 来源: https://www.cnblogs.com/nxopen2018/p/16157408.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。