PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

且听风吟 楼主

2015-7-26 22:12:05

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

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

x
/*****************************************************************************6 a* H# @* y. ?9 i* m
**& t: X. S) i$ a8 h
** test.c
% N3 y, {, t! P**; v  H% @1 a6 x; j
** Description:
2 u% H2 _) U# I/ N8 k/ j**     Contains Unigraphics entry points for the application.' W4 m# r, G+ h5 d, c  n& h$ e
**
  h  I# _$ ^7 S8 [0 z8 L- a*****************************************************************************/
+ g. P# F# X$ M/* Include files */* S8 H: {* p" C+ V. [' |+ Q
#include <stdio.h>! S7 X6 w8 K) e0 t, K
#include <uf.h>
, u4 s4 x3 E, q2 Y: o: c#include <uf_ui.h>/ ?# L) D* y$ y+ l+ Q8 B
#include <uf_modl.h>1 a2 p! ^# e9 L- o9 t: \
#include <uf_curve.h>
# R" r# V9 g2 F* d% W; q' O3 U) h#include <uf_part.h>
9 x9 s0 C2 r" A/ ~#include <uf_modl_types.h>5 N$ Z4 m. t- c) K, s: P) V, a
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
: }* U7 a* C, |5 J3 @- Bstatic int report_error( char *file, int line, char *call, int irc), {, T% t: S7 }# }$ R  v4 l
{; ?5 D. i6 i4 g8 d# H0 E. s
    if (irc)( i/ Q9 {. t+ i/ K5 i
    {
3 Y* i7 X4 b( X  b: P* Z' ~        char err[133],& i8 u; |) r) Y- A3 R! ]. H
             msg[133];3 {3 X5 I- m5 A& M
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
1 E) A# h/ J2 ]3 \  M* X' Z' }            irc, line, file);- ~* z1 Q! ?' M% p6 V7 l, L: q
        UF_get_fail_message(irc, err);
- ]- t. P6 h; c' e( E$ P        UF_print_syslog(msg, FALSE);
+ f6 X5 x$ M7 H* A        UF_print_syslog(err, FALSE);
2 P$ [' L$ f9 q+ v2 x3 N        UF_print_syslog("\n", FALSE);
3 n/ J; J- {% p% H/ i        UF_print_syslog(call, FALSE);% _# Q  T* ^9 ]
        UF_print_syslog(";\n", FALSE);* t' J9 d! Z( x  Y" O6 X$ s  O
        if (!UF_UI_open_listing_window())
5 x6 w; m: {- M. R        {
4 I8 R8 Z, ~6 c; ]) Q            UF_UI_write_listing_window(msg);
+ W' H0 K+ w; Z            UF_UI_write_listing_window(err);
. A( N* R4 o8 `+ y- ^* q  E$ o; S            UF_UI_write_listing_window("\n");7 X7 Q/ i7 X1 M% D, ~# A( Q+ I
            UF_UI_write_listing_window(call);
: O6 `6 q0 H- }            UF_UI_write_listing_window(";\n");: ^% a8 h, f7 D% N
        }
5 E/ o  ^4 X. G' d    }
% V0 Y2 k% x5 G1 D8 T6 l    return(irc);
2 z8 u8 c, l5 B8 t0 o4 C& ^# @  }}# c5 M- O' q  @9 a8 C9 \5 {
  I* @' u0 k) f6 A) Y' \/ M
/*****************************************************************************( D4 f% ~% Q: ]% i0 E# j6 a$ i
**  Activation Methods
5 P; S- \. o" O*****************************************************************************/
4 L- }# T  r/ d4 Z: P2 U! k1 x. h/*  Explicit Activation2 y: m) S. D4 e1 u( k6 D# S+ \6 X4 o
**      This entry point is used to activate the application explicitly, as in1 c% m8 E: A8 X: b* g
**      "File->Execute UG/Open->User Function..." */" {& V" M% l7 a$ u, @
tag_t part_tag=NULL_TAG;! S$ K9 }+ R6 K- |
tag_t tar_tag=NULL_TAG;2 i* y" z  H, f  ?
double origin[3]={0.0,0.0,0.0};, V* C3 O* W' l* K
char *height="30";: \7 M( k: D# j1 y7 {2 ~6 S5 v% Y
char *diam="100";
0 K- ]* T3 N/ ?) `$ @1 U( a6 P% ^double direction[3]={0.0,1.0,0.0};
2 m0 G" T& y0 B& @, w) etag_t cylinderfea_tag=NULL_TAG;
' r! \, J; R% D, Z2 k, Buf_list_p_t edge_list=NULL;
' T5 h! |% I) Jint edge_count;
5 N6 p# ?7 b$ g5 g" w! hchar msg[256];
4 {4 N& e' {+ |! `! ~# Sint i=0;
5 ~' _; r1 u' Mtag_t edge_tag=NULL_TAG;0 r' s  U% d4 J
tag_t curve_tag=NULL_TAG;0 B' y( O6 c' G0 i  S* c; W
tag_t point_tag=NULL_TAG;- i/ J. m8 }. q, V* ^( K5 K( Q
tag_t line_tag=NULL_TAG;1 v. r5 m1 K: d" f8 U/ i/ {
tag_t point_tag2=NULL_TAG;
$ a( M+ z8 H. W* U8 S( b8 vdouble cen[2][3];
9 S7 i& A: \& @UF_CURVE_line_t line_coord;//最好不要定义为指针( P& x/ k1 J* N7 Q/ n: Z; q1 ~/ q
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )" B4 {, ~7 V; L# {$ g
{
# G$ O* U' y# t    /* Initialize the API environment */
+ [% M) t. L; Y: s# f3 Q$ a  N( y    if( UF_CALL(UF_initialize()) )
/ s9 H5 u+ d, |# |5 ]4 h    {6 T2 V$ W1 c, ^  u  L' P
        /* Failed to initialize */
% E4 o+ _! s" p  N7 q3 W" q        return;
! _: k  C1 F- K6 T5 W7 N    }
3 {  F; M$ T" Z1 b& i   
$ R0 r% I* `) t& _    /* TODO: Add your application code here */7 o, _7 s$ d# b
//1.create a new part. q' W7 }' U1 x5 w5 C" a, @1 ^* l
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);* @/ g' `- F7 H' _
//2.create a new cylinder+ r/ e- f* F5 ]% L% c( r
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);9 R9 P2 @) G; _) H  h" z# Z
//3.get the edge list
8 o2 w4 m" |% G* q6 M9 H; L7 D* P UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);" K' }4 e6 O$ O: p$ p0 x/ w$ X
//4.get the edges
; U: B$ f, }- [9 P0 P" r UF_MODL_ask_list_count(edge_list,&edge_count);& x8 }8 O" F* K9 t

1 t8 I) w  c4 e/ ]0 m  w4 q* T //5.get the centers
( a) B4 Y2 Y" U$ ^ for(;i<edge_count;++i){
* H# T% u/ |) Z) V) m  UF_MODL_ask_list_item(edge_list,i,&edge_tag);' ^/ {$ a5 [# l! z5 `
  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
2 g9 V4 l" m" ?. m" Y  UF_CURVE_ask_centroid(edge_tag,cen[i]);
! p7 N+ v3 {" {+ L, p9 n }. ?. r# g, b# ?' g/ j8 r6 C3 e
//6.create line. v7 D4 w( T& Y& b/ j$ z
//UF_CURVE_create_point(cen[0],&point_tag);
9 v' q' G& v0 y5 C //UF_CURVE_create_point(cen[1],&point_tag2);
6 L* Z( v$ k. J$ W3 J9 w+ I line_coord.start_point[0]=cen[0][0];
! m' Q% p( ?- K% r3 c3 O7 Y3 d% e line_coord.start_point[1]=cen[0][1];# I* r1 B9 U+ W) j* @
line_coord.start_point[2]=cen[0][2];* M1 O9 N+ Q# u  B: g+ U
line_coord.end_point[0]=cen[1][0];
2 S+ O" c9 F3 \( I$ t line_coord.end_point[1]=cen[1][1];
1 m2 D( R, \. q4 S8 a line_coord.end_point[2]=cen[1][2];: R4 [: ^7 ?0 r
UF_CURVE_create_line(&line_coord,&line_tag);
6 ~8 m7 g3 A: c% C3 H9 w //UF_MODL_ask_list_item()
, v2 M. G% h5 d! K; N    /* Terminate the API environment */% ^$ ]3 Q5 N9 o- [: @* E
    UF_CALL(UF_terminate());  T5 T* i! g: n( M9 U) _
}
# o# O' y  c; C' c3 X6 H/*****************************************************************************
- a* ?/ M5 H2 ~' H0 g**  Utilities( D  ^+ A8 H. X  R# \, G
*****************************************************************************/* d; w& S9 t$ `6 l
/* Unload Handler
* B' n: T* m9 x5 @% J! I**     This function specifies when to unload your application from Unigraphics.& G& J" H  `* l. k( o8 @$ k3 |
**     If your application registers a callback (from a MenuScript item or a5 W. Q  H" y- p. e3 G
**     User Defined Object for example), this function MUST return
+ q4 s6 ~* R) r  a8 S; [1 S" p9 \+ ?+ P**     "UF_UNLOAD_UG_TERMINATE". */5 i+ m! G# b  k5 \$ h& P  m
extern int ufusr_ask_unload( void )6 W# Q4 V+ V- B' j. c' P
{) V) g2 K' n- I
    return( UF_UNLOAD_IMMEDIATELY );! _# D1 d& w4 P
}) f. {1 Q0 t. s& ]

8 R/ Y  H4 B, `! v" N  v6 d6 I1 @

评分

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

    我知道了