- 文章主题
NXOpen::Measurement::GetMinimumDistance 这个NXOpen方法是:获得两个对象之间的最小距离
与它相对应的UF函数是 UF_MODL_ask_minimum_dist ,有关它的用法,请查看 https://www.cnblogs.com/nxopen2018/p/10975886.html
- NXOpen类和方法介绍
NXOpen::Measurement类 : 提供计算和显示测量信息的方法
GetMinimumDistance 方法 : 计算并返回对象之间的“最小距离” ,这个方法有多个重载函数,按需选择。
- 代码例子
下面这个代码例子,来自一位网友,这是他在西门子官网上面下载的
//Sample NX Open C++ program : report minimum distance between selected objects interop #include <stdio.h> #include <string.h> #include <uf.h> #include <uf_ui.h> #include <uf_disp.h> #include <uf_modl.h> #include <uf_obj.h> #include <uf_object_types.h> #include <stdarg.h> static void ECHO(char *format, ...) { char msg[UF_UI_MAX_STRING_LEN + 1]; va_list args; va_start(args, format); vsprintf(msg, 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); } /*ARGSUSED*/ static int mask_add_faces_and_edges(UF_UI_selection_p_t select, void *type) { UF_UI_mask_t mask[2] = { { UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE }, { UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_EDGE } }; if (!UF_CALL(UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_ENABLE_SPECIFIC, 2, mask))) return (UF_UI_SEL_SUCCESS); else return (UF_UI_SEL_FAILURE); } static tag_t select_any_object(char *prompt) { double cp[3]; int resp; tag_t object, view; UF_CALL(UF_UI_select_with_single_dialog("Select an object", prompt, UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_add_faces_and_edges, 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, FALSE)); return object; } else return NULL_TAG; } #include <NXOpen/Session.hxx> #include <NXOpen/NXObject.hxx> #include <NXOpen/NXObjectManager.hxx> #include <NXOpen/Measurement.hxx> using namespace NXOpen; static double get_min_dist_interop(tag_t obj1, tag_t obj2) { Session *theSession = Session::GetSession(); Point3d *p1 = new Point3d; Point3d *p2 = new Point3d; double acc; return theSession->Measurement()->GetMinimumDistance( dynamic_cast<NXObject *>(NXObjectManager::Get(obj1)), dynamic_cast<NXObject *>(NXObjectManager::Get(obj2)), p1, p2, &acc); } static void do_it(void) { tag_t object1, object2; double dist; while (((object1 = select_any_object("First object")) != NULL_TAG) && ((object2 = select_any_object("Second object")) != NULL_TAG)) { dist = get_min_dist_interop(object1, object2); ECHO("The minimum distance = %f\n", dist); } } /*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); }
- 演示
阿飞
2022年4月16日