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

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

  [复制链接]

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

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

admin 楼主

2014-6-7 10:50:25

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

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

x
# @7 \( Z- r& K# ?$ ~0 y

9 B) K" s  j/ C) j# t3 K2 R0 e1 u( e) Q

2 n6 z5 U: A/ O4 o$ V

#include <stdlib.h>' c. V+ d1 ]$ x- `( ]& p
#include <stdio.h>

#include <uf.h>, a7 S# Q- W. |: S
#include <uf_object_types.h>
% U7 F  N, B. f; c#include <uf_ui.h>. R! S! n8 V: m( L0 J" z
#include <uf_disp.h>
2 ^9 V) y4 H0 m6 ?#include <uf_obj.h>
. t. c) W" E8 H; M4 ~#include <uf_cam.h>
: b9 n* K6 w- |" B/ s, q" p#include <uf_camgeom.h>

#include <ufd_camgeom_UGroup.h>

#define MAX_CAMGEOM 20( c9 a+ q, ~" \9 h) Z
#define EXIT_SUCCESS 0

/*#define DEBUG*/

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

static int geoption;; S2 c8 M9 s* Y1 }, L8 p7 y) M
static char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何! f5 N/ f, C6 L2 Z' z/ ^
static char menu3[][38] = { "1) Part Geometry",+ g: O* y1 c: L9 P$ Z) c" @
"2) Blank Geometry",( ~. |7 b; N/ [- g$ v
"3) Drive Geometry",
0 G/ ^) H0 {: S2 t. [5 C"4) Cut Area Geometry",) E3 v9 @% J! z; W
"5) Trim Geometry",
1 |4 h. d- U0 c( U8 T, i* ?9 B) q"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 )

{' X( y* T. |* {8 `' l
UF_CAMGEOM_app_data_p_t app_data_list[MAX_CAMGEOM];7 d' R( _- w* ^7 S$ A( S; u3 w
tag_t *objects, entity_list[MAX_CAMGEOM];" O: ~( Z5 @/ y5 D/ y
int i, entity_count, object_count, err_code, type, subtype;

char atitle[] = "Geometry Selection.";
# R9 I# `& q$ fchar *cue = "Identify Geometry - Wait for the Filter!";
; B+ L) W. f1 w5 O) ]1 M4 [char errorstrg[133];+ f. X* |& E  T, @: c6 y2 l& Y2 i
int response, irc;/ L% w' l% i0 q
tag_t eid, view;
8 C- ^5 ]9 t7 {double cursor[3];

#ifdef DEBUG
0 a. b# d- h0 L/ a; Oprintf( "Object tag passed into camgeom_ugroup is %d \n", objTag );& O+ F- J$ E/ [. r
#endif

geoption = 0;

while ( geoption < 10 )//为什么是10呢????
/ |  B  l1 d; _, @/ h{
1 Y  v) {4 n& v, A+ [; G/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/

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

if (geoption == 1 || geoption == 2 || geoption == 10 )1 q' j3 |, ?8 T3 q
{
- n  L8 A0 i: y9 vbreak;  Z0 R7 a3 q8 @1 |. D1 e) L" w$ P
}
+ d4 M% }: R5 U) l2 R' C#ifdef DEBUG
$ S% R, o4 `6 ~* n- l3 u* Aprintf("\n Geometry option returns %d\n", geoption);
/ U: o8 a' V6 b( d4 |#endif
) o* _1 Z5 W7 u' [/* Allow the user to select faces or bodies. 选取面和实体*/

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

if (obj_count > 0 )5 E* j7 g( z  C- P" y
{. q& k; R  ~& F  `
entity_count = 0;

while (TRUE)

{

UF_UI_select_with_single_dialog(cue,atitle,
4 E5 g* B$ O  a0 M2 ]UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,
7 p: C: l6 V' L2 \9 P&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义0 z" p5 Z& f: A$ e* I
//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标

if (response == UF_UI_OBJECT_SELECTED); B9 h& Z0 ]2 o6 D% B3 `* @8 s
{( R2 @/ p9 |5 A1 [1 G/ y' s3 D
entity_list[entity_count] = eid;
& p- q3 c4 V, H2 K, X7 A+ u+ B#ifdef DEBUG
, c4 J, V5 ~! y  J5 J. zprintf(" EID number returns %d\n", eid );
* J7 g, z5 x3 @" u6 n" D6 j#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),
1 K7 M: f/ Q  u- K&err_code);

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

init_camgeom_app_data(app_data_list[entity_count]);

entity_count++;
3 L. S1 P0 A8 W4 q  u+ @& W2 t* F$ U}1 R, d; N* A; C% @# g( ]) t3 Y
else if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
: r0 D0 u) c+ D( z{
0 x& `3 ?6 M( S/* Geometry selection is finished.几何体选取完成 */$ z: w6 `  d2 E. n/ [* b+ L$ g0 G7 e
break;
0 i" r) [' k& b6 u}. w; T5 V1 _8 V" S8 y
}8 O1 |; F7 R2 N7 Z
#ifdef DEBUG
* ?4 P, J) }5 E2 ~: fprintf(" Entity count this selection is %d\n",entity_count);
1 i$ v1 H$ y! q#endif

if (entity_count > 0)
- R: {$ X* [! |, b  S1 J, a{
/ g8 a3 L2 L" J- }$ \7 M, \, q/* UF_CAMGEOM_item_t *items;, y! u! I" y% L; i+ B+ q  [
int item_count;*/

for( i = 0; i < obj_count; i++ )
8 `" a, A9 Q5 H" R' h( P{
5 M  a7 A  t$ r  C" nirc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值

if( type == UF_machining_operation_type ||, l- d+ K% q6 }
type == UF_machining_geometry_grp_type)

#ifdef DEBUG6 J/ F" ~4 J% r6 x+ A. ]& Q2 B( \9 j) n/ Q
printf("\n Current entity count is %d", entity_count);. ~% `4 l8 L0 Y5 V5 d+ u
printf("\n Current object count is %d", obj_count);( v2 i. J) @4 d- z# E. b
printf("\n Geometry option is %d \n", geoption );
# y; ~5 G* j" r) e- p#endif

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

{& v# a# }( l3 a, R5 \% t* r6 c
swiTCh (geoption)# d* c4 Y; ?! N2 a7 G% A5 R
{
- n/ \4 U2 q2 W+ hcase 1:8 r* S4 j/ ~8 {# ~5 k
case 2:
$ O: {. V9 U0 i6 ncase 3:
# w$ C9 \6 n. v( z" j) Gcase 4:
. c! Z! s& N7 D; z1 O' Ccase 5: /* Part Geometry 部件几何体*/
* w! t1 @9 U! c0 j{( t$ w( n8 m, a' r6 P9 W- N
#ifdef DEBUG6 N1 O- y7 Z2 W
printf("\n Type returned is %d", type);0 Q6 h# N% u0 M- }" y+ v5 _( O& w' h
printf("\n Subtype returned is %d", subtype);
2 Z+ a3 l8 g- f& a1 F8 d#endif
3 Y. G( M0 M/ v& F/ r9 c% a3 [{3 \) x3 O; A% N5 C
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,
! l6 s% H( ?3 f8 Nentity_list, app_data_list );: B& k( D; d7 }, n& M  R! a
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
& a1 E" }$ _) A1 f9 j; J% T/ W* ^! d//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。
0 y5 O6 ^- @7 i6 f& p3 v. u}7 b4 T7 P* A- K5 P1 _
if ( irc != 0 )
# C3 l6 E2 B5 i( L/ V* F{
% W, u7 H( H. K$ N( ^/ N' ^3 tUF_get_fail_message( irc, errorstrg );
+ Q" Q" ?" X' z7 _+ i- a6 `printf("\n The return code is %d\n", irc);7 O0 \0 M4 Q) H1 C' p
printf("\n Error code translates to %s\n", errorstrg);
( e- l% x2 w& a& m& k& V, |return objTag;
6 [) [. \; y1 A. i1 f) @' j}. y, a1 ^3 l2 d" L
break;/ g/ n! J. f6 N& |5 w2 I
}

case 6: /* Blank Geometry 空白几何体*/
/ g- D6 ^0 B" ?4 |' |. j0 P{: s, l8 `( O/ \: W  O  A8 e
#ifdef DEBUG
" U+ I# N; k8 q2 lprintf("\n Type returned is %d", type);! r' Z, Q1 }- }" a3 y
printf("\n Subtype returned is %d", subtype);% s$ L. b8 u: `: ~
#endif
! s( S, W  a  X; y5 [( l. _: N{3 Y- b/ q; w7 g. ]9 q7 ]" C
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,% P. H- T! d% T+ I. ]8 @
entity_list, app_data_list );1 i# q1 o1 y4 x  I8 j
}* D  ~3 z+ N/ ^, u  o4 _) Z
if ( irc != 0 )" Z) J' b8 a( v! D; D
{  P. K% U) X1 i- i/ s; s
UF_get_fail_message( irc, errorstrg );1 L# E: K; Y( s( Z' e# l& }$ H
printf("\n The return code is %d\n", irc);
6 D% g, I4 B  w7 J; ~# Gprintf("\n Error code translates to %s\n", errorstrg);
8 G& r# A2 @8 q: c7 \9 `: R6 w9 d: freturn objTag;" T0 `5 q9 O4 G
}6 T8 D9 p' c# y. B* U; }
break;

}

case 7: /* Check Geometry 检查几何体 驱动*/- `- u. I9 q' N  G; N
{  c: T8 H; i: G
#ifdef DEBUG
5 _) a. [4 p: e/ c  fprintf("\n Type returned is %d", type);
. ]0 R1 ]) U0 B0 h% d# jprintf("\n Subtype returned is %d", subtype);
% S# K& V5 o; \#endif5 P! y3 }! Z# ?7 C
{
2 m& C6 P7 }0 w$ girc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,
% V. ~, F: }$ Ventity_list,app_data_list);
# a4 i3 Z/ g4 G- T$ p5 S}
/ N. }! F; W/ |! D, C! uif ( irc != 0 )" Z; t0 G1 K/ O7 a. I+ y$ z
{
8 |$ J) B8 o3 ZUF_get_fail_message( irc, errorstrg );
3 E" W( [- T5 o( w+ @& J8 Jprintf("\n The return code is %d\n", irc);
. n/ H: a2 }4 F2 ]5 B+ w+ W9 tprintf("\n Error code translates to %s\n", errorstrg);. v! K0 g! E- \( _+ _4 ?' H
return objTag;% L7 {! s* X+ ^, w, H
}! \. ^, Q* W2 E
break;

}

case 8: /* Cut Area Geometry 切削区域几何体*/
4 }3 B: i# l) N6 g7 X{9 |" p& p' J! U
#ifdef DEBUG+ X6 i9 l) J, n* a
printf("\n Type returned is %d", type);
% Z$ \1 t; q9 s# }" O" Zprintf("\n Subtype returned is %d", subtype);
1 f% F7 P& k3 w. v#endif
. e$ D+ E6 [2 I# R* g! U{
" T9 U* w; u2 C3 b2 E! T! x3 Circ = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
/ S7 t; L$ ]9 F& n; N- aentity_list, app_data_list );5 L6 |8 E; Q4 \* q/ E; V
}+ M" [# {( U  {5 v! O5 p
if ( irc != 0 )* f6 a4 h# m2 o' p- S! S( K
{
0 h+ i2 v7 ~4 W6 f, D5 ^% R; cUF_get_fail_message( irc, errorstrg );3 h  I5 y! V  N! t
printf("\n The return code is %d\n", irc);
9 [: ~/ W) ]8 a* d  Q2 D# W+ @printf("\n Error code translates to %s\n", errorstrg);* g; z# h+ y, D/ p" b! {& U) v( |
return objTag;
6 u; @' ]) S3 g" v- D4 n}
; v: t& j/ L: _# B" @/ Lbreak;" j# h8 C/ E/ V6 J
}3 o, T- K2 m+ Y" [- s
case 9: /* Trim Geometry 修剪几何体 */+ C) a/ `, x  o7 I' B
{
: [( i; Z& d7 x' Dprintf("This case not implemented.\n");) W8 m- c# p0 q6 c
break;
4 t; e0 [1 |) ^- k7 o}
" n. I9 ^0 i9 P( _/*Drive Geometry 驱动几何体*/

default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/# A" U5 I0 `6 \
{0 x% J- @# k" E% G8 n6 t& H0 f
break;
8 d2 l* ~7 q! f# ^3 r}# o% D* a$ T8 a3 U  q
}4 g9 P$ f1 G, l1 w6 {. N1 m. X+ S
}
  J& o1 @8 v( U% p  M, A7 ^}8 C: s& U, T/ h4 \" [0 v) u
}
( h1 c. v: Y( T9 _" @}  @1 x4 O+ d8 n
}2 l4 N) B" H& }' [( l
/* Free the Allocated Memory. 释放内存*/. F# A- v8 c  K9 c' {" c
for (i=0; i<entity_count; i++)
# r7 ?7 |2 z1 r8 T{) n6 e* k$ M9 W- y% _  {* w
UF_free (app_data_list);1 H' @$ E1 l' G$ v9 w
}

/* UF_free (objects);*/

return(0);/ \, E) l0 r' L! v) T, V6 z
}; u. d! r# P) |8 o3 U( D  G! t3 v% `
/* Selection initialization procedure 选择初始化程序*/' n  @  o+ m) k# E# U0 G
static int init_proc/ @* p; |. ]( E# c
(! O% W7 a5 T3 e+ U: ?4 g
UF_UI_selection_p_t select,//指针 pointer* _3 R! r5 c) h8 S
void* user_data) I8 f1 n, L; x- R3 r; s, l! S
)
  b: K5 {# @' ?2 z3 Y7 k" l9 B{0 h; d6 x- u, ~% q& l8 m6 h
int num_triples = 3;* J# O. g$ `' x( j* @$ B, x
//最终指定的特征类型
) X6 `% m- a3 r- R: ]UF_UI_mask_t mask_triples[] = {
! V( m3 i% B4 ^2 V# V- _1 N) _5 e6 fUF_line_type, 0, 0,+ ]  b8 q& g5 T  o8 E1 W
UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,3 C: N" [* Y6 ?0 E' ~& H3 ]" I
UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};

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

if((UF_UI_set_sel_mask(select,
3 z# ^. g0 o( S9 u0 T( q. nUF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,- ~/ \, k  }; ]
num_triples, mask_triples)) == 0)//3倍 3*3=9

{& H9 [- p. b9 A8 a; ^
return (UF_UI_SEL_SUCCESS);/ s+ k9 Y' o( N2 U& |; l8 J6 o
}
1 a$ ^# y1 h) Y& L' Lelse) ^' Q  I) C; C+ ]1 h  a$ I6 P
{- I$ n! t4 ?3 `0 w( {
return (UF_UI_SEL_FAILURE);
. y' x6 a/ m7 b" R' U4 a4 d5 b}
) [& n5 ~+ W5 l* Q: G$ B+ U}* A0 d. x5 Y, a  g: [. F
static void init_camgeom_app_data2 i% j4 D8 f4 ?
(
- G( U0 y: X; MUF_CAMGEOM_app_data_p_t app_data) v7 c9 \: k/ o; z5 g: v
)
3 N6 b' ]0 ^" Q6 w& J{
8 ~5 v8 e! A6 n! K) Lif (app_data)
" I2 L% g& z& e, l" C2 {{
! t! S/ [6 _+ Y5 `& ^* i& ]/* Set flags. 设置标识*/

app_data->has_stock = 0; /* Used 1 - Else 0 */7 m  p% h! ~7 ?7 ~
app_data->has_cut_stock = 0; /* Used 1 - Else 0 */: V( e4 i, W$ X/ p, |  g; N
app_data->has_tolerances = 0 ; /* Used 1 - Else 0 */
1 @; r, |. A  ?6 r5 F/ c- kapp_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
6 r( t$ w$ b6 \+ p# c0 [' P3 xapp_data->has_offset = 0; /* Used 1 - Else 0 */
/ q* F8 Q$ H# q, i4 S* }app_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 */

/* Set values.设置参数值 */
" O3 m( {% {2 c( Aapp_data->stock = 0.033 ;
' r4 H8 G- g0 a5 aapp_data->cut_stock[0] = 0.2 ;
/ w. |# K- f& }( k( m1 c: F$ lapp_data->cut_stock[1] = 0.1 ;
: i, `, m9 Z8 z/ n- ~- F( Happ_data->cut_stock[2] = 0.5 ;/ W4 Z0 ^: Y: M* I5 U  S- w- s& ?
app_data->tolerances[0] = 0.003 ;
" d2 y2 P( L) r3 d3 u$ rapp_data->tolerances[1] = 0.003 ;
( N) g6 D7 I5 g: c& |app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
. s5 j0 R2 F& B5 s5 T! ?  dapp_data->feedrate_value = 33.0 ;
, X" U" O: {! S4 `0 n$ b" J" Gapp_data->offset = 0.055 ;# C6 J1 m: E  K3 H# W- p2 Z4 X$ M' c
app_data->avoidance_type = UF_CAM_avoidance_type_warning;
0 h2 ?, \" n% r9 P! j, S" u}' D( L9 b6 X2 G2 r+ k) P4 f
}

) o. \+ u4 T9 A
上海点团信息科技有限公司,承接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’错误。) e& I' T$ [, 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

7 ]" I7 ]3 X# X; G, y
不错不错,正需要的东西
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了