|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发代码分享: 获取实体的最小包络尺寸bounding box
; ]/ Y: ~% \3 \0 A7 h1 L. ~- w2 v {) t7 w# W7 Q) W6 K
很多时候我们需要指导毛坯的尺寸,也就是stock size,在moldwizard里面已经有这个类似的功能,如果通过开发,如何获得,请参考如下代码,执行结果,就是显示x,y,z方向的尺寸!. @' d* g$ ]- E* c
bounding box
! E l1 C, q$ ^1 r- static int UF_UI_sel_init(UF_UI_selection_p_t select, void * user_data)" C. A |$ |5 D) z$ T/ i$ s
- {
- j3 ?1 ~# x, D - UF_UI_mask_t mask_triples[] = {
) e, O. K$ b: @$ b - UF_solid_type, 0, 0};
w8 f2 C: F* Q! w( o) p7 [ - if (UF_CALL(UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,1,mask_triples))==0)6 g* A% T h# Z5 k* S3 i
- {7 G! x/ S: G' m0 g' B8 u& A
- return (UF_UI_SEL_SUCCESS);
" K2 ~' Y: Q- ^, M% d4 |0 D7 k. Q - }- n9 I( `4 ~1 q3 |' B
- else# y8 M3 v7 { |' j! a
- {
+ x8 K/ B# A/ S# q& C$ W - return (UF_UI_SEL_FAILURE);
8 }8 r$ c% b5 |! _ - }9 x; V( S; T! X$ O$ l, y
- }0 g" L2 P& ^( k4 e
- ' l8 V4 S: m y! p8 R2 E) [" w
! p9 T, o' O) }5 @9 Z1 P- static void do_api()4 U" ~# q4 E& B' r, E
- {9 Q/ }# K$ c/ v
- tag_t object,view;6 B1 g8 A( }) {
- char cue[] = "select object to get the dimensions";
- F w2 \! ^: l9 g G/ _$ _ - int scope = UF_UI_SEL_SCOPE_WORK_PART;' \- K! }3 E1 }: {; p
- double x,y,z;4 |& l$ U7 I1 n- z& A# L9 P
- int response;
1 u( V" p( j) q( K - double boundingbox[6];
% a2 ]3 z3 c) v% T8 H( ~- `; M - double cursor[3];
, s8 e+ n& F ]9 O - UF_UI_select_with_single_dialog(cue,"select the object",scope, UF_UI_sel_init, NULL, &response, &object, cursor, &view );: l' X$ G% R' i, G) K0 N6 W% i/ L
- if (response == UF_UI_OBJECT_SELECTED ||8 D; S0 ?' g. Q! ?, H9 N
- response == UF_UI_OBJECT_SELECTED_BY_NAME)6 y1 @4 l# v/ p( g
- {* j4 Q8 \7 N& [2 w! o' r( E
- UF_DISP_set_highlight(object,0);0 Y" Q8 X: w0 H5 E: o
- UF_MODL_ask_bounding_box(object,boundingbox);
g& n2 ~8 t6 Q - x = boundingbox[3]-boundingbox[0];+ ?$ d% d7 g+ _6 C" [
- y = boundingbox[4]-boundingbox[1];
( N: ^8 E) U3 N; |1 F3 r; M - z = boundingbox[5]-boundingbox[2];) V! _7 P1 h8 M" E n! N0 h
- char message[256];
7 G- o9 B2 {# h- H - sprintf(message," X dimension = %.3f\n Y dimension = %.3f\n Z dimension = %.3f\n",x,y,z);: E. V' ~- y" T# ^" f5 x
- uc1601(message,1);# A( H( L4 l2 r
- }
5 C4 W3 s# h. y( U4 r2 g6 B& f - else
) O1 y$ C' q3 P( t - uc1601("No object selected",1);
, Q$ h5 f5 ]/ ]$ D -
1 \5 k, p* }8 b Y7 W- T \1 s+ g - }9 T) x0 [. x& G- c
复制代码
$ |: i; i" j7 G# I+ r" ^& u3 e" a
|
|