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

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

  [复制链接]

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

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

admin 楼主

2014-6-7 10:50:25

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

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

x

4 {5 s! G% {: q2 e( u0 B
& f: n6 T+ n' i0 v- _2 U
3 l, [( e; ?0 y+ E6 L; J1 ]0 }3 z% p) }* k8 A9 K2 \; s

#include <stdlib.h>
# l; U( V, B& ]% Y#include <stdio.h>

#include <uf.h>7 D1 r& e0 u0 A6 w( x6 _
#include <uf_object_types.h>( D' K) w1 e: M  k* ~8 X
#include <uf_ui.h>
3 }6 o% E) T' i#include <uf_disp.h>5 t: r: E6 q8 I  {$ i
#include <uf_obj.h>1 X* T' ~3 c6 M
#include <uf_cam.h>
8 E0 }( [% L7 s- G#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 20/ @9 a* f( m6 f" i: Q
#define EXIT_SUCCESS 0

/*#define DEBUG*/

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

static int geoption;2 c9 a( _6 R  U) ~% O% Z) |2 s
static char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何4 I7 E. z3 y) y8 ]" Q; T6 l
static char menu3[][38] = { "1) Part Geometry",3 {3 Q6 k: o& U1 Z% F
"2) Blank Geometry",
& B* Z2 t* n& J7 h; `: @& d1 I"3) Drive Geometry",
0 ]& _- ^6 f! R6 ^( l"4) Cut Area Geometry",( l& W7 T) D! T, G3 o
"5) Trim Geometry",
9 F% Y% T' t( Q$ N& i"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 )

{  M* c, N5 ~# g9 g# A
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];
) z! I; L, E9 E2 J7 mtag_t *objects, entity_list[MAX_CAMGEOM];
, G( ^. ~! h4 k( }int i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";
0 A6 `0 {6 k' n, Kchar *cue = "Identify Geometry - Wait for the Filter!";1 F2 r3 j5 s2 s1 H( t  z3 O9 O
char errorstrg[133];6 y. L& U* a$ t: R1 Z: k
int response, irc;
5 H; }  A- z  w, rtag_t eid, view;3 S2 o  z2 W" R2 q* \- b
double cursor[3];

#ifdef DEBUG
+ ]- B. o7 ~" S( m7 bprintf( "Object tag passed into camgeom_ugroup is %d \n", objTag );
1 x& r+ N. j' Z9 b1 u: }#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????
/ Y. d7 E: E* Z' p  u- `* \( R{1 d! n. z3 @6 H- [, i* K/ {
/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

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

if (geoption == 1 || geoption == 2 || geoption == 10 )
6 j8 P: J! S: `' D+ t# m# N{
" O5 S' ^' }* M% Sbreak;
0 g: ?" @5 q) Z}: C; Z. w0 q' X1 P& N3 W/ z- d" h6 w
#ifdef DEBUG" C! H  S( b) K3 j( C1 P7 d
printf("\n Geometry option returns %d\n", geoption);3 \) d" i$ ^! m5 d
#endif
( \+ {) W. [# }" F; b' W, `* {/* Allow the user to select faces or bodies. 选取面和实体*/

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

if (obj_count > 0 )  R1 E# K8 W; B/ \- p
{$ q$ I8 o+ G5 ]
entity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle,4 ?+ T. H: N4 b* L5 O
UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,, S# d% k9 P% L0 l
&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义& h: d) {0 ^. N- k5 s  M9 `" g6 m
//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED)
+ R. R' Q+ Y; E! T" }2 J5 `, k' J{( A: P  g# E4 ]! Y$ k
entity_list[entity_count] = eid;1 D( u4 A4 j5 p) p- z0 W
#ifdef DEBUG# i' y( q; x' B" T( O9 f
printf(" EID number returns %d\n", eid );! e$ z6 N. [/ l% q9 r9 h
#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),+ S0 @; H, q' t4 G4 F+ }6 j( N/ T* s
&err_code);

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

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;
+ H2 i7 Y" g' `6 Z: @$ q}9 l5 x* f& A6 Q! w2 n6 a# W
else if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
  q/ w0 e5 L' W8 {0 g{
6 r5 n. Y( M( X' X/* Geometry selection is finished.几何体选取完成 */; y' w$ s# a% k0 z1 z3 a
break;
% S. h+ x7 ]0 s4 K) r2 V1 J" s}
3 Y7 J' f  a( r- h: V5 r, R}
8 w* I3 K6 d* F2 L#ifdef DEBUG
$ I. Y: r- B2 yprintf(" Entity count this selection is %d\n",entity_count);
& }$ N- }/ y) k( n#endif

if (entity_count > 0)
* J1 n# ~) q+ S# v- W{
$ ~8 j6 m$ P# f5 V! w/* UF_CAMGEOM_item_t *items;. G6 d$ D: W7 G* i. S! U% u) ?
int item_count;*/

for( i = 0; i < obj_count; i++ )4 l, _4 ^7 U. y# U5 l7 c) g
{
; a% f$ M5 t+ S  j+ Birc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||
' d( Q9 z' l' Etype == UF_machining_geometry_grp_type)

#ifdef DEBUG+ t! {  F* V" P/ p& S
printf("\n Current entity count is %d", entity_count);
8 S* W; e* y1 m3 S3 |' b9 Kprintf("\n Current object count is %d", obj_count);% t* J9 ^6 ^$ K8 C- h( E0 h+ S
printf("\n Geometry option is %d \n", geoption );
/ j% l- u4 P2 n0 m# _$ D* f# r#endif

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

{: T: f% B- T8 `: Q+ ?
swiTCh (geoption)# D( l3 U& K' \
{* p- y. V) c1 K4 w9 K' j7 c
case 1:
! F& j8 \, y5 ?. h2 Ncase 2:+ i6 m- Y9 P# Q; n$ d% N! G
case 3:  W2 \8 ^( @/ |
case 4:- S# @* y; m8 ]" x: }, b# O
case 5: /* Part Geometry 部件几何体*/, y. i  f6 h* s% M5 p" Y0 L
{
6 N* g  G% G( k/ d# P! @5 Z/ B! s5 s& I% k#ifdef DEBUG
* A- }/ W- ?2 O" p) Yprintf("\n Type returned is %d", type);
7 A) w( h" f  d5 q$ c) Xprintf("\n Subtype returned is %d", subtype);
- c3 u3 ], ]- K' _#endif3 n, Z3 S; g" V" k
{$ s& J' m' c8 v8 Q3 ?: m
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,
& x, b" q8 v* c% rentity_list, app_data_list );, w+ u+ u. z4 f5 ?
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
5 O" }4 _1 ~! ^: D0 \8 b+ H- E0 N//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。
' e6 W* m8 u3 w( I3 V5 _}7 V; A2 W* c( s$ b. ?2 f- |( g
if ( irc != 0 )
3 o. i. B$ N3 {$ x. d{$ T4 E8 R  z" _6 j5 f
UF_get_fail_message( irc, errorstrg );
. v- t5 J2 t# l$ e3 r% T! Wprintf("\n The return code is %d\n", irc);1 {& w8 Y# Y+ v% [) [
printf("\n Error code translates to %s\n", errorstrg);
+ @9 T, G  X5 areturn objTag;, D! Z0 v: l( ~' _
}! q' ~  F, W' c+ U; C! E4 [
break;- A8 v' K) X1 I, L
}

case 6: /* Blank Geometry 空白几何体*/
: ]/ E- q. d( t3 A/ T! l  y9 A' F{
9 }. M0 {2 d1 [9 p: S  b5 z( P#ifdef DEBUG
. }7 X# f: U! D# s% [( v! nprintf("\n Type returned is %d", type);( U+ q# A: _, ~' z
printf("\n Subtype returned is %d", subtype);; _; L# [+ t7 ?9 R
#endif
; l. j, h$ w, ?' y  q2 V$ L+ p# \1 o{
; c; a- l; n: M+ s. L; X$ M) sirc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,
: G- }" K1 \* Uentity_list, app_data_list );1 d3 y: I) j' O0 b, p
}3 Z/ t; ]) f5 E" P6 k) }/ m
if ( irc != 0 )
- u4 }2 q- A6 k4 k8 [7 O4 M{
+ P: b; `3 p/ F1 R# d7 J- }UF_get_fail_message( irc, errorstrg );/ |. n8 a+ w9 {: a+ a
printf("\n The return code is %d\n", irc);
2 f+ h! `/ s5 C# zprintf("\n Error code translates to %s\n", errorstrg);
, n% S: ~) S9 L; Qreturn objTag;
$ t6 _0 X  ~+ E3 E}! x. L4 t  c- ]2 L
break;

}

case 7: /* Check Geometry 检查几何体 驱动*/6 V: E' |! @, b3 \  a8 c' k# Q/ d
{
$ {2 v3 `4 n: r) h5 {0 g, h#ifdef DEBUG; Q( A/ g+ O( c
printf("\n Type returned is %d", type);
' z3 ~  f  S$ x0 a+ O1 z2 {; @& g6 Z. wprintf("\n Subtype returned is %d", subtype);) W8 _' |' k, k8 k; z9 G
#endif
# w. h6 @* p/ g{
7 R/ T* t, j6 k8 y) z5 v0 y8 [irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,% Q  g6 a5 {3 A$ d" l
entity_list,app_data_list);+ Y* O! p, p" i1 s/ t9 |
}9 V; z2 Y9 m; e, {
if ( irc != 0 )
" Q: i3 B  m- K{1 O( Y  D, A% K
UF_get_fail_message( irc, errorstrg );
# m3 H2 Z% Y. S( I6 q: o, mprintf("\n The return code is %d\n", irc);
6 p) \& f3 J$ Z( d: v& F" eprintf("\n Error code translates to %s\n", errorstrg);
8 h  W' v# h! l/ k/ `* `; x, Z& u- }return objTag;
- i7 s/ ^8 G, i# ?2 @! N0 z( W}0 o4 c0 ~6 _2 y) H+ l3 O7 X
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
6 w( T) ]2 \3 Y$ M2 _& t{
& }5 T0 x; q5 y5 X. L#ifdef DEBUG) A5 @! z  R: v8 T& M; M- I+ W
printf("\n Type returned is %d", type);
. y( v% C# s, Bprintf("\n Subtype returned is %d", subtype);8 w. Q* Q. r/ Z
#endif& N2 M! F! }: _# t
{1 o$ {, d, q  b4 ~
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
  S% Q9 U" m$ P+ Eentity_list, app_data_list );5 e. H, ?+ K% f: K# d  X3 f" g6 z4 l
}
! F% J; D! G; ]8 s% m0 g7 {if ( irc != 0 )( j  G5 c# \% B. H5 ?
{
! g: e" R* k# }$ y0 r- E' k: KUF_get_fail_message( irc, errorstrg );
" C! X) Q. N  B) c. U, Aprintf("\n The return code is %d\n", irc);, k. h7 f4 S3 V+ s$ g* Y& m
printf("\n Error code translates to %s\n", errorstrg);
3 v- o2 @- h, a7 l4 k; J6 Ereturn objTag;+ b* v7 A+ w* R, u& E0 I, A
}7 }1 C1 D) w) D% e6 s. B
break;) C2 q$ d5 t) G) y! B/ I& ^  ^
}
$ a- Y! W" A, u, P, |- Zcase 9: /* Trim Geometry 修剪几何体 */
) ^. M. _3 f5 u, n& |! M{
3 P/ j9 U# X2 t( yprintf("This case not implemented.\n");9 g3 M" o/ c) k. L
break;" X) b8 V1 x4 _; U1 D
}
2 L( ^/ t3 _& A7 ?/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/
) K; u) P# L9 \: Z{; i8 ~' y2 Y3 u, z, {
break;
" q+ e' C% r1 f}
2 Q) o. w7 M/ o- C5 G2 `# ~) q3 Y0 b- k# S}
! ^" Q/ Y/ ~, s  Z) _/ E}
! `1 v2 m% G! O! x0 x0 U6 y}
) k; X6 t. \7 w1 E9 @5 o6 N4 G7 h}: h+ Q0 W- o' B7 Y' Y0 Q* }
}
- q* [; N5 s0 o% z}
0 p/ A# Q: R0 b9 J  G/* Free the Allocated Memory. 释放内存*/
# G+ k8 x( ]" t8 ]: C, hfor (i=0; i<entity_count; i++)
, p9 h4 M  Z3 {2 f; a1 M; v{* D# n5 \# _8 v- f0 Y- U
UF_free (app_data_list);" B4 D4 u* t! R9 k2 y
}

/* UF_free (objects);*/

return(0);
3 h7 Y9 L8 K+ T5 d}
( I! \0 d7 ?( b3 c/ H. }/* Selection initialization procedure 选择初始化程序*/2 V# E: c$ O" v4 b; Q6 A5 Y
static int init_proc0 b1 p! r; y5 Z5 A$ i
(
" {+ D- V" F$ y4 f. p5 z, a6 E0 t3 CUF_UI_selection_p_t select,//指针 pointer, ?1 N5 o9 p9 ?3 D6 c2 ^
void* user_data3 f; w1 W1 ~6 W  j
)4 p  R. ]/ v# {* M! G% b! Z# Z
{% D+ U, d9 \+ b( m- S3 X3 l( u8 I
int num_triples = 3;
9 `, J; ~& q! Z//最终指定的特征类型4 Z* d( h3 H% [: D3 K( U
UF_UI_mask_t mask_triples[] = {
' p& g# K( W- M/ yUF_line_type, 0, 0,
6 W6 t2 }. }) G/ ]4 v/ NUF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,# G7 R/ B2 |2 I0 {. G/ D1 T! _: C5 l! I
UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

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

if((UF_UI_set_sel_mask(select,
: q" V, U7 o- \( N2 X. q; p5 kUF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,8 ]% I3 N4 P/ [  s3 ~
num_triples, mask_triples)) == 0)//3倍 3*3=9

{7 n9 C. Z% ]: n% H
return (UF_UI_SEL_SUCCESS);6 l, _5 B/ R$ o  i
}
1 m! D3 Q5 J2 ~/ v! v+ Zelse
5 s/ \$ L; I" R3 y4 V1 n$ P! e{
7 n2 M1 \% e3 ~" k/ J( v* rreturn (UF_UI_SEL_FAILURE);# I5 Q* n$ f' h. E
}
4 R7 e4 @% T3 u) d# L6 E: }}; D3 O4 h( }7 j- M& _
static void init_camgeom_app_data: v9 V+ U9 ?+ k: s( d" x& U
(- j0 `$ f! G5 f! K
UF_CAMGEOM_app_data_p_t app_data
* w! l+ U% ?) S6 ])
, R3 T/ F. V: S7 S: J5 e; @{/ J3 h! N, v5 e, d
if (app_data)
8 b/ m  S3 s, w{
6 H  ~; }% j7 r, i/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */
! \" M$ ~" j0 x! K4 l# Kapp_data->has_cut_stock = 0; /* Used 1 - Else 0 */
( y; B4 {5 o6 h7 L/ x2 }, l# a) Zapp_data->has_tolerances = 0 ; /* Used 1 - Else 0 */4 ~: Q  _5 n, Y5 M" f; s$ q- R
app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
1 T' W" l+ b1 m2 s% t; h9 Oapp_data->has_offset = 0; /* Used 1 - Else 0 */% ~. t, P5 T. z! W
app_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */6 V, ~* D9 y4 z& B
app_data->stock = 0.033 ;/ _7 b$ ?1 f* R4 ]8 D
app_data->cut_stock[0] = 0.2 ;
/ @5 d: A7 G. \7 `$ {app_data->cut_stock[1] = 0.1 ;9 U* L* ?& W8 J; V
app_data->cut_stock[2] = 0.5 ;; w9 w7 |& c% K+ ?5 \) ~8 C' Q
app_data->tolerances[0] = 0.003 ;0 r2 \/ r# R0 [. l% U) s
app_data->tolerances[1] = 0.003 ;0 U! P3 P7 @% Q! [. j
app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
1 R! c/ C$ w& d: `; Oapp_data->feedrate_value = 33.0 ;% U, V" G( K) [* V: Z3 l/ L
app_data->offset = 0.055 ;
! ]6 f( Z& ?* T& A% ]app_data->avoidance_type = UF_CAM_avoidance_type_warning;0 E" n( H4 [3 b/ I* O
}- ]# J. J5 J0 s$ q( `* R6 P/ g
}


7 }4 ~9 E$ |+ [  ~
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 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’错误。0 i8 b$ s0 P# n
有了解可能的原因的吗?
上海点团信息科技有限公司,承接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

+ n4 R# t( b0 A5 P/ ^
不错不错,正需要的东西
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了