|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
使用UFUN进行UG NX二次开发: 装配设计技巧及步骤
2 |, `# H5 a' D/ ]; P4 M
" w+ |5 B" \5 U- d p. I7 G. t
. ~( o6 U' M& I P1、装入部件7 a8 X- ]4 S" K5 t
通过函数UF_ASSEM_add_part_to_assembly()指定部件装入的位置 、姿态等信息,实现在装配体中装入一个部件功能;9 k8 w5 c# M6 K5 s4 a' C
+ c& R$ u4 e1 Q5 l( H( n
2、创建配合关系
+ g; p3 ?) Z( U7 w9 T# za.通过函数UF_ASSEM_init_mc()初始化约束; N+ F9 o5 M+ V) V- z- y
b.定义约束关系,即填写结构UF_ASSEM_constraint_s中信息;. V4 T; f, n0 r$ D+ e
装配中各部件间的配合关系是通过装配约束关系来实现的。装配约束是指一个部件到另一个部件的约束,将部件A配合到部件B上,则部件A称为主动件(from),部件B称为被动件(to),在约束求解过程中,被动件在装配空间中的位置固定,而主动件将变换姿态到满足装配约束位置上。组成配合关系的约束之间不能存在几何关系上的矛盾,也不能形成循环定义。4 f4 z. y- o) W) z! ~
c.通过函数UF_ASSEM_solve_mc()求解约束;. r7 v7 p9 P" R. Z: m
d.通过函数UF_ASSEM_apply_mc_data将约束应用到装配体上;
# k4 Z. b$ D* J" _; R% Q8 be.通过函数UF_MODL_update更新模型。5 A% R: [4 e) m* h4 Q
% B1 {2 u. ?; c% R0 n* f6 f; j
- #include <stdio.h>6 o* h' E' L/ |* t
- ) t$ W; {- C1 U! k, D
- #include <uf.h>" `: J! q1 N% ~: R2 ^. @. a' \/ W9 w
- #include <uf_ui.h>
) Y% Q6 G, Q3 P. v - #include <uf_obj.h>
8 ~+ J! X: N* H/ W* @# D - #include <uf_disp.h>
# n5 z% k) r" f* Z! e - #include <uf_modl.h>
, j" z. q! C6 ~. c - #include <uf_part.h>9 J% N. r5 \: n0 V/ t% A
- #include <uf_assem.h>; }4 D/ C. B# K( @5 W" \
- ~- V# X& [: P
- #define UF_CALL( X ) ( report( __FILE__, __LINE__, #X, ( X ) ) )) V# n0 `9 c3 H9 j
t N* `$ |# ?1 w- int report( char *file, int line, char *call, int irc );: K: X6 {, m- C1 G- M9 h8 u
- void DoAssembly( void );
/ a# T2 A4 x# `2 H* W - 3 N* ? M- q2 h( B% z; O. j
- int report( char *file, int line, char *call, int irc )7 P" e6 i" s0 R- v9 y5 w! X
- {
4 o9 @( \7 F, T - if ( irc )
+ h W/ J& Z; r' r9 ^# M7 T - {; w. \5 q$ T0 \4 r6 e
- char err_msg[ UF_UI_MAX_STRING_LEN + 1 ];8 I! l% H# S: Y
- char msg[ 133 ];
6 V% B, @8 M2 F6 |- _. o - char fail_message[ 133 ];6 r/ e$ z4 E* j7 A2 \3 I6 J
- int len;0 i& w3 }7 t. X6 F5 Y8 A, F
- 1 J# F# E2 j3 n( [0 @
- UF_get_fail_message( irc, fail_message );
% f4 K/ @2 P' A7 f# R3 ? - ) X8 g, Y6 O% S0 ]+ w: U
- sprintf( err_msg, "%s, line %d: error %d: %s", file, line, irc, fail_message );
8 [" f! Z m2 I9 f' B2 E
: L* d" U7 ^" d+ P y- len = strlen( err_msg );% q5 [$ u7 J: w- q: X/ z$ k
- len = ( len < 131 ) ? len : 131;; a8 v6 I; W5 i- @3 o8 T
- strncpy ( msg, err_msg, len );
6 S+ M, H! b: y! V2 v8 [/ m+ a - msg[ len + 1 ] = '\000';
9 x8 V0 ~9 x8 q6 d# B# _$ J6 F+ ] - ( X1 ~) _$ U6 W3 _7 E$ l0 j
- uc1601( err_msg, TRUE );
: I& W! ~' P; g; ]( }: a - }+ p4 m; ~8 ^7 V9 j E
- return( irc );9 Y i9 ^- C6 ^, i) _7 `
- }- @& `1 P" B( b* n
- % ?* ^1 O8 e2 E* b ^9 K# |3 E
- extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
! x8 }5 c$ n2 C3 P - {
3 f/ v* \0 ~3 t& J: J5 V' F4 C, x - if ( UF_initialize() ) return;
7 X$ N+ o% a$ u - DoAssembly();% w9 V! v/ p2 m- v& K. i; m
- UF_terminate();
5 T' C4 e! Y' U B, u0 p - }
& e1 L' T0 ]9 J& B& Y - 3 A# y- b5 b+ b( p' [; Z8 K, k
- void DoAssembly( void )
# A5 o* A# m9 t3 c# L7 { - {# ^( f9 d2 @0 Y% u, e! s5 r
- if ( NULL_TAG == UF_PART_ask_display_part() )( J7 W% o2 z- [8 f
- {1 ] P6 v! f' J5 L7 b( u
- uc1601( "请新建一个文件再进行本操作!", 1 );
, }0 n: e) D( j% J - return;
n6 @ m/ {, n3 j- J - }
/ Y) n1 z2 W% i- x/ s - 7 w% `2 h+ S+ [! x Z
- tag_t tagInsCyl = NULL_TAG;0 s, C% `/ n( t! {( B! V% F
- tag_t tagInsVBlk= NULL_TAG;
8 U, ^( P1 R8 S j5 w - tag_t tagOccCyl = NULL_TAG;, y8 g5 z+ l) l" I" E1 S
- tag_t tagOccVBlk= NULL_TAG;0 P) S, g2 M+ f5 E& n, z0 a! c
- UF_PART_load_status_t ErrorStatus;
$ A2 p- n' H: l) e - # e& A5 a& P& i1 }0 K
- double dblzOrigin[ 3 ] = { 0, 0, 0 };
+ n6 d& k3 d' ]$ p* }5 t5 A - double dblzCsysMatrix[ 6 ] = { 1, 0, 0, 0, 1, 0 };
5 V" @& v R7 I5 z# L4 M+ t
9 c: p; B2 t! Y& t9 r* |- /* 装入部件GB2208_80_Vblock.prt */: ?% F2 b& A1 s& B+ @6 q( k. J4 J
- UF_ASSEM_add_part_to_assembly(
2 _. Q" w1 A# x d- Q - UF_PART_ask_display_part(),! n+ f) h4 i/ Q/ r
- "f:\\ug\\chapter4_1\\GB2208_80_Vblock.prt",
! u1 }2 u/ v6 {$ a - NULL,
2 I7 O* e( s* }+ `" k* o3 S* O2 F - "VBLOCK",
- j: X0 B9 [- @ - dblzOrigin,
7 I! e; Z/ X( G, s) M) ~ - dblzCsysMatrix,3 E3 ~) f9 B- R2 i
- -1, ]4 \+ P: l* T5 X" J& j9 @' O
- &tagInsVBlk,
7 J1 A* m: M a$ g - &ErrorStatus );
4 \+ X+ s6 L- J& M" r7 F - /* 装入部件Cylinder.prt */4 n# Z) ^- f: j/ D8 v; A
- dblzOrigin[ 1 ] = 50;
( |' e) W6 i2 c' ? - UF_ASSEM_add_part_to_assembly(5 j% i. [3 r: f1 z8 R
- UF_PART_ask_display_part(),: m3 H3 y# d2 y' c& {3 L" a8 {
- "f:\\ug\\chapter4_1\\Cylinder.prt",/ ?6 f' r3 y- @) i+ T, H
- NULL,
! r( q/ M( w/ ^- G/ K6 P8 p - "CYLINDER",
& O+ I% w7 S) W' V# u$ ^& ] - dblzOrigin,$ |! N" Q% h. }
- dblzCsysMatrix,
* T0 Z" u3 E7 B+ d - -1,7 K1 B# |9 u8 I/ I
- &tagInsCyl,. I) I" ^2 A: i
- &ErrorStatus );) M$ A/ s5 z" ?8 F! h; [/ r7 `
- tagOccCyl = UF_ASSEM_ask_part_occ_of_inst( NULL_TAG, tagInsCyl );, w+ r! S. r+ I. N3 s- ]
- tagOccVBlk= UF_ASSEM_ask_part_occ_of_inst( NULL_TAG, tagInsVBlk );8 b# b6 C4 L* @0 I8 N* J; B( n) N2 X
: n2 a8 h- C {7 E& ~- /* 创建配合关系 */
, d7 k- x& n) u$ B/ c - UF_ASSEM_mating_condition_t McData;0 R" {+ r, X6 m% k
- tag_t tagObjectFrom = NULL_TAG;
5 N$ o+ w$ b8 T0 X: t5 V$ I# Z0 f" @ - tag_t tagObjectTo = NULL_TAG;
% D8 X b, d1 ^2 l+ x* }& N( I - tag_t tagPrototypeFrom = NULL_TAG;' s4 s& L. F0 I( G1 U) E, @! {
- tag_t tagPrototypeTo = NULL_TAG;
3 Y$ N: h) }9 F+ ]: T1 ^ -
" T' n# s/ ?5 ` - /* 初始化约束*/) Y+ P0 x5 l: `8 C5 ^
- UF_ASSEM_init_mc( &McData );
4 H; k T: d- G; f* ^1 U- p9 K - 1 }* `' o3 o! m9 X& L
- /* 定义约束,构造配合关系*/& e# x) m |* N1 c4 `
- McData.mated_object = tagInsCyl;; g5 l# J. F2 Q4 L) {$ C- w9 F- g
-
0 o0 v" L9 ^/ O; h0 W* ] - McData.num_constraints = 3;0 @6 E6 }4 t. ?. G; M2 y
- McData.name = NULL;* F4 E/ e) _. y7 O0 P* [
- McData.user_name = false;
; a9 |5 m9 `0 C3 a8 x4 E. K/ x - McData.override = false;9 l( c/ N% b$ q
- McData.suppressed = false;
2 ^; {0 W8 \$ }: Z" g6 H* W6 }' I - McData.implicit = false;! V4 K6 S s7 \8 z
; S/ s6 ?1 [2 e+ t, ^- tagObjectFrom = NULL_TAG;
# p6 [1 ^& J; }" W# I- j! J - tagObjectTo = NULL_TAG;
' b+ N' K5 F' F. q K V/ {) m+ I W - UF_OBJ_cycle_by_name( "CYL_FACE_3", &tagObjectFrom );
& {( [) Q) X6 t) B' f7 A - UF_OBJ_cycle_by_name( "P1", &tagObjectTo );! [. i* G: n; L' ]/ I; ~+ W
- tagPrototypeFrom= UF_ASSEM_ask_prototype_of_occ( tagObjectFrom );
% o6 Q5 |! m+ P% c: X7 i! w - tagPrototypeTo = UF_ASSEM_ask_prototype_of_occ( tagObjectTo );! W1 D* h; f- [
- McData.constraints[ 0 ].from = tagPrototypeFrom;
( R. n( k! z+ I2 G0 k, | - McData.constraints[ 0 ].from_part_occ = tagOccCyl;! Q3 U! R" J$ e1 L, G
- McData.constraints[ 0 ].from_status = UF_ASSEM_ok;; r: {6 q1 H6 r9 P, B1 a9 I- E8 {
- McData.constraints[ 0 ].from_type = UF_ASSEM_cylindrical_face;
+ ?5 m f b0 W$ [, M# G5 J7 ` - McData.constraints[ 0 ].to = tagPrototypeTo;; P3 c; o& F9 Y$ c9 B4 _
- McData.constraints[ 0 ].to_part_occ = tagOccVBlk;
& c$ O9 [1 ^1 c/ _% u) e - McData.constraints[ 0 ].to_status = UF_ASSEM_ok;
& ^6 f' D8 m% k5 E" { - McData.constraints[ 0 ].to_type = UF_ASSEM_planar_face;& w2 i9 L- i7 ?+ h: A5 t" W
- McData.constraints[ 0 ].mate_type = UF_ASSEM_tangent;' _( D3 N h4 p# {7 h
- McData.constraints[ 0 ].offset = NULL_TAG;
6 R* I" L+ @* l/ {( N3 Z) Y - McData.constraints[ 0 ].name = NULL;: w& `( \% z: q/ K9 W0 B
- McData.constraints[ 0 ].user_name = false;
2 Z. |. q' r6 S8 _1 ?6 H; | - McData.constraints[ 0 ].inherited = false;3 ~& ]/ B) P1 ?: ~; A
- McData.constraints[ 0 ].suppressed = false;6 Q8 V1 M) Z" h) q& C3 c
- McData.constraints[ 0 ].has_help_point = false;4 R) l# s& b- c5 ]% \7 G( \; a/ c
- UF_DISP_set_highlight( tagObjectFrom, 1 );
- d6 J) a7 o/ e, { - UF_DISP_set_highlight( tagObjectTo, 1 );1 O3 m9 z% ~& X2 E2 H6 |. h
- uc1601( "这两个面进行相切操作", 1 );5 ]3 \- D4 X- c9 j* h7 Y
- UF_DISP_set_highlight( tagObjectFrom, 0 );
, E# K: C3 o J+ k - UF_DISP_set_highlight( tagObjectTo, 0 );
5 T. C" Z; z3 j, n# Q3 O9 o* E: a - ( ^* l) l6 d6 V
- tagObjectFrom = NULL_TAG;
( R4 G" u3 h2 W. `3 H% U' T - tagObjectTo = NULL_TAG; s6 w. {9 M. d/ |$ j- w
- UF_OBJ_cycle_by_name( "CYL_FACE_3", &tagObjectFrom );
& D; U4 e# ?6 d! Q - UF_OBJ_cycle_by_name( "P2", &tagObjectTo );* W3 _% O" w7 r) x0 p
- tagPrototypeFrom= UF_ASSEM_ask_prototype_of_occ( tagObjectFrom );
4 W+ y* [! \" o# ` - tagPrototypeTo = UF_ASSEM_ask_prototype_of_occ( tagObjectTo );
, ^8 t, l6 z( }2 ^. T2 w, T9 B8 c - McData.constraints[ 1 ].from = tagPrototypeFrom;
1 Q9 w+ l( G r' K5 J4 G9 H - McData.constraints[ 1 ].from_part_occ = tagOccCyl;7 o# q8 v# h+ t" X4 L% r
- McData.constraints[ 1 ].from_status = UF_ASSEM_ok;6 F6 R# Y3 V8 O% @3 d% W4 F9 F1 Y
- McData.constraints[ 1 ].from_type = UF_ASSEM_cylindrical_face;! z8 H* ]# b e% d+ p4 M
- McData.constraints[ 1 ].to = tagPrototypeTo;
& H3 u, p$ P: t7 F0 {6 { - McData.constraints[ 1 ].to_part_occ = tagOccVBlk;
* T8 f+ P2 L& c - McData.constraints[ 1 ].to_status = UF_ASSEM_ok;
: f+ _+ ^7 G5 h. X; p3 x1 Q9 S - McData.constraints[ 1 ].to_type = UF_ASSEM_planar_face;
9 R* v6 u# c. d1 p - McData.constraints[ 1 ].mate_type = UF_ASSEM_tangent;
; L( u' H" r1 C3 m9 T - McData.constraints[ 1 ].offset = NULL_TAG;# ]2 n* |2 B# a: m
- McData.constraints[ 1 ].name = NULL;
, f* D6 f t# E3 f0 i S - McData.constraints[ 1 ].user_name = false;
" W$ x/ S! {! P! V) L" \ - McData.constraints[ 1 ].inherited = false;
k2 k& @0 Q, B' f/ D1 ^ - McData.constraints[ 1 ].suppressed = false;
5 U$ \4 o# r( G4 O - McData.constraints[ 1 ].has_help_point = false;% [4 S9 D1 i, g- J1 r; k! s
- UF_DISP_set_highlight( tagObjectFrom, 1 );
( A- c+ P% I1 R - UF_DISP_set_highlight( tagObjectTo, 1 );8 |2 J/ c# y6 f8 s! W
- uc1601( "这两个面进行相切操作", 1 );2 p- I. b8 U, w# N' i5 }2 r
- UF_DISP_set_highlight( tagObjectFrom, 0 ); q& Z- m7 g# X! t
- UF_DISP_set_highlight( tagObjectTo, 0 );+ @4 G: y5 c1 a3 |# i
1 k: E `1 Z/ I9 D6 V( Z- tagObjectFrom = NULL_TAG;
* D+ \8 Q& n# z& a3 B0 q2 B! _ - tagObjectTo = NULL_TAG;
, v5 h& v' g, @& W - UF_OBJ_cycle_by_name( "CYL_FACE_1", &tagObjectFrom );
: |' r. F& K5 k9 u5 B& w - UF_OBJ_cycle_by_name( "P3", &tagObjectTo );
# o1 L" t2 T9 I& W( J6 F - tagPrototypeFrom= UF_ASSEM_ask_prototype_of_occ( tagObjectFrom );/ x0 i3 O3 Z. t# D2 I
- tagPrototypeTo = UF_ASSEM_ask_prototype_of_occ( tagObjectTo );4 p# K/ S! I! `6 f! \* N2 o
- McData.constraints[ 2 ].from = tagPrototypeFrom;
1 v* g( V6 D/ i5 r - McData.constraints[ 2 ].from_part_occ = tagOccCyl;. |* o5 q# i8 Q: l
- McData.constraints[ 2 ].from_status = UF_ASSEM_ok;9 D1 x& y. E! I' Q; L$ z( O
- McData.constraints[ 2 ].from_type = UF_ASSEM_planar_face;
D6 _+ f O! p" A5 G: I6 h - McData.constraints[ 2 ].to = tagPrototypeTo;0 B8 |+ \& P* j6 \. E( w$ v1 j5 @ t
- McData.constraints[ 2 ].to_part_occ = tagOccVBlk;
4 v; V$ o8 O: S) O# Y7 Q - McData.constraints[ 2 ].to_status = UF_ASSEM_ok;$ j& x3 E$ N# t- V4 j8 P
- McData.constraints[ 2 ].to_type = UF_ASSEM_planar_face;
, {4 _; {9 X6 \/ S3 ]1 P5 H" @ - McData.constraints[ 2 ].mate_type = UF_ASSEM_align;
% v W t4 T I8 q6 \) J* E6 a - McData.constraints[ 2 ].offset = NULL_TAG;; |# z/ X1 A" S6 F8 z
- McData.constraints[ 2 ].name = NULL;
. g. M9 J( Q5 m# e: N7 S; b& L - McData.constraints[ 2 ].user_name = false;
, \# J. |0 S& d7 n - McData.constraints[ 2 ].inherited = false;9 V: ?( q5 v* \' `% A
- McData.constraints[ 2 ].suppressed = false;
- b" Y' N! t0 V5 e/ h" U( Y - McData.constraints[ 2 ].has_help_point = false;
/ t3 F+ p' ?% ]3 H. A - UF_DISP_set_highlight( tagObjectFrom, 1 );
. T4 ^3 P& y1 @- e" b7 K, M - UF_DISP_set_highlight( tagObjectTo, 1 );
" W' P. F: ]2 ?% G$ l A - uc1601( "这两个面进行对齐操作", 1 );
: I" o( v+ R. [ y' Z - UF_DISP_set_highlight( tagObjectFrom, 0 );
5 P! Q1 y! u3 { - UF_DISP_set_highlight( tagObjectTo, 0 );
+ `7 }: p5 _5 A. l3 J& t8 w - # H. b+ m' `7 _# }, @
- double dblzTransform[ 4 ][ 4 ];
) y; b1 t7 C E7 W9 B0 Y7 V - UF_ASSEM_dof_t Dof;
4 X2 J6 R" g9 B6 w! M0 ? - UF_ASSEM_mc_status_t Status;5 l9 X( |3 b2 A9 ~1 W' t+ ~
- 7 e4 W3 [8 ]. i; t
% @# J' w* b4 f( G/ B- /* 求解约束*/# p4 u8 v! k8 N8 ^- l' T% l
- UF_CALL( UF_ASSEM_solve_mc( &McData, &Status, &Dof, dblzTransform ) );! _- x' g9 i; `" p$ }) I
- if ( UF_ASSEM_mc_solved == Status )' y2 z4 ~7 _1 p. F$ ?& \
- {
1 L( E0 ~( p+ i7 a& N g - uc1601( "求解约束成功!", 1 );; w& M7 }9 k, k0 }1 q6 D
- UF_ASSEM_mc_structure_state_t StructStatus;4 @4 [7 e7 }& i, V" V
) P! \$ t1 M+ E; d1 {- /* 将约束应用到装配体上*// p) M; C c: L. L- B; Q8 j
- UF_CALL( UF_ASSEM_apply_mc_data( &McData, &StructStatus, &Status ) );* o( r: ~/ q1 N1 H' |; t
- if ( UF_ASSEM_structure_ok == StructStatus ) 5 v- o. z! P7 k* J( g
- {
+ a) ?2 A2 ]' M* I - uc1601( "应用装配成功!", 1 );3 T* V# T- k7 g! X! H( N; ^
-
* ?9 q1 |+ o( e2 |: f - /* 更新模型*/, m/ I5 }: o& s2 T1 h- z4 X
- UF_MODL_update();& w; h+ p9 C( V4 ^+ R0 r
- UF_DISP_refresh();
( ]/ f" u1 h: u" s2 J& w4 I( R - }4 J/ D" W9 S/ D
- else uc1601( "应用装配失败!", 1 );
/ p) Z% ^0 N0 W. L" o3 J( Z d - }
' M7 I: C! O5 \& H - else uc1601( "求解约束失败!", 1 );( @8 U4 {/ I. p+ ?7 {1 {/ Q5 ^
- }
( l9 c% I y+ R - }6 J; }; w/ z, A! x
复制代码 . T8 J# y# o7 y9 h
! {5 k6 {$ z% o- b, M
; W+ |5 C$ V! J3 {6 `% w7 Q' |$ X" k
7 t2 l! D7 A' Q" |
7 x( D9 R! _. G- Z2 n6 T! p, C' d* j6 f: V6 X3 E$ d6 A8 L% ?
|
|