PLM之家PLMHome-工业软件与AI结合践行者

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

  [复制链接]

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

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

admin 楼主

2014-6-7 10:50:25

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

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

x
) I/ E1 ^! ^- v! U2 f) i
+ w5 q, u! S' Z- }+ _* J3 Z# b

1 w: g2 o; N6 @# E: T1 O3 s( U" ^  v6 ?% j( L

#include <stdlib.h>6 e' i2 c: A8 Q6 v; K/ P; J/ A# @
#include <stdio.h>

#include <uf.h>7 h& a6 b2 E, U0 T
#include <uf_object_types.h>7 r* @  j) x7 I+ l+ g2 W6 W
#include <uf_ui.h>: L4 `0 v5 k! m+ A
#include <uf_disp.h>
9 U4 v7 w; K3 @9 D( G8 u# a#include <uf_obj.h>
( B1 r8 f: f+ N5 O/ N#include <uf_cam.h>3 t' |' X- w7 \! A# i
#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 201 `, o3 O# `! m, V0 y" g3 v' s! e
#define EXIT_SUCCESS 0

/*#define DEBUG*/

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

static int geoption;1 H, t+ O3 q( K, F
static char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何
! n" |1 L& m; P( Zstatic char menu3[][38] = { "1) Part Geometry",# q0 ?$ c- _2 [8 Y8 _5 w+ E$ F
"2) Blank Geometry",- E; N4 D, \# ^5 f, d3 w* B/ R6 Q3 ^
"3) Drive Geometry",8 o# Z6 }) ~3 _- J% ^7 i* o
"4) Cut Area Geometry",
+ [! L9 R: @8 _2 C4 s9 k"5) Trim Geometry",
! h$ m8 [) S' I: [. j3 ?5 \"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 )

{+ z# \1 U* C3 H' M1 N/ e
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];- Z7 W; l+ H4 m" M' ~
tag_t *objects, entity_list[MAX_CAMGEOM];
$ L9 O: c4 a) ~( x; wint i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";
8 r; n+ @* y7 V, \4 xchar *cue = "Identify Geometry - Wait for the Filter!";5 X" `$ E/ ~  @+ J3 @" E
char errorstrg[133];! A. U5 E9 r6 j
int response, irc;4 \/ P1 p4 z2 }# i- m& e
tag_t eid, view;
$ S7 `" y$ P8 Edouble cursor[3];

#ifdef DEBUG9 A, q9 S7 F7 n" X8 U- d
printf( "Object tag passed into camgeom_ugroup is %d \n", objTag );
6 y& u& P; n9 l8 \5 b& A#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????
8 C6 v# v" T; T$ F{. c+ q5 w8 \5 J" I" w
/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

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

if (geoption == 1 || geoption == 2 || geoption == 10 )' H: D$ B  e5 I5 Z: M+ Y
{: j8 l( q% \0 {/ u3 \! a
break;
2 E1 n( V4 k6 f- V9 ^1 }+ r% g* Y}* z$ s  d! O( L( J" I0 N
#ifdef DEBUG' E/ H4 `: L/ m4 d: A' ~% K
printf("\n Geometry option returns %d\n", geoption);
5 s* j. Y) `+ [* J6 _5 B# _#endif! e. Y3 l: K4 |0 U2 ^
/* Allow the user to select faces or bodies. 选取面和实体*/

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

if (obj_count > 0 )
2 ?5 U2 }  {3 H{
  u" A4 d3 I! ~7 A$ fentity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle," c1 m% K' S3 J1 [' I0 P( T+ r
UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,
/ `5 P3 O5 _9 e% ?&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义
+ M5 {8 q5 \& g, {//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED)# }. T2 A( a# u5 g7 R" p9 D
{. B" y( h5 Q0 {
entity_list[entity_count] = eid;; w9 `- p9 ]4 M- `9 l. L( V2 j2 f! f! B
#ifdef DEBUG% A, ~: |! O4 g$ f  e
printf(" EID number returns %d\n", eid );, u# ]) h5 L) d; T* L$ r5 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),
8 k& c, c  q* v" ~% k$ |3 E&err_code);

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

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;% O+ O3 Z: M+ o+ x# U% Z) g& }3 n( H6 t
}
. J+ ?6 _; e$ ^; P1 f; o( yelse if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
/ w. R! P6 g9 ^# z+ H8 }* |  f{) H  F6 ~6 x- ]% W/ `) G
/* Geometry selection is finished.几何体选取完成 */
% k0 @+ y$ K  E3 B0 U# Sbreak;
  H3 d! U5 s- D& c# S2 B; ]+ Y}
5 L% G6 W3 f2 y+ f4 r/ B* X& Y}9 H! Z4 l& }/ y& E+ q
#ifdef DEBUG+ W% N! ~) m7 U! P/ w9 u
printf(" Entity count this selection is %d\n",entity_count);
) G% `" _0 @3 m5 @: U8 J#endif

if (entity_count > 0)
3 X" T) U- D9 H' h8 l/ }{
  z. L) R& p+ I( T& C. `% ]2 Z/* UF_CAMGEOM_item_t *items;
3 H$ U* V$ A7 N+ Z1 W, f# lint item_count;*/

for( i = 0; i < obj_count; i++ )( l! Q4 T* Z( t5 O: E% z& d* v; C
{* }5 g( X) g$ D7 q7 ~6 u! }; ?
irc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||
5 p' u9 ?  [3 y) d7 Btype == UF_machining_geometry_grp_type)

#ifdef DEBUG5 H# o/ m5 C* x' z0 T5 ?
printf("\n Current entity count is %d", entity_count);
% J- C# ~& p' }( jprintf("\n Current object count is %d", obj_count);
0 d0 g2 U4 K) \printf("\n Geometry option is %d \n", geoption );
5 X& Q5 s7 y/ E#endif

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

{
: J5 l; i' g) X% Z0 B3 ?- ^" CswiTCh (geoption)
2 }5 h+ R+ }7 W6 l{
8 M1 [& \% `7 P- ?case 1:+ n5 U( @- M6 T* s
case 2:
1 h" i# ~: O" M5 R% b) ~case 3:
2 G% E0 t( d' _, }& [# q6 f) pcase 4:! R, t* H7 k( M* `# q( b0 z: T6 P
case 5: /* Part Geometry 部件几何体*/
# b, H( G! L. {7 N+ ^" u{
1 i. d  o& {* C#ifdef DEBUG$ V' S' s) Q* P! L
printf("\n Type returned is %d", type);
3 i/ E5 y9 }2 H! O3 ^" n1 H9 j( sprintf("\n Subtype returned is %d", subtype);8 t% l% b' o3 K
#endif
( U  b  u( F% o6 K' v3 p{1 y6 r6 ^  ?/ S: {7 c9 }8 n
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,
) @" S- q& Z# C# centity_list, app_data_list );% H; J- B: B! N4 ?- b/ x/ n( }
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
7 p4 ]( B) u7 q) u2 A//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。8 ^* @/ S/ H' v+ J" Q6 R
}4 Z; c$ P+ X9 d7 x5 A8 q
if ( irc != 0 )
* |/ J( k4 H. @) l& N0 ]{3 _1 ~" t; @. x! m# e3 G9 L7 c
UF_get_fail_message( irc, errorstrg );* L8 Y9 O& A% k' T! h. Z. C: @
printf("\n The return code is %d\n", irc);
. b9 |, c9 @. P: z; p: v! P9 cprintf("\n Error code translates to %s\n", errorstrg);2 u% \. L. J! ?* Z5 ^+ T
return objTag;3 L  }8 v1 m2 t# y  ~" f
}
2 E( Z  b/ l) P, p7 bbreak;8 x6 P% ?6 V* o! G: B! R
}

case 6: /* Blank Geometry 空白几何体*/5 K  p* ~* F- |, _$ c9 L0 ~
{
. O5 y+ B- \) O1 _) O#ifdef DEBUG: T) |7 ?! U/ q! m
printf("\n Type returned is %d", type);( t/ x+ H9 R( q' H* \
printf("\n Subtype returned is %d", subtype);: S( k( u" D* }2 j, |
#endif# E. p! S) M7 Q7 }0 P, f! \4 L
{
. d6 l# d( A$ E- p. lirc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,- c+ u: `+ Y' u; m9 S
entity_list, app_data_list );
; A! i. q2 i6 W# P, J}
: \9 `9 A/ Q: _8 |; ~4 L5 Lif ( irc != 0 )) W: d6 \& ?3 j, U. f
{
- A/ e1 X5 W# b8 jUF_get_fail_message( irc, errorstrg );5 l% R' Y" C0 h# w8 h1 j
printf("\n The return code is %d\n", irc);% T/ i7 h; Y5 I1 M: O
printf("\n Error code translates to %s\n", errorstrg);
: w2 c8 \/ t& m( R7 D1 L# |return objTag;
3 i2 w1 M7 y- y% E4 u  S}* ?0 u' D  m+ J: N& Q* t
break;

}

case 7: /* Check Geometry 检查几何体 驱动*/
) l7 @4 o: J7 o{
, [% p% B0 `3 ~#ifdef DEBUG
  w5 z. W  G2 C" m" T! S6 ?4 ~printf("\n Type returned is %d", type);7 z$ d% ~: V+ ]7 Q$ h. b( h
printf("\n Subtype returned is %d", subtype);
; K7 i5 n- p/ E! [3 t3 l, ?2 R#endif$ X1 o7 [& o  j
{$ \/ G! I8 Z1 N3 \# j* L0 t' H
irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,
3 X- T! b- x. R* }$ Centity_list,app_data_list);4 B% [) q# y) e9 t
}
7 `9 W+ A! X5 w' V" n5 ?" Eif ( irc != 0 )
5 y3 |: q2 M: h0 O; u4 }2 P4 ?# n- D{
# W9 @" ^' n. Z1 a; E7 I+ |( xUF_get_fail_message( irc, errorstrg );, s# d3 ^9 w( w7 ]$ n2 c. |
printf("\n The return code is %d\n", irc);
9 N( e. L  n5 u  h- W3 Q, Nprintf("\n Error code translates to %s\n", errorstrg);1 U  s+ n$ F6 I& p0 e. C$ s; k
return objTag;
, Q7 [  y/ |; n8 `4 t}( x  R. w9 D( q9 k! S8 ?6 B
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
' `) ^7 h5 ~! X9 d7 o( w/ o{
: d8 E. f" j; X2 j, i2 A' c* C#ifdef DEBUG7 F" B+ c7 K/ N* U5 P
printf("\n Type returned is %d", type);
; L7 ]; ]( f* w; cprintf("\n Subtype returned is %d", subtype);+ @6 H" {+ Y; I- ?# c' K6 [
#endif* T: P; U) i! i5 L' P  |
{/ d) d0 E6 W/ v
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,/ }( r1 Z3 Z9 C, Q9 f5 C; P6 [
entity_list, app_data_list );5 @, w) F8 D; ?4 g& S
}/ ?. P% i2 F  y( i
if ( irc != 0 ): j$ J* y0 U) R5 v! i
{0 K- y9 ~3 v4 o7 o/ f
UF_get_fail_message( irc, errorstrg );# j  s0 P2 ]0 x; j. C
printf("\n The return code is %d\n", irc);
' J: i( V# E; Z+ y- K4 x# I6 I/ Oprintf("\n Error code translates to %s\n", errorstrg);! K: U# c" r' Y" M6 x3 v, A3 H
return objTag;
' e, G' r* ?$ T}, [* n0 e# w. l5 g' O1 m" k6 M/ }  o
break;
7 D9 m# \' f2 _; G; ^}$ |* R- C6 S: _, q8 r
case 9: /* Trim Geometry 修剪几何体 *// s: O8 L6 I' P# ?& M7 a! D7 c' j
{# @+ f  W( F! k4 ]
printf("This case not implemented.\n");
. f- i3 ]% I  s5 `, Z) ibreak;" _2 d( m2 g: E- V8 q) t+ q) w
}, U4 `1 I9 [: w; S  E
/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/
+ X. {9 M1 B: J* @1 E$ \' S{& ?. {* w, Y0 L! C/ ^' c6 [' T
break;5 f  k+ t) s( {7 m5 l- E
}
  X# d) r( `4 C; L% @}
9 D9 g' y; P* L+ ~5 F8 H, ~6 `}
/ e* q* T5 h" h/ j7 A& `$ b% J. X# }}+ R3 w( D; L+ `, ?/ I; O
}/ J/ w& D; k, S3 K# F: e3 |- j3 J
}, ^- \4 U" a" ]4 |3 V
}
0 f' q% `8 {& T. l, T' t/* Free the Allocated Memory. 释放内存*/2 a8 ~9 t! q" H  E1 w
for (i=0; i<entity_count; i++)
; O+ F2 B0 _) G+ I  v3 u{9 p% X0 W1 I3 v2 X
UF_free (app_data_list);
0 `7 ?7 x" l4 s5 T; @8 D4 F}

/* UF_free (objects);*/

return(0);
3 b9 \4 j4 S! l' m- `# s% N}
- z3 y( _  @! ?0 {/* Selection initialization procedure 选择初始化程序*/7 p7 x* d5 L" Z5 f# v
static int init_proc
7 @9 |3 ^4 b/ I& M; m" Z(
, y# Y# l2 h5 R' c, h2 UUF_UI_selection_p_t select,//指针 pointer
# c9 C- o+ _0 s* M6 ~void* user_data
9 i9 y9 M& I4 l)! }0 K5 S2 R3 ]' R
{
" Y$ ~; E' |6 J( a; \# G. Iint num_triples = 3;  v$ D1 R* ?3 u( C6 H
//最终指定的特征类型9 T  n5 a) G$ j* q
UF_UI_mask_t mask_triples[] = {
5 P7 M& i% @. Q  \' N; U$ G8 O! yUF_line_type, 0, 0,
7 x& ^. z- }' C) {UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,
5 [/ }$ J" a9 ?- lUF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

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

if((UF_UI_set_sel_mask(select,/ U" y- X% n3 m! }, I* r* `9 z8 k5 w& u
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,  K: G; t3 |. k. b2 R1 q+ {: M
num_triples, mask_triples)) == 0)//3倍 3*3=9

{6 q$ ]; {1 b. g: Q; V
return (UF_UI_SEL_SUCCESS);
  S) H& _1 G6 p* r0 F& N/ L}
# C0 W  h# ~) D2 d8 belse7 F) r) M% b9 H4 ^
{
' ]  _* ~: u, b! P( H% Ereturn (UF_UI_SEL_FAILURE);% L2 c$ R  c# e1 T3 V! n0 x
}
2 U7 ~( c  h& t% V: V0 l. u}( j: {& ?% E. y' p
static void init_camgeom_app_data2 {7 k2 Q4 \6 L
(, \; ^+ q- f2 R  l. L% ~2 \8 Y# S$ g
UF_CAMGEOM_app_data_p_t app_data1 t1 V) o1 c% [( ^* K
)
$ z' U8 x$ T5 I{
* g. q3 u+ Y% G! I8 {' `) W  wif (app_data)# r' m, h1 P7 {+ `# T; S/ d
{: C  U" @( h8 e
/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */1 x! q$ M% W# b" S- k9 _
app_data->has_cut_stock = 0; /* Used 1 - Else 0 */& [8 y$ _  v6 Y- K" F
app_data->has_tolerances = 0 ; /* Used 1 - Else 0 */
- i, B' c7 y2 P& S- R8 _app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
( `3 d9 _6 s3 Iapp_data->has_offset = 0; /* Used 1 - Else 0 */
( `$ O* S2 [3 U1 F: [( happ_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */' f% t5 \. M& m
app_data->stock = 0.033 ;
  X" W! Y+ n- F) t, [+ Tapp_data->cut_stock[0] = 0.2 ;
2 h8 U2 W1 a* {, @  x: Papp_data->cut_stock[1] = 0.1 ;
! o% e2 m2 \9 e4 f8 Iapp_data->cut_stock[2] = 0.5 ;
% U: L& l% s7 t" japp_data->tolerances[0] = 0.003 ;
# d2 \& a9 U7 K! e4 p: B9 capp_data->tolerances[1] = 0.003 ;
5 {) ^% Z7 q6 r, x- Z0 V& N' bapp_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;' V# h" h0 b* N% ~9 a8 E
app_data->feedrate_value = 33.0 ;: W' E+ ?. {9 ?  \. _7 `2 q" k6 ~
app_data->offset = 0.055 ;
* f+ ?- U3 Z0 z8 b& g, lapp_data->avoidance_type = UF_CAM_avoidance_type_warning;# S% M$ r% P, _. {6 b
}
' f8 x9 [4 y4 ~9 D}


$ W3 Z- N7 j) Q! v/ M
上海点团信息科技有限公司,承接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’错误。
+ A7 I) n7 Y# k( y6 d5 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


) f& z8 w/ O3 O8 f% l5 s# D9 H! r" b* e不错不错,正需要的东西
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了