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

[交作业] 第二课圆柱创建轴线

[复制链接]

2015-7-27 11:00:52 3003 1

且听风吟 发表于 2015-7-26 22:12:05 |阅读模式

且听风吟 楼主

2015-7-26 22:12:05

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

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

x
/*****************************************************************************
" C# H# j- ~+ f' w; u**
0 A8 w5 [2 |3 S2 ?. o5 C' N+ ?** test.c
: A8 v9 _- j: h( @, P**
" f+ i9 h5 i0 z: G8 R9 U5 c** Description:1 U; k6 H8 [% l$ N. g
**     Contains Unigraphics entry points for the application.) N4 S% o4 \( r0 V/ F; k
**6 d/ T0 D1 j, x( h
*****************************************************************************/
& K* J- N3 |" Y/* Include files */
5 e4 h( g8 c5 w, C, n* x#include <stdio.h>
' X3 g$ W2 H$ |#include <uf.h>: _$ m  c9 a, G4 D8 {5 c2 b" P
#include <uf_ui.h>: q7 W  G3 X- u" W: H: f# r/ s
#include <uf_modl.h>) m7 k2 y6 ~% A, ^
#include <uf_curve.h># Q5 i. I$ Q2 b+ J' o
#include <uf_part.h>
, _* ]6 H( n2 N- ?% a#include <uf_modl_types.h>5 U. n2 X0 ?: P" T4 ?
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))), X1 W' _$ i' S  V
static int report_error( char *file, int line, char *call, int irc)
. b; @5 Q2 a1 l% u& g{
- v% m; D+ P+ J3 A( s' S6 D5 p    if (irc)
$ T! Q& g- n# Q  a& i7 k3 C/ I    {
% \7 }- E2 ^  ]        char err[133],* l' w4 _. k0 F$ u
             msg[133];, i8 q9 y6 e8 L9 \$ K
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
/ F1 O5 l) v$ ~: U            irc, line, file);
, x* E+ u0 A) P: u        UF_get_fail_message(irc, err);
' x7 ~! x3 j3 r. ?        UF_print_syslog(msg, FALSE);
- b2 F( e& i) ?- M4 S+ l6 r0 |# G        UF_print_syslog(err, FALSE);
+ Y7 z# O& v: z& z$ f: ]$ W        UF_print_syslog("\n", FALSE);8 e0 y( \0 X, |: n8 Q
        UF_print_syslog(call, FALSE);
7 k6 X  T% d% k+ L- k2 a        UF_print_syslog(";\n", FALSE);" k. ~0 c1 @, g
        if (!UF_UI_open_listing_window())
) e, U  ^# o% a* i6 t        {
# T, H# z& F* k2 n7 E& S3 g- d            UF_UI_write_listing_window(msg);
& }2 T* S* o1 C6 z- ~            UF_UI_write_listing_window(err);
! G  `* Z, s' I( d            UF_UI_write_listing_window("\n");
  U* q% H) |! r. R) J            UF_UI_write_listing_window(call);' I) [: u4 a( I9 W
            UF_UI_write_listing_window(";\n");# h9 w# J. b" w. ~  ?
        }
% c* I  ?8 p' |0 _    }) R6 N5 R4 u& Q  K# E8 }
    return(irc);
) S) P( ^  ~" |4 v% {9 k$ y6 ?( c}8 f$ x# ^, z; Y6 U7 M
  G" [2 J+ \9 O. m8 S- ^
/*****************************************************************************: \- C# |0 @/ O. Y, ~; G
**  Activation Methods
) S* Z9 L+ s, l5 m" a  S*****************************************************************************/
" e' m3 |) ~2 ~/*  Explicit Activation
! G. f1 m5 G& @* D' Z**      This entry point is used to activate the application explicitly, as in
" d. s$ Y5 x9 q  p: f1 m**      "File->Execute UG/Open->User Function..." */- y" L  q7 w7 M! s/ @5 s. u
tag_t part_tag=NULL_TAG;
. x' l# H% V! K# Qtag_t tar_tag=NULL_TAG;
% d* I) k, n% t" P- @& v7 ydouble origin[3]={0.0,0.0,0.0};; ]& a$ C: @! T7 W+ V
char *height="30";
# G2 |- S* I5 ?4 R4 m% u5 rchar *diam="100";3 l% u. k) P, G2 q, S3 U4 B
double direction[3]={0.0,1.0,0.0};
0 ^' p7 r" y; p& z& F, ?" Qtag_t cylinderfea_tag=NULL_TAG;
/ o3 F' v0 p4 ?/ K1 Z& luf_list_p_t edge_list=NULL;0 {% O9 R/ f# x& G
int edge_count;. v5 ~0 a4 s" _/ A- |; Z
char msg[256];
/ _5 s) v" Q; {- J- oint i=0;
4 M( A9 F2 C2 p6 W5 b5 K; K& B" Stag_t edge_tag=NULL_TAG;( x* P2 n4 k: R, O
tag_t curve_tag=NULL_TAG;0 _% C0 H0 J9 e: n" @
tag_t point_tag=NULL_TAG;0 P0 o9 O' W4 x
tag_t line_tag=NULL_TAG;/ p2 p( X8 j1 G& i
tag_t point_tag2=NULL_TAG;
" s9 j7 e, K( C- V; `double cen[2][3];5 n7 W7 E3 t# F; Q* s+ e
UF_CURVE_line_t line_coord;//最好不要定义为指针
' O  {: F! i( O* [extern DllExport void ufusr( char *parm, int *returnCode, int rlen ): F, ]3 {- w# M' W
{
/ l) ~7 ^9 Q) \" o1 A3 y    /* Initialize the API environment */- W7 F$ j) C/ j! ?
    if( UF_CALL(UF_initialize()) ) & P9 C/ N9 ]1 s8 C/ B  U, B
    {
% S2 W( t) ~: f0 W! a        /* Failed to initialize */# e; w$ G  E6 T, M8 j; Z
        return;
0 |, K+ A# [9 L1 g    }
" H: V$ a0 n( W( ^: L* I   
) u6 W0 x# j0 n. ?7 H% f1 |6 r  {  ^) J    /* TODO: Add your application code here */' o1 l# m& k) p1 P* \0 L
//1.create a new part
4 M: Q$ [0 K4 ~! c5 p UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);
6 |5 r6 ?. z& q* E) T //2.create a new cylinder6 o7 K# x/ v  [' q; u
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);9 T, b  ?% ~2 |
//3.get the edge list2 n' R$ j5 f+ Y, g0 l
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);; C; p3 e! J2 K" O1 v) F6 P( n- y
//4.get the edges
" D  j) M+ ?; T; N$ m! ? UF_MODL_ask_list_count(edge_list,&edge_count);
6 D9 r, s# s  u/ S $ ]: T5 c& g# l& c/ U) F
//5.get the centers2 O( \5 i  j  ]7 e. a; A
for(;i<edge_count;++i){
7 X; K5 Z9 N' t1 I+ z4 ?  UF_MODL_ask_list_item(edge_list,i,&edge_tag);
5 ~! V6 S; C5 ~0 X" y  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);9 m7 p5 {" O. r$ A8 |: Y0 ^
  UF_CURVE_ask_centroid(edge_tag,cen[i]);
" P. J2 R( z2 b3 x6 G' D }
+ i) R8 V5 h+ k, [+ g# v! o //6.create line
# @# A$ u! H5 ~$ o- B //UF_CURVE_create_point(cen[0],&point_tag);) }( G% o7 j$ H( E  X- ]8 i
//UF_CURVE_create_point(cen[1],&point_tag2);! T2 K: @' W4 y* \
line_coord.start_point[0]=cen[0][0];4 q$ c6 `: H8 ^( M* A1 o
line_coord.start_point[1]=cen[0][1];
4 J1 w" A! o$ g# I" N line_coord.start_point[2]=cen[0][2];" q+ d7 d1 k0 l" D
line_coord.end_point[0]=cen[1][0];
) b* L5 p( ~( J5 B2 Q: z/ |8 x% H5 [ line_coord.end_point[1]=cen[1][1];3 E! f* n: T  W- x
line_coord.end_point[2]=cen[1][2];
7 C9 B5 ~* m5 g: o) V% f3 M UF_CURVE_create_line(&line_coord,&line_tag);7 j! ]5 F( Y2 b0 o/ T3 p
//UF_MODL_ask_list_item()1 S! n4 g8 r& x( I& I( Y" H
    /* Terminate the API environment */6 M8 J. H$ @' R- T
    UF_CALL(UF_terminate());7 d3 X! [! O2 _, ]# D
}
# ^9 c# t$ a4 U# b/*****************************************************************************% |) U; r1 k  x- _8 X; P! E" g1 a
**  Utilities0 V0 x  \8 C  ]- `! j
*****************************************************************************/% {+ s& \# A8 ]* u/ a$ n
/* Unload Handler
* |' L, |5 A; x# i**     This function specifies when to unload your application from Unigraphics.
# E$ F0 |0 n! Q) l; p6 @3 Y**     If your application registers a callback (from a MenuScript item or a" H2 t! x- W3 D' R2 V
**     User Defined Object for example), this function MUST return" C. X' K8 q, E
**     "UF_UNLOAD_UG_TERMINATE". */
# e4 O- L) U9 F3 h+ Q8 Pextern int ufusr_ask_unload( void )
5 B2 _, W' x, n" g# R4 i; [{& q' @! l9 K4 `
    return( UF_UNLOAD_IMMEDIATELY );$ u+ l+ K. r* F: f
}* m" v' [2 k  j  x9 s; M
6 ?9 V- R/ e0 _1 I% b0 |

评分

参与人数 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
回复

使用道具 举报

全部回复1

admin 发表于 2015-7-27 11:00:52

admin 沙发

2015-7-27 11:00:52

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

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了