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

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

[复制链接]

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

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

且听风吟 楼主

2015-7-26 22:12:05

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

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

x
/*****************************************************************************
6 f& y4 Y; b" ?**/ ]/ E: p6 M! {/ D# v+ ~1 R
** test.c& v) p! L& M' ]& M
**
7 \# e( _9 v8 m' P; |& X* d1 ]; r** Description:
) E5 a- O0 T7 Y: I. e+ h: T& j**     Contains Unigraphics entry points for the application.% X9 |( q2 ^7 m$ T
**
+ C' }7 N  ^7 Y# i*****************************************************************************/3 ~) y# V5 x: S7 Z* S
/* Include files */9 g4 C# n) l3 ^) u: \9 D  D* T
#include <stdio.h>
  |5 `4 B3 F+ h0 @0 h#include <uf.h>/ t% E+ p( A3 u; \( g, k3 o
#include <uf_ui.h>4 i) B, l" _8 k3 P3 _9 p
#include <uf_modl.h>, d  {, }+ ]9 a1 j
#include <uf_curve.h>
! \9 v0 k8 l: O8 v1 S#include <uf_part.h>
' r& x3 }1 c6 e+ Z#include <uf_modl_types.h>2 j' A9 G1 a9 q$ |; N3 H6 D  x
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))# m1 z( t" T* W. J5 l6 E5 w* w, b9 g
static int report_error( char *file, int line, char *call, int irc)
+ Z+ }' d1 m: F) X  V{+ O/ b* I. I0 M
    if (irc)
% B- m% n2 b) _' }8 O* G" p    {
2 I/ ^7 r& C1 p' ]' `7 I        char err[133],- p+ f: _& W& C) d" _
             msg[133];; \7 H7 q8 C( X9 `1 W. S
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",# F. \/ `$ F8 `0 W7 e+ K( P
            irc, line, file);
. T& J0 e7 S; k" t7 G. B; i  C5 ~        UF_get_fail_message(irc, err);
* |3 ^  N, A$ @$ R2 Z" f        UF_print_syslog(msg, FALSE);+ B8 G1 W8 G/ H, J: O, r
        UF_print_syslog(err, FALSE);
& e5 S" ]7 n$ d3 S, U1 T2 a' v        UF_print_syslog("\n", FALSE);. J2 i! |3 L0 P- ^
        UF_print_syslog(call, FALSE);
; i" X# V' `( F- m, S        UF_print_syslog(";\n", FALSE);4 A) m. c" G( k6 C& \
        if (!UF_UI_open_listing_window()). f1 z7 @7 B& l4 _( M; o
        {; z. s9 q* J' B6 E+ X$ y" F
            UF_UI_write_listing_window(msg);
0 N- X$ {) `$ |3 b- U! G            UF_UI_write_listing_window(err);* U: j  ^5 i) C* W  p
            UF_UI_write_listing_window("\n");
$ K4 S: g' p2 T            UF_UI_write_listing_window(call);
6 H$ r) t  h0 S            UF_UI_write_listing_window(";\n");# n4 J# n/ M1 V* M
        }
* s$ O7 ]$ _6 N    }1 o, Z9 T; B4 N/ ?
    return(irc);( t; K$ x. }& t$ L4 z- x
}. O7 Z; g# Z9 ]" v; J! x- f' a: Q
! `9 j. m9 r6 I6 J! b# l8 w1 A/ L
/*****************************************************************************
9 D; V6 l; C8 c9 h) w5 C) f( D**  Activation Methods
- }& q' G5 J( r% ^) U$ W*****************************************************************************/
# M/ K% \& u" v! c' d5 Y$ {+ z/*  Explicit Activation
3 ]% W9 G$ ?+ F" Z**      This entry point is used to activate the application explicitly, as in
1 b# R9 ~/ E3 w+ r# b5 Y**      "File->Execute UG/Open->User Function..." */8 i) X) \7 L. W  o9 J5 z# v
tag_t part_tag=NULL_TAG;
' b7 j$ \- j$ @1 p  n- M4 \; H  {tag_t tar_tag=NULL_TAG;- o5 |; k9 ^6 W  _& x% w
double origin[3]={0.0,0.0,0.0};+ g, [4 L% M9 W% |+ Q
char *height="30";1 \: h1 p0 v& t
char *diam="100";! y/ B# i2 @7 ^
double direction[3]={0.0,1.0,0.0};
* m/ {7 \7 }0 E8 ?& T- I" A0 @6 o! N+ \tag_t cylinderfea_tag=NULL_TAG;
% V' H3 L. r0 Euf_list_p_t edge_list=NULL;3 z3 @7 s# D# H; ~; f
int edge_count;% |5 p0 u* k, X' S. T. n
char msg[256];. I* V8 u% j, l
int i=0;
; F' \2 B6 W" atag_t edge_tag=NULL_TAG;! S* w$ n: Y* v! Y
tag_t curve_tag=NULL_TAG;
1 c: u+ h- j, H$ X; m; Atag_t point_tag=NULL_TAG;
3 k8 R6 ?% ~8 Q# L/ Ktag_t line_tag=NULL_TAG;; g6 l2 H7 h; Q1 @" y# u2 u% n. e2 B
tag_t point_tag2=NULL_TAG;
( |) w% o" L9 n  U' h9 W5 }6 \double cen[2][3];
9 J8 a% o# K8 M' J" t$ D+ ZUF_CURVE_line_t line_coord;//最好不要定义为指针
0 h* a. c' k' F7 h6 o; Qextern DllExport void ufusr( char *parm, int *returnCode, int rlen )5 F' E$ ?% g9 x2 X- S/ B
{
0 N3 t8 p/ D7 Y5 s" E; c+ o3 B    /* Initialize the API environment */
% g$ |( t! j8 c! l    if( UF_CALL(UF_initialize()) ) % e+ U% p4 V' e
    {( A8 h: ~2 C$ m  \- B; K
        /* Failed to initialize */+ H: q5 i: p3 z3 H2 q& V1 }
        return;
% V- b" {& q" d! m. y    }
" ?( Y5 L2 ?/ L: f    , U7 \3 ^1 F- B4 N9 p1 Y2 @  o
    /* TODO: Add your application code here */
  E; _- O5 A" p8 d" Q5 t //1.create a new part
& S9 r$ T# g8 o UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);' B4 ~& _$ t3 g# B# a+ d: Y
//2.create a new cylinder
! x4 j3 T. @. V; I# w8 N9 \1 E/ [ UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);  J: _* ?) u. O1 B- d
//3.get the edge list
0 x5 [! O6 _, C/ R% H4 b UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);) x2 g/ ~, M5 k+ K8 D8 _
//4.get the edges
7 |9 ~, G' l5 i8 x UF_MODL_ask_list_count(edge_list,&edge_count);* x% \+ E5 V9 w1 s: z) Z8 a! F

" H% a: E5 z+ ?' a5 M //5.get the centers
& f: u! L+ C7 j* w0 F for(;i<edge_count;++i){" K$ ~/ f# c; e. P" q  K, p
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);7 d, H! W0 @) }  ^& d7 o
  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);0 e4 n' q, G) B& }
  UF_CURVE_ask_centroid(edge_tag,cen[i]);
+ {7 s% H& y2 F! n$ Z }7 I$ S4 W; s# i
//6.create line
, u6 l; A8 z; q1 l5 s  B& \ //UF_CURVE_create_point(cen[0],&point_tag);2 q; u1 N  X9 B* Q# S0 i
//UF_CURVE_create_point(cen[1],&point_tag2);' ]3 \3 g- s8 B5 S
line_coord.start_point[0]=cen[0][0];5 v% H) w' D9 b- X
line_coord.start_point[1]=cen[0][1];
( o2 Z2 {' x- J# j6 p8 X line_coord.start_point[2]=cen[0][2];
+ p  L4 X- e* h" C6 E line_coord.end_point[0]=cen[1][0];8 m+ l1 S+ F) P
line_coord.end_point[1]=cen[1][1];
! ^) l- |8 x/ {0 x line_coord.end_point[2]=cen[1][2];
- W1 y$ |: V% N0 b5 b" N# U( L UF_CURVE_create_line(&line_coord,&line_tag);* h/ r, n1 B4 Z! p) u7 Q( i
//UF_MODL_ask_list_item()
, x. c- b6 Y/ K2 }6 }    /* Terminate the API environment */+ J1 B3 d# f1 h7 R; }& l6 a. d
    UF_CALL(UF_terminate());" ]) g0 u  L4 ^5 @; v  k! A
}1 e' {; I) M9 E: k4 s
/*****************************************************************************! A( e( s0 _  v' H, L
**  Utilities
+ i6 Z, m& b" y3 V4 I*****************************************************************************/4 X3 Q& N% V9 l
/* Unload Handler% c& b% p8 @, f3 l6 L
**     This function specifies when to unload your application from Unigraphics.
' D. \* A$ {: T6 [) b; ]**     If your application registers a callback (from a MenuScript item or a, I1 p! M$ A9 Z9 J* x
**     User Defined Object for example), this function MUST return
5 d2 ^6 i+ ]# Z) [, G**     "UF_UNLOAD_UG_TERMINATE". */
5 ?, @  I5 p3 n2 n2 Wextern int ufusr_ask_unload( void )
0 R6 I; B' P8 s% H" ?/ b, W' e{3 Z- C8 W; y. p
    return( UF_UNLOAD_IMMEDIATELY );
* N" I5 S1 J8 i6 h}
) v) @" c0 v- A- a0 s/ \: `+ `) v/ b: u0 w+ n: t

评分

参与人数 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二次开发专题模块培训报名开始啦

    我知道了