PLM之家PLMHome-国产软件践行者

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

  [复制链接]

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

admin 发表于 2014-6-7 10:50:25 |阅读模式

admin 楼主

2014-6-7 10:50:25

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

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

x

  p. u) g% k9 L4 l; x4 M
! h) W$ |9 k6 P% X" C. O( T6 _. b4 P/ P: z: b' W0 H( J. y0 I' }+ n! w

  {+ g: x& E' `4 T

#include <stdlib.h>
# x8 p, f  Z: z2 r#include <stdio.h>

#include <uf.h>; \) P' w8 I* E" g
#include <uf_object_types.h>; a6 \, ^! g( T* l) W% w/ I
#include <uf_ui.h>
$ j) L  B  f% C  P+ G#include <uf_disp.h>
% g) Q# ^0 K/ u#include <uf_obj.h>8 I; w5 l0 y/ x* d1 E0 t: q
#include <uf_cam.h>- c" q' K" n3 P: k
#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 20
# w6 g+ E; c+ }8 t9 Y7 f& s" t) v#define EXIT_SUCCESS 0

/*#define DEBUG*/

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

static int geoption;  l1 E. P/ A5 N) A% {; T
static char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何) q% D( K$ @' @4 O# _
static char menu3[][38] = { "1) Part Geometry"," S5 E: q" P+ W  K
"2) Blank Geometry",* z& e4 h' c( G% Z
"3) Drive Geometry",$ a, _7 B5 O, N4 O3 U3 W
"4) Cut Area Geometry",
; ~/ ]) o" y3 F  O0 r"5) Trim Geometry",3 C: L8 |, t* w
"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 )

{, @# }% G/ D4 _7 l6 \& \. y3 L
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];
8 D1 N9 O. G* {5 Y! \/ R) T$ ^) ftag_t *objects, entity_list[MAX_CAMGEOM];: g# ?' p: ~- B8 ^) U* `$ t) _1 [
int i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";
1 m6 m4 d' w9 l" V% ~  U1 o0 Bchar *cue = "Identify Geometry - Wait for the Filter!";8 t  G; R2 Z5 V8 C+ M# b
char errorstrg[133];
6 m9 |+ p1 M/ ^3 p6 ?int response, irc;
; p9 l+ ~7 s6 S$ Ctag_t eid, view;
) J* ?2 ]1 P0 rdouble cursor[3];

#ifdef DEBUG
8 q* r6 ?  o8 V' \% a8 f/ _printf( "Object tag passed into camgeom_ugroup is %d \n", objTag );
' ~$ s4 P6 ~' _' M4 x5 V3 F#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????
; I* B+ J6 {( D* h" Y" o{
" K# C9 ^4 p# x1 b2 @/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

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

if (geoption == 1 || geoption == 2 || geoption == 10 )
& A& s. b1 ]' i) w* }{
5 ?1 E/ `1 Z' C& y5 U: pbreak;
0 m3 _8 e9 }% P8 ^) j}
9 `8 ~' Q( Q: _#ifdef DEBUG6 g2 \# v! W2 l% a+ C7 i: [
printf("\n Geometry option returns %d\n", geoption);% G0 j0 b# {. b' T+ P& l
#endif: g$ Q: Z& t/ x" _- t4 M0 X
/* Allow the user to select faces or bodies. 选取面和实体*/

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

if (obj_count > 0 )
& Z2 a: b# V. T- o4 I{7 @6 d8 d6 {3 k8 T2 g% ~3 Y0 I$ e; M
entity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle,+ [; a7 d4 s7 v3 v
UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,
3 C; z% e6 o7 ~9 q& m( m3 Y&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义% I% ?# P: X  \7 T
//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED)
7 G7 @* o1 u' x4 ~5 [{5 z0 F, U& D9 F% k* z9 M
entity_list[entity_count] = eid;  w2 B1 r- R2 D& M
#ifdef DEBUG3 j. n# I) x( k$ U4 D$ \/ R- g
printf(" EID number returns %d\n", eid );  ~1 X' }- [4 t! ?% Y! P
#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),0 c% G; F# G. v- T4 C) d
&err_code);

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

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;
. u5 ~. R6 Y+ U}1 N$ M9 T* o3 n9 @
else if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
+ G5 Y' q0 \" l- S1 `  q1 \{0 m' ~- O, r, r1 P
/* Geometry selection is finished.几何体选取完成 */
) m, o5 l/ W/ y5 N+ _) t% Sbreak;. o, r' Q  S# @  U" M7 w6 z
}
; S0 W" D  h3 p! ~: L4 i}
5 h, _& o  L+ W#ifdef DEBUG7 m" {6 y6 `: e; i
printf(" Entity count this selection is %d\n",entity_count);
- D  D4 M+ V3 h. F. D& _- l. B5 j8 h#endif

if (entity_count > 0)
( J7 N# V. c: A{- r" {) Q6 h) A  |$ U- d
/* UF_CAMGEOM_item_t *items;
. x: N/ l' L2 A4 D4 l6 xint item_count;*/

for( i = 0; i < obj_count; i++ )
3 D6 q7 r5 z6 R; }+ v% V4 X{# D8 Z$ n6 A3 \- t9 s
irc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||; u/ |; [5 W, v4 i3 H3 Y
type == UF_machining_geometry_grp_type)

#ifdef DEBUG
% v, U3 ~3 i$ C  K& z; X7 T1 F3 {printf("\n Current entity count is %d", entity_count);
7 R, f# H$ c: x: @0 b: w0 h- c" Bprintf("\n Current object count is %d", obj_count);
; g& W/ p1 w' L3 b9 k2 W4 v8 nprintf("\n Geometry option is %d \n", geoption );
) S! a% \5 Q3 C8 Q$ v. ^#endif

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

{
) ^1 ]& X- d3 j! F0 t$ k! L$ K( KswiTCh (geoption)4 ^1 O3 y: s9 Y0 H
{/ q; Q7 j( F$ m, O% F- T
case 1:
$ ^( j" M2 [  Q2 @! xcase 2:& _' y1 q/ C2 Z4 z) t9 P
case 3:
: P9 I; K/ ^2 k4 e& dcase 4:
* G; X9 \7 \# f8 n! E4 X2 }case 5: /* Part Geometry 部件几何体*/
7 p5 P+ a$ m2 z4 w; o{! A8 P+ x6 B' u" v) I' _3 m& s1 E
#ifdef DEBUG+ {0 B+ S0 I7 a/ A. O# p6 i
printf("\n Type returned is %d", type);! R. @; R! w) c/ T5 v% a4 f
printf("\n Subtype returned is %d", subtype);4 g) M& M; j1 d! N+ {
#endif
% @, b! U" G2 E9 u1 m, N{
" U( {' p. D9 Y, I4 [irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,9 W5 |; w% o& x! ?% P& B
entity_list, app_data_list );
. @% r" O; O2 ?//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。* b% P. Z, |& |& g  F0 _
//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。* C1 `, B6 c. z+ U6 f
}
9 @$ d0 s' c: T8 sif ( irc != 0 )
" c4 w9 ~; I" E  a{0 R0 z; N0 |  o% u
UF_get_fail_message( irc, errorstrg );9 M4 ~. m6 r$ b5 A
printf("\n The return code is %d\n", irc);
' D6 a: {( I( v; B% p2 }printf("\n Error code translates to %s\n", errorstrg);2 j1 W8 P/ p# K* Q& O
return objTag;1 f. C- b6 U, K2 H, \: j: C
}3 b8 b- f( ?% ~
break;! Q6 F9 n; u5 h! m' g% T% m
}

case 6: /* Blank Geometry 空白几何体*/
0 d: e' {) }7 o$ p) H3 B. d, L3 b  ^{; ^8 H4 q. [& c% n3 s" g/ ^% h+ A0 F8 L
#ifdef DEBUG
  o3 g- @7 f. }4 L' ~9 @; dprintf("\n Type returned is %d", type);
; j  N0 D, J% r! {/ J/ O  ?: Pprintf("\n Subtype returned is %d", subtype);
4 k. u: h3 U% M; u/ d#endif
3 d% @4 |4 K0 r8 n0 S2 D& {{
$ j( z* D' U5 Y5 ~6 ^+ birc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,; H. L+ U8 l1 M- O: F/ `' @" o1 K
entity_list, app_data_list );! I) d9 }' ~0 L1 b6 T7 d3 y# U
}# h! m; N! L  z% o. D4 L$ D
if ( irc != 0 )% r3 q1 h) E6 F, g
{
4 p+ m5 ]1 |4 g* ?UF_get_fail_message( irc, errorstrg );! [4 v2 \; k+ R7 N6 j
printf("\n The return code is %d\n", irc);% D# N- b! x3 z
printf("\n Error code translates to %s\n", errorstrg);7 `$ F! b& }' X. I4 z
return objTag;
, m  f; f! j0 o& A}6 H% t2 X. A; I( p9 j
break;

}

case 7: /* Check Geometry 检查几何体 驱动*/$ m; z$ {0 u$ u6 l' h5 a
{4 }7 z+ s. B1 V+ ~5 i1 W
#ifdef DEBUG" i5 {& _+ G3 ]0 p6 ]( X
printf("\n Type returned is %d", type);4 u8 ~! g, w( {" R( S
printf("\n Subtype returned is %d", subtype);* N1 N% x# @) W
#endif0 @% [1 v+ l2 W/ W& Y6 D5 \
{% F% M" L; W. B* n! Q1 i: d. s
irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,+ P" ]( I$ H' z% U1 G$ S% R
entity_list,app_data_list);+ u, W5 T' T" Z/ H" b: \: ?
}
) {5 `8 p* g# ?if ( irc != 0 )
' p+ Y3 I$ X3 ^4 H/ s+ N6 D& T{
. c5 `# H5 b9 h; ]UF_get_fail_message( irc, errorstrg );
, s, _* p( n; kprintf("\n The return code is %d\n", irc);" }, L) Y, X2 _( P; \' j8 [
printf("\n Error code translates to %s\n", errorstrg);
% y7 y% L) [8 m' {return objTag;* }0 b' c6 o7 i8 M/ U6 `6 _- d: V
}, r& S$ n' K. W" t  U7 F
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
* g- t5 ^8 \8 p' u. }/ p{
' [6 ]1 u9 Q3 j5 K1 h3 u5 @* e; Q#ifdef DEBUG
. H; i- n$ M% G/ O6 C1 @printf("\n Type returned is %d", type);
  L) B  G) V$ N! c2 z" T. Zprintf("\n Subtype returned is %d", subtype);2 L9 C0 l2 T- ]3 h  ~; Z" P& _2 u
#endif
" u4 u  U6 @4 @* O9 E{3 v8 V% }; Q1 d4 z; W+ E6 r' c) p3 V
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
" c5 _% P1 f6 F, H9 y0 ]entity_list, app_data_list );
' {1 v: d% F+ q9 l}
* p+ i- h5 h) k3 q0 V3 Xif ( irc != 0 )
' S) C- b$ Y- q3 ?0 X" T{6 j/ A+ V: l9 ]2 t7 ]- P
UF_get_fail_message( irc, errorstrg );; g: I" w* {0 a: f
printf("\n The return code is %d\n", irc);
/ ^; G7 G" U, z  x9 Rprintf("\n Error code translates to %s\n", errorstrg);
& e4 l9 V4 P; Sreturn objTag;- I1 ]3 Y" p3 @2 }, ?2 c8 \
}& |8 x& g4 J2 v9 G9 B2 _) ~
break;3 |, E3 F, m! s1 p
}
* [/ l7 `/ U; Y) D! S/ Q" Zcase 9: /* Trim Geometry 修剪几何体 */
5 n9 x! i2 c- r6 ^. y% ]{6 I0 c& Z; D  O
printf("This case not implemented.\n");
% [& p" T. ]3 A; L0 ~break;
8 S( f$ M' L, u/ s% V}
6 H, ?* d  O) o2 o/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/7 ]' b, t1 q2 c7 O2 X) ]
{
* W8 U: t5 n8 c% c  r; z6 Ebreak;
7 R" y' q1 i- D+ y$ Z+ d}
6 p6 G( s3 x7 g/ r& l5 h}
" o' u* }! Z! v" {1 w/ J}: j, q! H8 e7 l" U# i) E$ x8 X
}
7 ?. Q* h3 X6 G( y8 Z- L}5 r9 J3 N- p4 z& w7 O2 P! ]
}- b; T9 v- H* J5 I' t/ W$ _
}" L5 V; h6 [5 x  P' f" T7 k
/* Free the Allocated Memory. 释放内存*/) M; P3 @: K! e6 ^
for (i=0; i<entity_count; i++)6 Z3 R% Y+ S# i( a' T/ K* A5 q
{
9 Q1 w9 ]* n0 vUF_free (app_data_list);
+ c! `' B' b' z7 x2 |4 E}

/* UF_free (objects);*/

return(0);
/ Y5 f( s- }' X7 M  B}" s3 k9 a4 w, O0 [! Q
/* Selection initialization procedure 选择初始化程序*/% M# p0 ?% q- S
static int init_proc: P) O# j7 C! T# [" w! C. _4 _2 D
(( w* b0 k6 ^% _, y! ?/ t
UF_UI_selection_p_t select,//指针 pointer
4 a4 X- k" P4 t  m- N- D9 Vvoid* user_data$ V3 I3 s( ], j$ _. |$ q
)8 ?3 Y2 \% M/ Q6 b4 ~3 N
{
  s) S9 Y3 k, _# i0 pint num_triples = 3;* f. E  y& \  x( w
//最终指定的特征类型, }: n- R9 L- `, O# P7 m9 f' s2 ?
UF_UI_mask_t mask_triples[] = {% F  U9 a3 X# J  H- v! @1 ~4 O, Z! B
UF_line_type, 0, 0,
9 W4 I+ P' T1 [* F8 ?UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE," ~  Y% m  I% d& G* Z$ I- A
UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

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

if((UF_UI_set_sel_mask(select,
; z$ s& U  q9 @) _UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
! Y$ B/ Y0 A9 {0 i+ r  anum_triples, mask_triples)) == 0)//3倍 3*3=9

{
* {1 r& b5 R! Q1 k7 H6 C1 qreturn (UF_UI_SEL_SUCCESS);% o+ T. S: _( c1 [( P
}
, O1 Y9 ^% m& X$ qelse. D+ f* }, Q* Q1 R6 J
{  a7 T! h8 `1 w5 t# O
return (UF_UI_SEL_FAILURE);2 P7 U3 c7 }6 _# v; c" R8 t
}3 u! B/ m' D0 ]" v
}2 _9 O$ h! [' N% K. Q) g3 g
static void init_camgeom_app_data
6 T+ G" H6 Q3 }7 t7 g(+ i7 p4 X, S- {! S2 n0 n9 B
UF_CAMGEOM_app_data_p_t app_data' \, [8 j) r" ~2 r
)
6 E6 ]3 s* o7 [, n0 y' h+ e" E{
4 B4 t) a  Y6 f( B. |9 Rif (app_data)* H5 }% U1 b$ i4 m, n! i1 w3 N
{7 ?& K5 C& L- z6 K* [( ~; f
/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */% J( v; m% K* U! W2 v  l, c
app_data->has_cut_stock = 0; /* Used 1 - Else 0 */6 n5 f' y, r; k
app_data->has_tolerances = 0 ; /* Used 1 - Else 0 */0 U5 l* ~1 C4 Z, p, {0 h
app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
4 i3 w. J( L, y3 Dapp_data->has_offset = 0; /* Used 1 - Else 0 */
' R; S, J1 c2 E0 j8 mapp_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */
; i5 [; c+ B) ~4 Z  F: [/ mapp_data->stock = 0.033 ;& s# u9 @) _# R' V/ h) B7 @
app_data->cut_stock[0] = 0.2 ;5 s6 I, I2 q1 D9 I) r$ ?  b5 k
app_data->cut_stock[1] = 0.1 ;+ `- v4 D: `  a0 \' |
app_data->cut_stock[2] = 0.5 ;) e7 I# m. k( r
app_data->tolerances[0] = 0.003 ;- ~1 g8 i8 ]4 k
app_data->tolerances[1] = 0.003 ;& o1 D7 R: {0 i6 c1 C
app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;4 e! w, z4 ^) U; k9 I- K
app_data->feedrate_value = 33.0 ;" D- z8 }! i  P, N; L, `7 `
app_data->offset = 0.055 ;
* g+ a* t8 h) e4 z1 Mapp_data->avoidance_type = UF_CAM_avoidance_type_warning;
- Q: ]# D* V* R) {% l}
9 D0 A; ]3 n9 e( r6 }  \}

7 ?  H* r! M8 e
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复5

wskgumnm 发表于 2014-8-5 00:57:44 PLM之家手机频道

wskgumnm 沙发

2014-8-5 00:57:44

很好好好学习
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

Jocelyn 发表于 2017-7-18 21:43:08

Jocelyn 板凳

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.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

Jocelyn 发表于 2017-7-18 21:44:34

Jocelyn 地板

2017-7-18 21:44:34

UF_CAMGEOM_append_items我是用C#写的,用这个函数总是报‘Method not found’错误。
' j0 h2 z# `1 p9 D' O有了解可能的原因的吗?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

至简天成 发表于 2017-12-11 15:36:10

至简天成 5#

2017-12-11 15:36:10

不错不错,正需要的东西
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

至简天成 发表于 2017-12-11 15:49:09

至简天成 6#

2017-12-11 15:49:09

9 U* S& A. J# O5 B( ~1 k% J8 G, F! O
不错不错,正需要的东西
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了