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

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

  [复制链接]

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

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

admin 楼主

2014-6-7 10:50:25

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

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

x
( O) E- q" G3 F
0 M! f! n: z5 |) @0 W/ C
( G* V* Y0 D: ]$ W2 _3 L

) j; P7 X$ j5 n3 R

#include <stdlib.h>: v. D- r; L2 [  ^4 E0 a
#include <stdio.h>

#include <uf.h>
" w. u% g) J! o! M5 D* {#include <uf_object_types.h>! q. y: V( t  H& a3 G, y
#include <uf_ui.h>6 v% }3 R0 d: `1 ?9 v- z3 l
#include <uf_disp.h>
+ ~2 T: p! ]' n- D5 v! i3 h#include <uf_obj.h>
/ G( i8 _, ]3 R$ R! o) T/ N#include <uf_cam.h>" o' ?% W2 R) e/ Z  @! L
#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 20
3 ~* a' ~0 R( R! \" R/ }' E0 L#define EXIT_SUCCESS 0

/*#define DEBUG*/

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

static int geoption;
  v* O+ L" e' U* _( x+ l  A% R3 i$ Astatic char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何; }% ~- R& ?2 Y  r9 t# z
static char menu3[][38] = { "1) Part Geometry",9 M' u. ^5 a8 P7 T8 t- e$ W6 @
"2) Blank Geometry",3 c7 {; D3 }$ t3 i* B7 b+ e/ C( v$ g
"3) Drive Geometry",
, v7 T3 }' t1 m6 U9 q8 h( h- o"4) Cut Area Geometry",; [2 s8 ?9 Q( F- ~. _1 Z
"5) Trim Geometry",0 n/ O+ ^. f; _/ y" Z3 }
"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 )

{) t) {0 d) D- G# N) ~
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];
9 B- }- z$ U+ T8 Itag_t *objects, entity_list[MAX_CAMGEOM];- T, w7 |* S% q6 u3 C1 F/ Z% g; N
int i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";( l1 |; Q# A+ F
char *cue = "Identify Geometry - Wait for the Filter!";
9 r6 E3 W& S6 {char errorstrg[133];8 ?8 I$ H3 h& t" _6 P4 m
int response, irc;
' z$ W3 _* Y9 dtag_t eid, view;/ L5 m/ e- C% c
double cursor[3];

#ifdef DEBUG0 P( E7 G8 ^* e
printf( "Object tag passed into camgeom_ugroup is %d \n", objTag );
% w' T9 k* I- J$ T#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????( r9 ?  D; }8 |+ u& M/ @+ }/ G5 ?# g
{, Z, V" [6 h" d+ D* [& y
/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

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

if (geoption == 1 || geoption == 2 || geoption == 10 )
3 S8 [' b1 _7 H$ t0 X/ n" g5 |{
: B1 ^$ t, K( D3 |, A: jbreak;( h% J. d" S9 A8 L! p# P. P4 C$ \  S
}
) B5 F' v- A1 }& U- P8 l" Z#ifdef DEBUG
5 R* N5 K. h" C8 iprintf("\n Geometry option returns %d\n", geoption);
+ {+ [$ B: [6 g1 {$ E#endif: o! P; [4 p3 p1 v, o/ v/ O3 t
/* Allow the user to select faces or bodies. 选取面和实体*/

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

if (obj_count > 0 )
7 Q+ ]4 t& Z9 N/ f1 T  u{
; J/ N; q6 N2 G; ^2 z; N1 m3 tentity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle,
! M4 c! B7 e7 F; ]UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,- ^; l* [$ G* R/ j$ U8 S' G  T  z
&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义6 a+ E: K; s- z  Q
//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED)
. r! c' K& e4 ]. ]5 W{
; A+ a/ i9 z2 F  C& @entity_list[entity_count] = eid;
( @8 @0 n, ?. j* ]" E6 J6 I! i#ifdef DEBUG
5 n4 r* e& Y! h3 M' }; C0 O9 Sprintf(" EID number returns %d\n", eid );& H5 y8 Q# V: z, L3 r
#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),
3 Q" w* f4 }% ^! k' w9 z9 {/ g! y&err_code);

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

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;
3 R- x3 p! K& Z* {$ m}
  o3 \. H8 v- I: I4 O7 H% eelse if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
& @( a: B4 W7 X) U{
4 P1 e! w* U  u3 g, n2 K( f+ A/* Geometry selection is finished.几何体选取完成 */
4 r! U, D+ G5 A- E4 A( hbreak;6 M# U2 K1 p7 `8 D
}
  h0 w, I3 w  ~3 f0 f4 M8 x}+ G+ @% F" _( Q( {
#ifdef DEBUG  \! R, p/ {+ t8 C
printf(" Entity count this selection is %d\n",entity_count);
$ L4 h* d( Z3 D% I" ^#endif

if (entity_count > 0)
4 ^4 I2 S  ^# d4 y{
3 f2 y3 J1 n( z6 C/* UF_CAMGEOM_item_t *items;
! ^; R- a7 p' K) o/ q: Hint item_count;*/

for( i = 0; i < obj_count; i++ ), d1 A' S! C/ W! N8 r1 ]
{- k+ G6 {# A6 b0 b7 ^; S. D( R
irc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||
" O" q# W- R, Q- S" Ttype == UF_machining_geometry_grp_type)

#ifdef DEBUG
5 ]: K9 h* y2 c2 M7 U( Y4 G$ Lprintf("\n Current entity count is %d", entity_count);
# V5 q% W- F4 {) K9 G: uprintf("\n Current object count is %d", obj_count);
$ G; M+ E/ ?; Z: f/ Qprintf("\n Geometry option is %d \n", geoption );1 e- F+ f2 p. Z/ Y3 ^1 P
#endif

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

{
* @" d: J  e2 L9 MswiTCh (geoption)4 R( L8 _3 T# Q# D  j) Y
{
$ e% j# W* h- |* k2 V* `2 c6 q& icase 1:
" k# P$ a- |9 q  T3 R" [case 2:0 ]8 h1 X" w  P& d: c
case 3:& i' {; ], g" m+ K
case 4:$ A  d9 b& T" r9 @
case 5: /* Part Geometry 部件几何体*/
: c8 O& g" K% ^8 U# {- ^{% b5 V$ I5 J( j5 ]5 [* f- ]1 y
#ifdef DEBUG0 o- S1 o' Q" M. \
printf("\n Type returned is %d", type);* r* _* a! ~& s1 o2 G: E& y4 \. G
printf("\n Subtype returned is %d", subtype);  _; y' P" p' O' ~5 o  J! W' y
#endif8 {% y$ h8 ?1 F- Q# I+ p- ~: U# Z
{
2 j+ ]- H3 f+ w; {3 |' y& V$ Airc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,
) `4 G$ O4 y1 y- m+ Wentity_list, app_data_list );% w! y. N* _+ I7 F4 C$ d
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
5 U/ ~$ B; p" q" {//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。
: x  q( L0 p7 O. n}
1 ^: N" S, H1 s. h8 V7 ~$ m/ \if ( irc != 0 )% @1 f" B9 P1 Z& x5 F
{2 v* o6 l! o. G& x" E
UF_get_fail_message( irc, errorstrg );& B- }* m# r! g
printf("\n The return code is %d\n", irc);4 P2 y# O% ]/ \9 z- Y1 n+ R1 J, `
printf("\n Error code translates to %s\n", errorstrg);1 O9 g+ h3 l1 S, N1 m: M: b3 z
return objTag;) L& b$ U% }$ Z8 O0 m
}( p" [) Q1 n$ i6 y$ G" Q
break;
$ b& p; I, ]0 J* B( ^# a2 n, a}

case 6: /* Blank Geometry 空白几何体*/
) s$ O7 H+ |1 j) P) S{+ ]  d4 ~8 T7 p: K" M
#ifdef DEBUG
, l6 i# W$ ]" L1 g  ~printf("\n Type returned is %d", type);
, s5 M# J* k/ V' @printf("\n Subtype returned is %d", subtype);; V9 l) h" [" I! V1 ~) k3 ]  F% X
#endif# j, c5 V9 ?( f; Z# k7 F6 y
{5 `! }  }& v/ f% a3 S0 H, x
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,8 [/ z- D! D2 i
entity_list, app_data_list );
7 m# C" `) y9 z}
+ f! @8 |5 e! d  \if ( irc != 0 )6 V4 c9 o+ ?' |0 M
{
0 e- I6 s6 J8 |- N6 ^$ z; LUF_get_fail_message( irc, errorstrg );
; z8 f5 s3 R8 z, [$ ?* uprintf("\n The return code is %d\n", irc);
! a& l5 e' _* }& D: q  \/ Bprintf("\n Error code translates to %s\n", errorstrg);
% g6 z0 S* b( ?/ Rreturn objTag;
6 V& w+ S, q, n; ^4 |8 c! P}
& \3 w) J& C5 _* Kbreak;

}

case 7: /* Check Geometry 检查几何体 驱动*/
, h0 z: r2 ]  b% |  }1 I) p{6 k! n8 a; b8 ~
#ifdef DEBUG
4 v# j! a. ?; H1 ~6 j2 b+ Mprintf("\n Type returned is %d", type);9 m  Q0 I0 [/ Z* d; s
printf("\n Subtype returned is %d", subtype);
+ I% G' q6 N8 P1 }#endif" o; K& ^5 [& d  J, B
{+ B) K+ I! }! [1 c
irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,: R1 b9 B, K/ u3 |/ K  B5 B6 a& i
entity_list,app_data_list);
$ }: W3 C0 H. _1 O4 F  o3 l}
! h( Z# N: O6 p% k1 Lif ( irc != 0 )
7 O' N! w1 q% Z; N9 ]! f. }* h% U1 T{; y3 ]. ~$ q# |4 Q
UF_get_fail_message( irc, errorstrg );3 }9 E4 B3 f4 j  }& b
printf("\n The return code is %d\n", irc);& E$ J, `1 t3 `8 Z
printf("\n Error code translates to %s\n", errorstrg);% c1 P' J) d. L! O
return objTag;
* t# L, J7 ~: C% T$ [. q' V}% c  S+ B- Y1 r  O
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
) \4 M" `, ^; j3 C: T{0 V% A2 E; t0 g; [6 O9 P
#ifdef DEBUG' U! c6 w1 J/ w5 I
printf("\n Type returned is %d", type);- d9 {# m# d6 b/ ?
printf("\n Subtype returned is %d", subtype);5 @- g+ Z  M: C; k0 b/ r; h
#endif! T* V8 k; K' p' P
{
" u6 j1 q8 o" ~, o! V1 s7 uirc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
, L3 G% p# J. x- O4 G; \' z* }entity_list, app_data_list );
( _* `8 b% F0 |# i}
7 `) Y5 D7 H, v+ h' J$ dif ( irc != 0 )
( x9 e# B+ a( n5 w, J, D{
- Q5 q& F2 _4 m) w0 R( P3 ^; xUF_get_fail_message( irc, errorstrg );
! d7 `' g% A4 zprintf("\n The return code is %d\n", irc);
1 q* Z2 @1 l" S+ jprintf("\n Error code translates to %s\n", errorstrg);" G8 S( s3 {: J( }! R
return objTag;" ?3 Q& ^* j% V7 `, `) r" G
}8 Y" f, h0 I  X, `% Z; D
break;: U: Z' Q' Y/ l$ `; ?+ e$ j8 @
}3 P6 l" x) b/ o$ p, X9 h- q
case 9: /* Trim Geometry 修剪几何体 */! M4 l9 G) @4 K0 }4 o
{; m# _/ o3 o; |/ Z0 K; H: K; w! @
printf("This case not implemented.\n");
1 a9 @5 o' m3 v* `  L  }6 e0 }7 xbreak;
2 y6 ?) O* h' F& j4 _+ m) Z3 T* P}
  @- v% X& ~& n/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/) g3 x9 u) s1 e/ @9 l
{; e% M: r+ y1 `. d
break;
1 M0 [7 v7 v3 U" K0 |}  F. G  i& a% z/ I- N' X, R. T% Z
}0 I- R/ F. D4 D0 C7 W' }
}* o6 s$ B- N" g7 F
}1 R9 r" }3 k6 F+ B0 P+ K
}
" L: ?  H6 x& @3 J}3 f1 ]! E8 v+ V
}
: |% m0 |6 V, z; j0 q. l/* Free the Allocated Memory. 释放内存*/0 \5 E& X0 }. V* N% ]4 v
for (i=0; i<entity_count; i++)
- f: ?% o2 Z7 U& I! G- S{
- }7 ~2 X* y& w1 ?2 [/ ^UF_free (app_data_list);
& S( F. y: k- q$ I}

/* UF_free (objects);*/

return(0);
& J' f: d' U" t}3 \9 `+ f" W; X) M% Y9 y
/* Selection initialization procedure 选择初始化程序*/
1 c. |+ ~8 y0 F0 p3 i" y. e: Estatic int init_proc
5 ^0 I6 _6 n; V. x: v/ Q, r9 G(
& B2 J0 |% W$ E2 U0 }/ h- HUF_UI_selection_p_t select,//指针 pointer0 C4 [! O' c: ?; T; }8 a) w: w
void* user_data
3 h3 s" V8 O2 ]6 W)2 L0 P7 Y& E1 {3 r8 }: S4 l
{) I6 L% o  N6 [9 x
int num_triples = 3;
) f. H6 U# f% L8 Y' T: m/ L//最终指定的特征类型
* }& r- `9 g; q! W# R) SUF_UI_mask_t mask_triples[] = {
) A( B  r5 ]2 ]; }; q5 o5 B2 hUF_line_type, 0, 0,3 U3 x. W; ]+ E- a3 u! W
UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,
1 u8 g/ m2 m% j9 w$ ~) L9 }UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

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

if((UF_UI_set_sel_mask(select,
1 P7 P/ B+ I. |4 J3 o: s5 vUF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
% [; {* u- Q) i$ }8 b( P; bnum_triples, mask_triples)) == 0)//3倍 3*3=9

{& a' h2 x4 U0 y! n# I; N( y" U- @
return (UF_UI_SEL_SUCCESS);
: g7 e; O& k# n- i}
% c. J, e, x, n5 Celse! h, S5 Q+ B1 x3 Z
{
' t! {' Y/ H; ]7 \$ Rreturn (UF_UI_SEL_FAILURE);0 v; L& o8 {* o1 m8 C, s' J! N
}: H1 J9 W: Z7 v* t$ U+ v% I
}
" i6 X. K3 D* ~! b+ dstatic void init_camgeom_app_data
: b4 ?2 q1 g3 `(
4 d, ]- o" D" @# _5 U; w  a5 `( WUF_CAMGEOM_app_data_p_t app_data$ N7 Z- W0 B( v5 N
)+ h' C) q8 v* k* Y
{
2 [8 ~7 Q( p+ Y9 Oif (app_data)2 q1 J% M" K7 N7 x7 J
{/ ?: Q0 E( J6 a
/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */
- C& I8 a" t- B# a% Y" f9 Q5 qapp_data->has_cut_stock = 0; /* Used 1 - Else 0 */1 o& w' k. h. C& P
app_data->has_tolerances = 0 ; /* Used 1 - Else 0 */1 ?" _1 S9 h; m$ }6 |
app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
+ Z4 x6 b% r1 a) s  Y3 lapp_data->has_offset = 0; /* Used 1 - Else 0 */8 Z5 j) n8 j6 u% v1 |2 r% v, E
app_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */$ H$ Q! d9 M" v. V+ W( U1 k
app_data->stock = 0.033 ;
9 A3 m0 `( Q, k7 T9 l' vapp_data->cut_stock[0] = 0.2 ;
' P: f& y) Q0 F2 tapp_data->cut_stock[1] = 0.1 ;$ }7 t3 ]2 N  b- \* _
app_data->cut_stock[2] = 0.5 ;
9 |1 F4 `3 b# ^8 Yapp_data->tolerances[0] = 0.003 ;8 O. Y- ]+ i2 l4 W$ Z) ?
app_data->tolerances[1] = 0.003 ;* K- ?5 L" A8 B" d
app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
7 t9 s' s" P3 _3 oapp_data->feedrate_value = 33.0 ;
9 S* ?+ G8 x0 x( N0 @0 n; I# u/ Yapp_data->offset = 0.055 ;3 y) ]. b* R: ]/ X" P% ?
app_data->avoidance_type = UF_CAM_avoidance_type_warning;; \$ y' i& [; }# T4 z
}
# Y1 @( g8 i. T}

2 \3 o/ T3 d) N2 t5 |; S( F2 U2 ]
上海点团信息科技有限公司,承接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’错误。8 X) e' J5 P3 R- c( `
有了解可能的原因的吗?
上海点团信息科技有限公司,承接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

3 V* ^  }) D; p8 n0 W% X
不错不错,正需要的东西
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了