PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

[交作业] lesson2exercise_CreateCylinder

  [复制链接]

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

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

文星和合 楼主

2015-4-21 21:14:38

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

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

x
/* Include files */* w: r5 \! w+ m
#include <stdio.h>
' d6 K. y' P  X; e6 @" p#include <uf.h>+ I4 Y5 S# [/ W8 q" C5 T8 f5 I
#include <uf_ui.h>9 o. i% k' P( Z. @! T
#include <uf_modl.h>
# y$ k# q. O/ _4 d. Q) o#include <uf_part.h>
" v5 x) v/ N" @+ S% V+ e#include <uf_obj.h>;
- w( H) Z0 Z7 a#include <uf_curve.h>
+ b2 f5 \9 H5 B' ?( k( L
- O' q% t' ]. L#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))); F) C- j$ z6 ^5 |3 ]+ n# G! x% G9 w' n6 H
static int report_error( char *file, int line, char *call, int irc)
( [9 v- C# Q5 J4 Y{; q$ b) L3 y; W7 Z$ H+ ~
    if (irc)
' x& T  L3 n  N" A9 H    {; k+ f& m, P5 I8 F. u
        char err[133],
9 v( @0 j. L$ e             msg[133];$ c  n" x$ ~+ i" B# }
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
7 U# a, ?4 U( L6 E# p            irc, line, file);8 ]/ k- z) t# l( C( Q% X- Y
        UF_get_fail_message(irc, err);$ x' B3 V" t$ Z# p3 D9 Y
        UF_print_syslog(msg, FALSE);
- U3 P! m! }" e, M3 N5 K        UF_print_syslog(err, FALSE);
0 Q$ C0 |  y" k. g        UF_print_syslog("\n", FALSE);3 b+ ^; |' s  X5 C4 ^
        UF_print_syslog(call, FALSE);
! j3 f5 p& j  F( y7 ?7 B        UF_print_syslog(";\n", FALSE);. d2 j/ U3 O4 Y" b1 T, t; V% C
        if (!UF_UI_open_listing_window())' r: V, _2 G: h$ r& W) g9 n* F! ~2 \$ b
        {8 }- T# A' |3 q- c8 n2 p  ~, |
            UF_UI_write_listing_window(msg);3 _+ R. i+ G- s8 _
            UF_UI_write_listing_window(err);/ G5 ~1 c$ W* e7 {' x
            UF_UI_write_listing_window("\n");- L1 u# Z9 ^) a8 x5 P3 e
            UF_UI_write_listing_window(call);  p" P$ x" H8 E# R
            UF_UI_write_listing_window(";\n");$ T( |& L8 h+ L) e3 r2 U9 {
        }9 Y5 h4 t% U0 f% o
    }$ ~4 x. ^, r: Z: i: G! w
    return(irc);
2 p% `  ~% |# `3 O3 W& ~}
9 `' s) i! S0 h
- y3 a: x) I8 C% B0 p- I% U+ @  Z/*****************************************************************************
! j( P' ?4 W7 l9 E**  Activation Methods
4 R% L' d3 ^( q. z' X# R" p5 |*****************************************************************************/
  _1 Q$ n* W  B9 v" C/*  Explicit Activation3 Z0 u: @& N; B% t- \$ N+ A* I+ I, o
**      This entry point is used to activate the application explicitly, as in
9 E+ }0 a- J2 b% i) s$ J1 w2 E**      "File->Execute UG/Open->User Function..." */: G! b; m8 C( v
( |, C8 g! i) W1 `* U( @  Y3 ~
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )2 e% D7 @, j, Z! D$ X
{
( w0 _3 O4 p* b% K* c    /* Initialize the API environment */6 {( j# R( f# {
tag_t partTag=NULL_TAG;- V9 s( v, r) |- p* [/ l# J
double origin[3]={0,0,0};
$ S7 I% ?' c1 ^2 O0 M7 J4 u& I char *height="200";
6 u6 |7 n3 `' h# p char *diam="20";0 ?; k$ b+ H7 S* z' W* @1 V
double direction[3]={1,1,1};
: l8 M/ B0 ]9 b/ l' z tag_t cy_obj_id=NULL_TAG;
5 N; Z6 H: Z7 l uf_list_p_t edge_list;# o* l: ], L9 P$ E" E% {# ]9 C  w
int count=0;
. L1 Y! i+ i6 W7 C5 T, m; h tag_t edge=NULL_TAG;9 t$ ]) Q. Z3 G+ o% K! t
double originalpoint[2][3];
3 c! a5 d; c$ n3 B$ X* t* |2 F UF_CURVE_line_t curve_coords;9 o/ M2 l: m8 x
UF_CURVE_line_t mycurve_coords;$ f* R; f  g& h. g
tag_t linetag=NULL_TAG;
, _% d7 n: X+ g$ }0 V2 T tag_t body_ID=NULL_TAG;( K8 i3 A# f0 L
int i;* I1 r% K! g8 z, y3 h
char mymsg[256];
6 D5 ~8 ?7 W( ?) I3 p* s    if( UF_CALL(UF_initialize()) )
; W* q) ^( {; m    {
$ d! i& a! G# O& [' T        /* Failed to initialize */, M5 ?* H! h; P4 D
        return;8 Q: S  S4 `3 b8 h) |8 X# z
    }0 B# r4 o- `/ ~
   
; C$ j( j( N- U* c* X    /* TODO: Add your application code here */- M# R$ Z* e0 {0 t
// 1 new part& L8 E# V4 K, B3 ?. E% W& k# S
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠( p) r) {, e; C: O, r% S$ B. a
6 ?# a- k, h( v: ~
//2 new cylinder
. M5 j( F, Q  m: I# |0 z- W& x2 B UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));8 j0 d" ?, P5 j* W
UF_MODL_ask_feat_body(cy_obj_id,&body_ID);+ y3 x! q2 K) ]3 W% S3 x$ U% x
//feature -> body
, f' Z1 f: |( ]+ H- P# r7 q5 a4 T0 C UF_OBJ_set_color(body_ID,21);
5 C9 O! g6 Y( [2 f6 i) }7 O //change translucency
; l7 h% C) G( E/ W" ?) c* {( e  w& }" [ UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度2 L' C8 i" y3 e  R
//UF_OBJ_set_color(cy_obj_id,21);  //错误的用法,cy_obj_id是feature的tag,不是body的tag9 F0 L7 T: d( S7 M1 ^1 `
//3 new line* v2 O% o1 X, g5 P/ n% D
UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));& V& O! V- X. r1 f/ ^8 b2 j( |
UF_MODL_ask_list_count(edge_list,&count);$ `- U3 _7 P  j" i9 W3 z7 E
if (count>0)
0 q+ e1 L: i+ w. t( e3 I {: B# O" Z) t+ R! E- @% e( T
     for(i=0;i<count;i++)
8 L9 |9 q3 p$ K( l  ^  {' t; {' q  U' ^* P+ @
   UF_MODL_ask_list_item(edge_list,i,&edge);
3 I. c' `* |9 b   UF_CURVE_ask_centroid(edge,originalpoint[i]);//计算圆弧中心
5 _8 \8 f7 S/ R6 ^  }
2 V# F1 g9 Y* m1 u  for (i = 0; i <3; i++)
* \4 j: V! [; Y, M7 x, @6 {  {1 @; ]# T7 k; K6 h( A6 i( U
      curve_coords.start_point[i]=originalpoint[0][i];* l5 J* r% v* \* U# l- H
   curve_coords.end_point[i]=originalpoint[1][i];+ `) {8 {% g5 P5 y( W
  }
+ f8 G  p6 A: p, ^, L // UF_UI_open_listing_window();8 a$ h, @' }0 R" F" _3 y; B( t7 l
// 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]);
. u- a# h7 i( s8 ] //UF_UI_write_listing_window(mymsg);/ Y1 u6 M9 `# G% R; E7 c
// uc1601(mymsg,1);) O% a  V+ A- h% K7 j, A/ p3 m
  UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线
0 f( ?% j; S* V1 E+ T, i  UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点6 U' ?: d; \# q/ l2 Z4 `4 Q# n
  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]);
  Y2 S. k1 b8 s0 u0 `; x" e/ \  //UF_CURVE_ask_line_data(linetag,&curve_coords);! F2 A3 U& H( }
  //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]);) x$ w/ I4 k# N1 s  ^
  //UF_UI_write_listing_window(mymsg);" w5 J: N' B( }1 ^0 d
  uc1601(mymsg,1);
6 K/ _3 \: s8 t) B) v$ w1 B }1 B+ k; {0 j1 {- B; q, c: l
else+ r4 n$ H" Z( b0 J
{5 ^3 s1 u. r) v( v, o, F' J1 `) p
  uc1601("no edge founf",1);
+ a0 Y% {4 H5 B, x6 `: o! y }
3 O, F9 U( H3 B& a) |3 A' M
# n6 e9 S0 |8 i5 S7 q7 q+ o4 l. a. x
//UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);& x' Y; M7 A+ d  L
//UF_PART_save();  //保存部件8 _+ m7 z, j. m4 E
//UF_PART_close_all();   //关闭所有! ?. d' ?0 l' X% `
; D( F4 y, W* U
    /* Terminate the API environment */
* p2 z% I# ]. O' {: U    UF_CALL(UF_terminate());  h; W# j. ]- n1 q
}. ]/ U( U0 U2 ]( f( N- D  T
/*****************************************************************************
1 `) h2 V' d# P" P  D/ s7 X**  Utilities
3 W6 q9 i; M% s- _% F9 _*****************************************************************************/
: R/ O. r7 r$ |( w  B# {/* Unload Handler/ B4 L5 x$ G( ?7 T$ x6 e
**     This function specifies when to unload your application from Unigraphics.4 T7 I% |  {" I3 b$ y1 T+ T; f
**     If your application registers a callback (from a MenuScript item or a  ~- e' R2 w, T' p2 r
**     User Defined Object for example), this function MUST return. d; T  C# c6 g* g5 z
**     "UF_UNLOAD_UG_TERMINATE". */' K# j2 m  e. I( ?
extern int ufusr_ask_unload( void )' R0 @* x! d+ t
{
8 B, }7 ^# e) @1 Z: G- \; z    return( UF_UNLOAD_IMMEDIATELY );
: d0 ~+ q0 \- \9 o+ o  Z}
6 c3 V: |: y1 D4 K9 q: c( j; J' ~  c2 A
5 v+ P8 ?$ Q+ g- e/ m
我把圆柱的方向设成【1,1,1】,成功了
3 x. O$ C- _1 }6 ~  B# o3 Y2 m% W3 W+ W5 A, D$ M, l5 c
无标题.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二次开发专题模块培训报名开始啦

    我知道了