PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

[交作业] lesson2exercise_CreateCylinder

  [复制链接]

2015-7-17 22:23:12 3077 2

文星和合 发表于 2015-4-21 21:14:38 |阅读模式

文星和合 楼主

2015-4-21 21:14:38

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

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

x
/* Include files */; ]( M2 h( P6 b# a. Q' f8 X, O
#include <stdio.h>5 Z# ~: {5 z1 W" B
#include <uf.h>
* X; R- [( Q1 \' T' ~" R2 s$ x#include <uf_ui.h>4 C( X. q3 `6 u6 Z
#include <uf_modl.h>* E, C/ ~9 M, ^% N
#include <uf_part.h>" ~. d  l% O+ ~2 S" n
#include <uf_obj.h>;: ?' a2 I/ O) ], n4 U
#include <uf_curve.h>/ U$ ?6 |: ~. v

& d( U+ \$ [/ y& b7 f" b8 O; w#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))+ [$ S. }/ ^: I) P/ l
static int report_error( char *file, int line, char *call, int irc)
5 |- [# p! V6 I& l) [1 @7 Z! U' j{! }7 l7 H$ H' C/ B/ e; n6 E
    if (irc)
9 E. n1 s6 b+ w% S" K# q& x    {) R: n& d: Q, M5 K/ j% ~+ u4 y
        char err[133],
6 @) U+ I8 r6 X( Q$ Y) @  m             msg[133];
$ }' \# s6 s* r& F4 z. Q# w" ~  _        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
2 c+ ]: _/ v1 j; K" l0 y7 P            irc, line, file);
+ |. h5 R' W' S; d$ C        UF_get_fail_message(irc, err);+ m/ ~$ n' Z, U5 v3 l/ [5 O
        UF_print_syslog(msg, FALSE);" c0 G% S& \; o* L5 o' |
        UF_print_syslog(err, FALSE);% g; _& e3 r) i4 I3 Q; z
        UF_print_syslog("\n", FALSE);
. l7 {. o+ q3 t( V( @+ p        UF_print_syslog(call, FALSE);* B3 b# l* t/ @( P% ?' p
        UF_print_syslog(";\n", FALSE);3 t; ~( Q3 b/ g5 d
        if (!UF_UI_open_listing_window())! J! i+ z1 g9 |$ f' n9 q$ k
        {- H: o( `/ @* |) h- H7 M
            UF_UI_write_listing_window(msg);
3 ~; d% m/ Q1 ?# d9 y2 ?/ F            UF_UI_write_listing_window(err);
1 s5 i) d+ s( [: m7 n$ Q            UF_UI_write_listing_window("\n");
4 ^/ r- p: J% o) i            UF_UI_write_listing_window(call);
4 X6 b; \* l. X- c! A& R3 l            UF_UI_write_listing_window(";\n");
3 ^; p; V: i7 _% n/ q& X4 Q- ^) O        }
  p6 Q% a6 `) m    }& h, U0 ?* \- f3 X% o
    return(irc);! Y3 }5 g/ L( e% A4 u9 E3 [
}
- T. S& D6 F& I
$ F4 I# ~% \% t1 z/*****************************************************************************" S* I2 _% h/ j7 Y: U0 _
**  Activation Methods5 Z# q0 X; x: g
*****************************************************************************/& @7 w. m6 w" g) Y5 K+ Y
/*  Explicit Activation3 t6 `* z6 U1 s' v
**      This entry point is used to activate the application explicitly, as in
$ [/ h9 j* k4 g% I) V**      "File->Execute UG/Open->User Function..." */
, I8 z+ [; L, ~$ {( O9 C% Z$ {
- B- F5 E; t' G3 a; M; Aextern DllExport void ufusr( char *parm, int *returnCode, int rlen )2 V2 j& @: k0 m( U/ O3 h3 ?, [! [
{# ^. l) x! C4 V* z# B+ O- q3 q. d. C
    /* Initialize the API environment */
$ G0 d: s0 E' u3 p" y( z tag_t partTag=NULL_TAG;
/ f6 _; X5 G; p& W5 U' E double origin[3]={0,0,0};
% U. N2 P: P  l* h0 v2 f- t char *height="200";: N, {* P9 q' o$ H3 @+ q6 ~
char *diam="20";
$ `. S# l! r4 u0 x6 q- L( V double direction[3]={1,1,1};
1 g( t1 w4 \" X; J9 P0 n tag_t cy_obj_id=NULL_TAG;
: M; g+ f! n) O: N3 I+ z uf_list_p_t edge_list;. Q. \6 N2 X! q) \
int count=0;3 z. D1 B" E, I' L: E
tag_t edge=NULL_TAG;
! [0 J' B: a- a# M3 [+ W0 t7 H double originalpoint[2][3];- N4 b! ]# ?" x
UF_CURVE_line_t curve_coords;) ^( A% q5 v* [4 L  H
UF_CURVE_line_t mycurve_coords;1 ~* [6 M# y! \7 L& O" ~8 D
tag_t linetag=NULL_TAG;- o" q% c, {/ I7 e
tag_t body_ID=NULL_TAG;7 r7 E% ?/ n& M, b9 |7 z
int i;$ ~2 |0 J7 N2 ~( v" A3 O& R
char mymsg[256];
- l+ u, o4 p7 a3 c. U7 e    if( UF_CALL(UF_initialize()) )
/ ?  J' d* r' h* _8 m; B% s    {
/ |8 t! e* D5 ?8 s3 T/ m5 s        /* Failed to initialize */- ^& b& l! d+ W* I
        return;% Y6 P6 S7 I, G7 W0 S
    }0 G0 k* s9 _% R3 y4 D
    / {- |: r7 s2 L2 F- I
    /* TODO: Add your application code here */
: q8 `' A& q1 L  g: ?- M // 1 new part$ T* {' a6 }4 @5 c3 Z7 w
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠1 |9 F3 I. A5 L+ q6 l! f3 ?
. I- s$ h: i+ m6 q' q, Z2 K& n1 Q
//2 new cylinder
  z7 Y" o+ Q: e$ N UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));, P+ V1 ]8 D* F2 |) e. d( k( u5 Q
UF_MODL_ask_feat_body(cy_obj_id,&body_ID);
( A& h0 K( o; r7 g+ Y' V$ X9 Z //feature -> body4 _/ o. S$ Q, i9 x+ ?9 _3 A: P) `7 i
UF_OBJ_set_color(body_ID,21);6 R' n* g% w/ [. \- D9 S2 h5 i
//change translucency+ \8 }1 V8 f, e3 R6 N/ I+ f
UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度% g; z' _! Q* ~* e- V
//UF_OBJ_set_color(cy_obj_id,21);  //错误的用法,cy_obj_id是feature的tag,不是body的tag( s" X0 q& [" b2 y6 c) l
//3 new line
+ N4 j' k  y! S- R UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));
" R4 e% P. I2 T7 S6 ]7 t2 ?1 [ UF_MODL_ask_list_count(edge_list,&count);) k4 m! ^' ~. }0 O5 w+ \# w; f4 Y
if (count>0)' K) Z$ F9 t" }
{
8 {- d' M& G: L- z9 J$ M     for(i=0;i<count;i++)9 |; p- t! ~, m" R9 l$ Z6 g
  {9 w% Z) e) n% u! `( d! K# i
   UF_MODL_ask_list_item(edge_list,i,&edge);
/ B. _& y: `/ M# E   UF_CURVE_ask_centroid(edge,originalpoint[i]);//计算圆弧中心* P5 h* m  m- m, v! o
  } * ^; F) C; k7 `
  for (i = 0; i <3; i++)
6 Z# p! G: u0 P3 [  {6 |( A" T6 _5 Z  l& J+ d
      curve_coords.start_point[i]=originalpoint[0][i];, W& w/ C0 W( P( @" t: }
   curve_coords.end_point[i]=originalpoint[1][i];6 E: L  r4 }' t
  }
1 J& v/ o  A3 H( E8 ~ // UF_UI_open_listing_window();2 }' V4 _, X; W) z! L2 w
// sprintf_s(mymsg,sizeof(mymsg),"point1:%f,%f,%f point2:%f,%f,%f\n",curve_coords.start_point[0],curve_coords.start_point[1],curve_coords.start_point[2],curve_coords.end_point[0],curve_coords.end_point[1],curve_coords.end_point[2]);
# Y. U% q' V- {6 m0 d* [8 m" ~ //UF_UI_write_listing_window(mymsg);
( F! j: g: Y( s( ~5 \ // uc1601(mymsg,1);
. ]( a1 \& G# T  X0 @  UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线
& O: w7 B( E3 s' G0 T  UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点) j; a* A* W6 S
  sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%f  end:%f,%f,%f\n",mycurve_coords.start_point[0],mycurve_coords.start_point[1],mycurve_coords.start_point[2],mycurve_coords.end_point[0],mycurve_coords.end_point[1],mycurve_coords.end_point[2]);
) r- s2 o5 Y1 K  R5 u1 d  //UF_CURVE_ask_line_data(linetag,&curve_coords);
, Q5 E4 r4 t5 d  //sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%f  end:%f,%f,%f\n",curve_coords.start_point[0],curve_coords.start_point[1],curve_coords.start_point[2],curve_coords.end_point[0],curve_coords.end_point[1],curve_coords.end_point[2]);5 I. D* V7 p+ S  _! D; T3 H
  //UF_UI_write_listing_window(mymsg);
! X) A3 x; p' K- [  uc1601(mymsg,1);
; J9 r) x" @6 j: u3 D( r  t }
. `, k2 Z+ X% l5 Y' G$ d* N. W2 R else; S6 F& w8 A8 B
{& C' M3 W- A2 n. I* s+ [
  uc1601("no edge founf",1);
/ ~" W7 w5 r; b+ d/ d( x }: X' G$ }8 D( Q8 _
% S2 `5 W" Z/ o% X( L  e0 f
  `) i1 o) b$ S3 Z2 |8 ^
//UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);* R: F$ o0 c; L/ D6 h
//UF_PART_save();  //保存部件
4 E; K7 S! k: K7 e9 {' t/ Z2 h //UF_PART_close_all();   //关闭所有
/ f% Y+ Y1 H( S* e9 r
9 B6 y1 W- ]" ?    /* Terminate the API environment */* H" g2 v/ m3 }
    UF_CALL(UF_terminate());
2 I0 o$ `6 j- x- ^6 a}3 O0 Q3 y: h3 z4 A& H/ E
/*****************************************************************************: q- u1 i; X- x; Z/ M9 g
**  Utilities% F" b# G% ^. b5 X! k5 ^# K) E
*****************************************************************************/
5 a! Z0 h8 o. S3 c6 f+ S% J2 I/* Unload Handler* P4 {: m$ Y: |: B- ~- A
**     This function specifies when to unload your application from Unigraphics.
3 Q( w  W' d+ A* G. y**     If your application registers a callback (from a MenuScript item or a
% |& d' n7 W# b, F* [**     User Defined Object for example), this function MUST return- o: P0 [4 g( E) W
**     "UF_UNLOAD_UG_TERMINATE". */" s/ H% b5 D; s; L$ f
extern int ufusr_ask_unload( void )' G* g9 p; Y  ?& q+ e) K; S( @
{" m; Q6 C% Z7 K- a
    return( UF_UNLOAD_IMMEDIATELY );
  S; |, h; Z7 p: o' e' m- T3 D}
) E7 T9 X% \6 O% N
6 `3 F% E) b4 ]: G( c6 s& Z& h: V& U; o0 G% V
我把圆柱的方向设成【1,1,1】,成功了. f+ k1 Q& {9 i
% I% O2 x- u1 A: o
无标题.png

评分

参与人数 1PLM币 +5 收起 理由
admin + 5

查看全部评分

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

使用道具 举报

全部回复2

hcaini0829 发表于 2015-7-17 22:23:12

hcaini0829 板凳

2015-7-17 22:23:12

很厉害 支持支持
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了