PLM之家PLMHome-工业软件践行者

[二次开发源码] UG二次开发源码分享:UG NX CAM加工开发简单实例

  [复制链接]

2017-12-11 15:49:09 8589 5

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82172
QQ
发表于 2014-6-7 10:50:25 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
8 P3 p# y8 A# u4 T. n' r, ?
& a- Y+ }, a- U- R
% ^% T6 ]$ I0 L+ g3 `1 @
* g. {: y+ @. q) ]" [

#include <stdlib.h>5 r5 u. S' G5 I9 e# Z
#include <stdio.h>

#include <uf.h>% g  T0 w1 C2 G/ `# v) n
#include <uf_object_types.h>
% Z+ ^/ i. x& F1 u" `" h#include <uf_ui.h>
* u, ]0 |2 r/ A" r#include <uf_disp.h>
8 y( m0 K) h4 L. s5 r#include <uf_obj.h>' F) r: g7 m4 G" ]* I; `6 l: m
#include <uf_cam.h>8 Z% m3 P4 M) v. ?& q7 Y/ f' |
#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 20
" w# A% U  N" m/ w' x#define EXIT_SUCCESS 0

/*#define DEBUG*/

static char *title1 = "Select an API routine...";

static int geoption;
" O5 H+ |+ U4 m0 `* O* a' ostatic char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何
8 a+ f9 N- u0 u& z; v% Jstatic char menu3[][38] = { "1) Part Geometry",
. ?- l; H# }# u8 _"2) Blank Geometry",7 G+ B0 D( h# Q7 z0 K! ]0 V
"3) Drive Geometry",% M3 Z$ `+ i/ I0 i# J
"4) Cut Area Geometry",
9 @6 e6 t5 \3 \"5) Trim Geometry",- Z9 w/ w* o, z$ f3 ?9 l# V, ?# [
"6) Selection Complete"};

static int init_proc(UF_UI_selection_p_t select, void *user_data);//初始化程序

static void init_camgeom_app_data(UF_CAMGEOM_app_data_p_t app_data);

int ufd_camgeom_ugroup( tag_t objTag, int obj_count )

{( Y- S1 s% z, t) r/ D2 K; ]4 Z0 k
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];( ]* g, A/ n& j. \4 i
tag_t *objects, entity_list[MAX_CAMGEOM];
7 O; c  `3 j9 Z# }9 `6 ~int i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";" y$ Q8 @% ^% p' f% S. l
char *cue = "Identify Geometry - Wait for the Filter!";0 ]. x" w. i& \/ {' E
char errorstrg[133];) x' _( Y: v( L
int response, irc;6 j/ i" _" E' m5 [* D: c
tag_t eid, view;
9 D2 N7 x2 z4 a. cdouble cursor[3];

#ifdef DEBUG7 e4 O0 |: m. _- q
printf( "Object tag passed into camgeom_ugroup is %d \n", objTag );& k# s6 s! F* O6 _5 y
#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????
9 c! B0 P  S8 J* \. @* g7 \  |3 C{4 i$ N; c; D$ ~8 p
/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

geoption = uc1603(title3, 1, menu3, 6);

if (geoption == 1 || geoption == 2 || geoption == 10 )
1 m; t) o7 i6 }1 U* w1 o( F{% B+ D8 j( m$ E4 @: {
break;* ?9 a+ \' j" _% ?2 a$ e$ Q: i
}
+ |) E- v$ m3 \#ifdef DEBUG" X, Q& [/ @) x& x+ ^# ^5 l
printf("\n Geometry option returns %d\n", geoption);
  [8 G) l! o% @#endif) p  L  }2 j- }# c4 v- `/ a0 |
/* Allow the user to select faces or bodies. 选取面和实体*/

/* Pass in this function the object to be assigned geometry 通过函数,对象被分配到几何体 */

if (obj_count > 0 )
' Z; F9 l' ~- |9 Z/ x5 G{
/ e% K* @" u8 L& Lentity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle,2 ~& h3 b0 R+ w# B0 w0 a$ C
UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,% a* A: d. k5 T. h
&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义
/ M/ @& N% m+ @! l//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED)$ W# Y2 |. y; H9 R* E( z4 V( @
{
; h. k6 S& i, p# g' Lentity_list[entity_count] = eid;
, B+ G$ [& a0 l, w, w/ r$ B6 U#ifdef DEBUG2 S$ A1 ~4 e8 @) Z0 d
printf(" EID number returns %d\n", eid );5 g) S9 d% \* u+ e1 _
#endif

/* Allocate the memory for the application data of an item. 为当前的应用数据分配内存*/

app_data_list[entity_count] = (UF_CAMGEOM_app_data_p_t)UF_allocate_memory(sizeof(UF_CAMGEOM_app_data_t),5 d$ G# b% _% A$ R. s( f
&err_code);

/* Initialize the application data.初始化应用数据 */

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;0 r; z; @1 W7 V1 \9 g# ?
}- @. Z9 c* M/ u: Y! W" L
else if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
9 v' `9 _  a" S: J# _5 T" [{
% U/ F$ j& _% I8 X, B/* Geometry selection is finished.几何体选取完成 */
1 r  }( Z9 W* ^, t# hbreak;
$ ]: L0 b) @8 l2 t}6 Z* K' C* R  T  {0 D9 f. K: ]
}5 y  ]; C0 I$ e( `) `. Q
#ifdef DEBUG
. K4 m3 y" `! h  f# Z; q5 x$ ?printf(" Entity count this selection is %d\n",entity_count);
* g# E' E9 I. Q#endif

if (entity_count > 0)
$ y8 L. j2 j+ K! W4 j. e- T7 b! m6 O( N{
- ^2 j- k+ F/ V, w2 d/* UF_CAMGEOM_item_t *items;
! H# H4 R8 ~  R6 [$ Kint item_count;*/

for( i = 0; i < obj_count; i++ )" s6 y/ D9 F$ G/ S2 y5 J; V$ p
{8 ?" S  n9 u# Z1 e- y0 ]
irc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||
( _4 k- x: a, G" \type == UF_machining_geometry_grp_type)

#ifdef DEBUG
- \6 x; f+ K8 u+ g0 q! Tprintf("\n Current entity count is %d", entity_count);: {2 {$ ]9 j( {8 L0 F
printf("\n Current object count is %d", obj_count);
9 w% ?; ^- O& I; g1 X& r& Wprintf("\n Geometry option is %d \n", geoption );
6 f! p. T, {% ~6 J#endif

/* Above prints to help in debugging if "DEBUG" defined. */

{
. f* C& ~, N+ V/ Z2 V9 z" bswiTCh (geoption)% A$ p, p6 _* _7 @
{/ ]6 L+ `1 S1 B
case 1:3 j* E6 w$ ~, h7 B5 V( Y9 ?: M
case 2:) r8 @8 d4 u+ j9 A! s: \
case 3:! P; Z& _. ]& \
case 4:
5 o/ Z% X$ @( t! T$ W$ R- acase 5: /* Part Geometry 部件几何体*/6 R* t3 L, X' h; }. ?$ \0 c
{
1 I. n& r/ \* f# u#ifdef DEBUG" d1 s, P1 z5 H! h% c
printf("\n Type returned is %d", type);
" u; j" h& a8 W5 k- Aprintf("\n Subtype returned is %d", subtype);
1 D- ]) A+ z% s. e; `#endif! F1 s* f7 ~& k5 o) v$ Y5 S3 t
{* Z3 W, O& }; ^
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,) o" m0 T- o: b, Z
entity_list, app_data_list );( ]+ o, a. r; t- `7 V2 H4 ~5 O7 n
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
! Q6 e/ M3 I* f2 d# h: y; z//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。
: Q' Z+ F! s# `$ e5 E. O/ B/ \}
1 S) ?& ^3 ~. I( U  wif ( irc != 0 )
) K+ Q  M& z; S9 f0 A0 d{, P8 x' {4 r5 w; W0 S: w& p
UF_get_fail_message( irc, errorstrg );
7 l4 m& T9 }  y, L5 i2 lprintf("\n The return code is %d\n", irc);$ r( k* v7 z3 o2 j. X2 A+ y- v* u5 l
printf("\n Error code translates to %s\n", errorstrg);
- P. n, p3 T3 f; \9 Rreturn objTag;1 D5 M) Y& Q: A3 e( r
}
6 B) j2 p& }. U, |break;
8 `9 S- O2 L: m: x" Y9 g}

case 6: /* Blank Geometry 空白几何体*/
# ]( J) p" g' U, `{$ |. u# u3 w' v) W; V: O& f) {$ X
#ifdef DEBUG
, M+ F8 {1 J+ _; u8 aprintf("\n Type returned is %d", type);, t$ I6 a, J: f
printf("\n Subtype returned is %d", subtype);
8 u9 D2 }( I/ c#endif$ ]7 e& m$ p' {: }6 ~7 I; X9 z
{
5 u  O( _2 r1 W# c0 t; Jirc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,
& }7 @2 c2 Y- eentity_list, app_data_list );
9 w3 I, J, L& n, x7 y7 }- O5 v( M}- K: O2 [! N! B  M  U% M
if ( irc != 0 )
. Z  B9 o) t& W9 y7 j6 S8 T! m9 D{  A) o4 J& Q' A; Q: o: v
UF_get_fail_message( irc, errorstrg );
, }1 x, j- F& ]# a9 c% Dprintf("\n The return code is %d\n", irc);8 A' d: k$ |- d
printf("\n Error code translates to %s\n", errorstrg);5 M% {4 B% W1 ~' \
return objTag;$ q" b( o1 Z" I/ m* a& C
}9 k+ `: N, K. `
break;

}

case 7: /* Check Geometry 检查几何体 驱动*/0 N& r8 c: q9 F
{' g6 _9 Z7 {5 d- r2 H; k* Y; l* h* r) s
#ifdef DEBUG7 w) h5 }- c" v7 M* N2 M
printf("\n Type returned is %d", type);
% {2 G. E+ L, M( S, |4 K$ w. k% {printf("\n Subtype returned is %d", subtype);, f9 ?2 |. ?/ C7 G
#endif
# q2 n# _. j3 ~4 A, Z7 {( H{4 m5 k& Z! a! Q# Q8 U5 Z( P
irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,
  b* E, m% m1 Pentity_list,app_data_list);  p. j0 ]6 A9 L+ e+ `$ B2 x
}
) |: k. _! k# H+ D; K7 y6 V& D8 iif ( irc != 0 )
3 i* X& H9 p9 _{
/ E3 C1 x6 t7 lUF_get_fail_message( irc, errorstrg );
% A/ q* `/ x8 D( ?1 c9 n( q8 ^printf("\n The return code is %d\n", irc);
+ c( a7 |. ?$ I  D4 F& C, }printf("\n Error code translates to %s\n", errorstrg);, W& h6 \% P) U8 A5 i
return objTag;$ L9 L6 c, M, g+ s; Q, L* R
}; t. K  E' W; T# @0 r# s3 X
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
) l' T* P* s' ^# X{- U, [+ U4 J* @0 @5 i# ^
#ifdef DEBUG# E1 H, q& e. J9 i: X
printf("\n Type returned is %d", type);) _# X& Q: s' N# o3 x. [2 p7 s
printf("\n Subtype returned is %d", subtype);( P. O$ f  N4 e7 H& b( p' `1 H
#endif8 o* i+ P( b+ y7 g; x
{
% h1 b8 s( u. U. o3 U( ^! Virc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
6 {8 ~, `1 [) M3 ?2 mentity_list, app_data_list );
* [2 r- e/ J/ r}
3 }5 V, E5 {0 M1 o& dif ( irc != 0 )9 e( R, L) e: {0 D# ~4 `
{. b8 I  p5 S" J$ B* s- ~
UF_get_fail_message( irc, errorstrg );
& k5 C8 a! L6 ^. F* \. h$ f' iprintf("\n The return code is %d\n", irc);
0 A) D6 d! ~3 L9 [& r1 d! bprintf("\n Error code translates to %s\n", errorstrg);$ S1 v9 A2 Y4 R/ ]5 z1 M
return objTag;, c/ l; q7 ?, d, Z0 o  v
}- p! Z8 Z. b9 N: O
break;  I8 i" n0 g/ i, Z7 o/ T) k! j4 \
}
1 u3 j- g4 _3 L4 y9 Xcase 9: /* Trim Geometry 修剪几何体 */0 i; {+ y* S5 ?& y
{* Z! g5 b% X  M3 l5 H
printf("This case not implemented.\n");4 U: I4 D2 ~9 ]5 }& e
break;9 Q4 k! ]6 b% K: V3 F1 `
}
$ O  t7 C$ _# w0 A1 M4 V  R; d/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/2 p  }- s- \1 C: d4 K1 D
{
5 W" ^; K& }. N1 ybreak;
$ T. ]: h7 i, S. {}
2 L6 R3 K, R. `6 _2 n; E) ~3 d}: W) g6 g6 i! q. V- K
}
/ Z5 S  e6 `! G# C9 n$ V}  v" e# X+ e- T( a3 W
}
5 q$ U9 x/ Z4 V- m2 [2 `/ @) W}+ a3 r# i" u! P1 V$ ^! h' d/ N
}5 @* ?+ H. k; Z
/* Free the Allocated Memory. 释放内存*/
0 R$ }- L8 u' xfor (i=0; i<entity_count; i++)
+ y; e' `/ K' D- U0 s1 c/ q/ [{
) h0 ~' f: D7 G1 C  S( Z9 kUF_free (app_data_list);. v; P. f0 F# L
}

/* UF_free (objects);*/

return(0);
9 F1 O1 U2 w/ Q" X9 m}9 U) s4 b0 f4 [7 i# n
/* Selection initialization procedure 选择初始化程序*/% ]- c. J) @& x: ]
static int init_proc
2 O$ \8 t" @8 h) R(! E3 J) O# e+ ^2 |1 r
UF_UI_selection_p_t select,//指针 pointer% m" y2 P7 R& g6 @
void* user_data  b, Q3 u" L+ u& y! Y6 ^
)$ E4 x  y# u* ]  z
{5 ]7 q" ^! t9 }- W
int num_triples = 3;
$ I; m# E+ j* t9 @/ @# K# X//最终指定的特征类型! {" a2 X  n6 Y. P" ^0 i) U3 }
UF_UI_mask_t mask_triples[] = {2 s6 n; _* z& J' }( `
UF_line_type, 0, 0,
7 u4 M! ^! X+ ~) ~' BUF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,
  X* ]) Q8 R- u$ v. \  X! W. m$ A' hUF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

/* Enable Faces and Solid Bodies允许选取面和实体 */

if((UF_UI_set_sel_mask(select,5 B/ L& l+ X' g# t) ?
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,+ W) g0 }7 f1 x6 G8 \
num_triples, mask_triples)) == 0)//3倍 3*3=9

{* |! k% P3 p# y4 h7 W6 Q+ L! ?
return (UF_UI_SEL_SUCCESS);0 b+ l% w, {% {7 W& Y
}4 O1 F1 V7 z9 |4 p4 [; Z/ Y# b
else
8 R4 I! E: I* R9 s" A4 j" D1 _5 D) w{
( M, [$ p. q. ?( [6 ^return (UF_UI_SEL_FAILURE);, h6 \; y! f6 w  h8 [
}; J& B) |* s# K9 D! [
}
; b) K* [4 t' I% Fstatic void init_camgeom_app_data
8 |. V& R4 |* g: @; ](
+ s/ \/ D. {( jUF_CAMGEOM_app_data_p_t app_data
# j$ q# V8 A  n)8 b7 C8 R: U/ I2 b
{
; C& C( `: i5 X8 t; vif (app_data)
: q% K; c+ \7 X, u8 B  o$ X6 v{1 i% f, C& l+ {. A& s5 x5 [$ E
/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */* r( n4 J6 S* G+ e( \
app_data->has_cut_stock = 0; /* Used 1 - Else 0 */
, R0 ^! _1 b8 P# Mapp_data->has_tolerances = 0 ; /* Used 1 - Else 0 */2 y1 r" R0 S- u: ?, G" u
app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */, b, |% n; n; I7 Y
app_data->has_offset = 0; /* Used 1 - Else 0 */
9 I: }% z5 w" Z* \% n, T6 Sapp_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */
; Y/ B. C, f, Vapp_data->stock = 0.033 ;
' \: {( O2 f% y. `* F, V; d3 fapp_data->cut_stock[0] = 0.2 ;
/ v& c4 f$ D! [9 Z6 Wapp_data->cut_stock[1] = 0.1 ;
6 `1 b* u# Z* w3 Japp_data->cut_stock[2] = 0.5 ;
" w. X7 @9 Z! j8 B9 f/ Happ_data->tolerances[0] = 0.003 ;4 E& h- V5 V9 E1 Z( m4 J* ?1 o
app_data->tolerances[1] = 0.003 ;+ |& l. h1 ]# B' z2 u2 I5 o- K
app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
( p5 ^- W- Y# [. N: {0 ]app_data->feedrate_value = 33.0 ;
: _9 R% X' m3 fapp_data->offset = 0.055 ;. K, C& A. z3 x. t: k) s
app_data->avoidance_type = UF_CAM_avoidance_type_warning;
: Q8 S  w' Z* B+ U}& S5 [* F, }, Q+ g0 y9 W
}

# ]  w7 }6 g: q/ C) w, j' L/ M( V
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复5

0

主题

7

回帖

41

积分

新手上路

积分
41
发表于 2014-8-5 00:57:44 来自手机 | 显示全部楼层
很好好好学习
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

0

主题

4

回帖

47

积分

新手上路

积分
47
发表于 2017-7-18 21:43:08 | 显示全部楼层
UF_CAMGEOM_append_items
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

0

主题

4

回帖

47

积分

新手上路

积分
47
发表于 2017-7-18 21:44:34 | 显示全部楼层
UF_CAMGEOM_append_items我是用C#写的,用这个函数总是报‘Method not found’错误。
/ d, y6 ?8 t/ g; {; t2 v/ ]- w有了解可能的原因的吗?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

0

主题

19

回帖

117

积分

注册会员

积分
117
发表于 2017-12-11 15:36:10 | 显示全部楼层
不错不错,正需要的东西
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

0

主题

19

回帖

117

积分

注册会员

积分
117
发表于 2017-12-11 15:49:09 | 显示全部楼层
5 ]4 C, b  ?6 T! K" K7 u' m
不错不错,正需要的东西
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了