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

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

[复制链接]

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

2

主题

21

回帖

270

积分

培训VIP会员

积分
270
发表于 2015-7-26 22:12:05 | 显示全部楼层 |阅读模式

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

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

x
/*****************************************************************************& P! h- @  X2 u# \
**
% o, V1 `0 E+ a  X1 I* F% h** test.c
3 p* ~. f4 }3 P. K**' t0 b. h4 b) g( `8 k& f% x
** Description:
: t& W; f9 ?8 u**     Contains Unigraphics entry points for the application./ o' c* f% ^, p% ^+ E6 Z# T5 }. O
**
( F2 K- ]6 e$ u4 Q7 C: U5 P*****************************************************************************/
+ d, f1 A( E4 ]6 q6 l/* Include files */
1 b# Z+ N& F- e' ~3 H& q$ d' m#include <stdio.h>% F2 d) \( r* m/ G* x/ J
#include <uf.h>4 T! h0 s) e) h7 @, W
#include <uf_ui.h>* S% l9 J! N2 E4 t
#include <uf_modl.h>4 {5 K- I( {' B+ [! l0 F  o
#include <uf_curve.h>
7 x' S! E1 \& U2 n$ _7 N; L! G; A#include <uf_part.h>
. S' Q3 C% \/ F3 n6 k: N* G* g, U#include <uf_modl_types.h>
. d2 J# N- c1 ^#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))): c) G" I5 _+ B+ x5 u
static int report_error( char *file, int line, char *call, int irc)
5 i: c7 Y! r) Q. M8 Y{
8 d9 z" Q( H% [    if (irc)
: }' P6 U+ T* Y$ M+ d2 L    {
( [+ s% \5 x) ~0 W        char err[133],
+ \8 F( T/ ^6 I1 f0 u7 n/ D             msg[133];; {! t7 B5 I- `) O8 i8 a
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",+ V* r+ t. w# @. e+ s4 X0 j
            irc, line, file);
. M4 G; P+ ]3 A        UF_get_fail_message(irc, err);
$ p, d9 Z; C- Y1 ], n4 ?2 u" Q        UF_print_syslog(msg, FALSE);
9 P% @$ E; H' T        UF_print_syslog(err, FALSE);
8 D0 F9 S! R3 }6 O        UF_print_syslog("\n", FALSE);
: w$ n$ s# q; U0 M4 R0 ?- Z        UF_print_syslog(call, FALSE);
: W8 |0 ~/ f: l) W# o$ u# ~        UF_print_syslog(";\n", FALSE);
( ^8 L  V/ ^5 Q" j" [        if (!UF_UI_open_listing_window())+ ~4 U' o$ b9 l. v
        {
4 U4 h- }9 }! t* I: L+ q            UF_UI_write_listing_window(msg);
1 j& O2 ?! [+ N, E4 R; t: V            UF_UI_write_listing_window(err);
; _2 D$ \* l8 W+ \            UF_UI_write_listing_window("\n");
" s* p+ j/ o- X! [( n: x9 [; j            UF_UI_write_listing_window(call);- d- G/ l/ C/ e  g7 q
            UF_UI_write_listing_window(";\n");
9 {$ N7 n. H1 F! Q! b        }- L& ]# t+ @2 }3 o. f7 Y  h( s4 u
    }& |# `+ y( V2 {0 P: A) W
    return(irc);; x/ m3 [8 g( W  X+ N6 X
}" i8 H& _* K  {1 ~% m) Q
+ G$ n, L8 W: F7 @9 G- u
/*****************************************************************************
& o( H: c+ g8 i**  Activation Methods# \' K3 _! \" U& i0 |: U! |! ?0 F
*****************************************************************************/
# u4 W, M% N  ~* S/*  Explicit Activation
$ G  W; I7 Q6 S6 ~, c5 M* |**      This entry point is used to activate the application explicitly, as in8 d- Z8 C0 R# C( a1 Q, Z' @* t* j
**      "File->Execute UG/Open->User Function..." */
1 G/ ?# B1 B6 ^tag_t part_tag=NULL_TAG;
0 h" K, Z% q0 ?tag_t tar_tag=NULL_TAG;! U! ~- n: o$ P5 {
double origin[3]={0.0,0.0,0.0};
7 G& K/ ~! k, r' |. Ychar *height="30";$ M9 U& Z0 m( f& z) h; ?8 J
char *diam="100";. y% L1 o8 M: I# i$ |" E, k1 W
double direction[3]={0.0,1.0,0.0};5 A8 X( x5 b2 i  V9 x
tag_t cylinderfea_tag=NULL_TAG;
4 z9 |, ~# M: X) buf_list_p_t edge_list=NULL;
! U1 m1 F9 G( x$ Rint edge_count;
0 P7 e! A' K& M/ dchar msg[256];
9 P1 G- M6 ~% R! G8 aint i=0;
9 y* J1 f  c- [" M1 Q2 }5 V, {" y! ntag_t edge_tag=NULL_TAG;
% E. S+ H( X' D  ?2 m6 v. i6 _& Etag_t curve_tag=NULL_TAG;( D+ L5 A  m; D& k+ }
tag_t point_tag=NULL_TAG;" C7 t& h8 E" f/ m/ ^
tag_t line_tag=NULL_TAG;" J/ Z7 }/ ]% f* e( ?% q% t
tag_t point_tag2=NULL_TAG;3 j2 X* ?5 c3 {3 Q1 B# Q8 \
double cen[2][3];
0 ?" D* e2 a5 `/ V7 lUF_CURVE_line_t line_coord;//最好不要定义为指针3 W; Y/ x) [: q; S3 M' s  `
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
. J# e* {+ x6 }% J6 l{" k& E% e# m3 L; ]) h2 C  {
    /* Initialize the API environment */
$ w. Y. b) @* W4 n+ w$ ]    if( UF_CALL(UF_initialize()) ) 4 U0 J& s7 T7 O4 N: \2 b% J
    {
$ H( V( |0 a. b1 d1 r0 i        /* Failed to initialize */
7 G6 O; T2 p* k8 y& t        return;
% O& ~+ L2 O0 W: H    }. q, o" U$ L1 _3 I. W
   
* {0 f4 ]+ O- K    /* TODO: Add your application code here */: z9 n2 s& j; z9 `$ U$ }) i
//1.create a new part1 k  J) g) ?1 m1 @" E2 z2 u8 j% f! B
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);
6 T. H/ d; I) W: x; `1 K& ]6 `0 l  X //2.create a new cylinder8 R( O" d/ T) I: V9 b, d3 x
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
' o$ t' I0 }5 s+ ]! ` //3.get the edge list. H) Q( k2 q. T2 B5 Y: C
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);
* R  P1 y6 O& D3 \ //4.get the edges# B+ c: r& V- X6 M! I- n8 a, n: n
UF_MODL_ask_list_count(edge_list,&edge_count);
0 S/ ]; ]/ u5 E" w , C, _0 u. n  _- J+ A) j
//5.get the centers
0 k5 O: U1 v' @7 H/ e- a for(;i<edge_count;++i){! G  R5 y8 a; U, E. T3 [% w
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);
6 p/ }9 G4 u4 @0 ?3 G% k6 P  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
  t7 N* p7 U. Y5 i$ o2 F3 n. k' J  UF_CURVE_ask_centroid(edge_tag,cen[i]);* |* }! C1 T$ k; |4 S4 C
}# x: ~. T8 s& b# _& Z
//6.create line* D' [" z1 ?1 {. P+ d
//UF_CURVE_create_point(cen[0],&point_tag);) q- S4 b# n, Y: t( @' _
//UF_CURVE_create_point(cen[1],&point_tag2);/ U* _4 u, F. L
line_coord.start_point[0]=cen[0][0];
5 Y) K! O# z8 k# `; }6 x line_coord.start_point[1]=cen[0][1];' b3 \+ [! z9 O; g2 S
line_coord.start_point[2]=cen[0][2];
' |4 o" E/ C/ |/ H0 e2 V line_coord.end_point[0]=cen[1][0];! p$ V5 v) w" \2 w
line_coord.end_point[1]=cen[1][1];
$ c: g$ s- D3 ^! I line_coord.end_point[2]=cen[1][2];
, H- Q% g# A$ z: r7 L: v UF_CURVE_create_line(&line_coord,&line_tag);% N! o3 \( b$ _, S' D
//UF_MODL_ask_list_item()
" f3 @; F: F4 d/ m    /* Terminate the API environment */4 ^  M- y+ \, Z8 [+ w
    UF_CALL(UF_terminate());
8 |: o$ j$ I( a8 L3 d}8 i+ @0 ~' X0 P
/*****************************************************************************
+ n5 _% h- I+ ~/ q( ~**  Utilities% B3 n* a* r0 |. @2 t( K* E
*****************************************************************************/& N: h! J4 S% I5 C3 d3 k2 O! x' A) d
/* Unload Handler6 y3 L* i* T7 [/ e- ]6 Q
**     This function specifies when to unload your application from Unigraphics.+ Z8 `6 R2 g' h
**     If your application registers a callback (from a MenuScript item or a
9 f% |, Z- L7 T( S% d1 V) ~8 Z- N**     User Defined Object for example), this function MUST return
! B+ I9 Z) c" l) g9 O**     "UF_UNLOAD_UG_TERMINATE". */
3 E- N- F. |# z2 b: T# rextern int ufusr_ask_unload( void )
5 O. Z% o1 c& d{5 z- o# D! R/ h  t  C9 ]5 s9 ~
    return( UF_UNLOAD_IMMEDIATELY );
% Z3 ^4 @; ^. w+ C8 \* x}* m: F4 r3 o( }  G% T$ a- F
5 x' R/ ]1 O! @$ y  F1 @

评分

参与人数 1PLM币 +5 收起 理由
admin + 5 很给力!

查看全部评分

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

使用道具 举报

全部回复1

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82168
QQ
发表于 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二次开发专题模块培训报名开始啦

    我知道了