查看: 3409|回复: 1

[交作业] 20160320 lesson 2 2圆柱求和+手工输入中心线+点信息

[复制链接]

13

主题

13

回帖

275

积分

培训VIP会员

积分
275
发表于 2016-3-20 19:15:41 | 显示全部楼层 |阅读模式

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

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

×
/*****************************************************************************% \: y2 ]% e, C5 m& b9 |, [
**
' M  d' m6 P) Y" k; f** creat cly.cpp
! {) w$ L6 l2 P$ e3 H* Y**& W6 g; N0 Z( h1 s' P5 L2 w
** Description:
$ D! N9 K# A( v6 K# z* v**     Contains Unigraphics entry points for the application.4 @4 J2 y. T7 h0 B
**
. P/ I4 @5 O0 t" x5 B% Z*****************************************************************************/6 T0 i; \$ y% A
( U% D0 {$ b2 O) S( D) y1 f: }: u
/* Include files */% {3 e$ E6 g$ R% l! j8 F1 e
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
1 \3 T" ]- b( D0 Q% x#   include <strstream>
4 Y- x; \2 R6 b#   include <iostream>! Q0 }) e# s! L* E
    using std:strstream;% ~9 D: B" t* Y# Z, h
    using std::endl;    ) s3 m4 i) b+ D6 ~$ F
    using std::ends;0 ]9 U5 D6 B& O- Z5 ?  o
    using std::cerr;" O* o7 t  [* g0 |4 l) D
#else
) O3 W' D( g: a3 M#   include <strstream.h># u5 a8 f1 d  o( y0 Z+ k; J. `; k
#   include <iostream.h>7 |1 a4 D  i4 m/ f2 R
#endif
* T# ?, {& k6 v' s5 V' O#include <uf.h>- z9 p  z4 ?) @) l# U9 e
#include <uf_ui.h>$ s: W% I. y$ _* V" I
#include <uf_exit.h>
( ?, G1 D: r3 M; ?2 {#include<uf_part.h>  L1 J+ v8 J& r* s
#include<uf_modl.h>
/ z5 A" U: @6 c( P#include<uf_curve.h>" Z6 ~5 t& I5 O9 C
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))4 _; Y( G( V( L0 M+ _
& y4 l# e8 o( a1 x; d/ I

8 o9 e* K& T! R8 i- d$ s) H( gstatic int report_error( char *file, int line, char *call, int irc)# N2 Y  O+ K! B4 x+ P1 B2 n
{
& X+ t( `% M9 j+ Y    if (irc)
) f, G7 _) N. _, ^' c    {1 }! }5 K( ~: x, L" W9 }0 X. `
        char err[133],2 q8 e- a: I; ^7 i4 v; T6 R! E$ T, L
             msg[133];
. t# u3 [6 r7 D. ~4 h
  j! o2 X8 M' Y+ S        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
4 A: W0 |+ P1 W            irc, line, file);
( W) V% K( p* O3 J6 B+ @$ h        UF_get_fail_message(irc, err);
. L7 @* `" I# x+ K; Z3 z) `
4 u0 V7 E- J5 N) F8 X2 ^        UF_print_syslog(msg, FALSE);6 I; }8 I" F: z6 ?
        UF_print_syslog(err, FALSE);, G# i6 U1 \/ g8 U% p7 X$ _4 j
        UF_print_syslog("\n", FALSE);
5 q" w7 K( N2 m( x, b; ?9 e        UF_print_syslog(call, FALSE);: H! V) y( G* l
        UF_print_syslog(";\n", FALSE);  g! K8 A& w1 c* J0 A$ {  u
2 G2 s/ x% z5 B' n; }6 d8 \
        if (!UF_UI_open_listing_window())
5 H. i) B. K* x) }) \& J6 y. S        {
$ Y( D" _) x: X3 f0 _9 z: F            UF_UI_write_listing_window(msg);+ P: s! ]# W# q' f. V6 b
            UF_UI_write_listing_window(err);+ c) q, U& w- \% L
            UF_UI_write_listing_window("\n");
4 o5 `0 I0 @. }/ [( K2 F            UF_UI_write_listing_window(call);
* r% s  L$ u) e0 `4 u; \            UF_UI_write_listing_window(";\n");
: A8 Q, g) W0 t        }
3 e+ h% R: m- N: z% I" z( Q2 v. j    }5 n$ `7 I! P4 D  L
. c  ~! `. `, d0 p
    return(irc);: o9 ?6 p; H  ]4 B! `/ D
}3 O% L! X4 ?+ B9 z* V$ w: b5 Y2 K

6 I  W# F' n5 w, A3 ^% {6 W9 K7 ~* h9 U# J; a5 D5 F" N4 V! G' `
/*****************************************************************************
3 D2 c7 d2 \5 j6 O**  Activation Methods, D( r7 k5 g' h. B
*****************************************************************************/% f6 E0 F6 c6 x# V6 ~% H8 v" U
/*  Unigraphics Startup2 B( G) O# {% p+ C6 ^  M: W
**      This entry point activates the application at Unigraphics startup */
/ I+ h8 ^! X( `: _0 a) }2 nextern DllExport void ufsta( char *param, int *returnCode, int rlen )0 ]. V  U6 O- A* N
{
/ t8 |3 c. W4 I    /* Initialize the API environment */
5 U, ~! k% g% r; J    if( UF_CALL(UF_initialize()) )
' {& Q7 t( b9 n; t9 v    {$ k1 |' Z/ Y' q. b
        /* Failed to initialize */7 K1 V/ n: P. G8 W
        return;
) p, `5 ^: B4 i: Y    }- E- x" V# l& B2 x2 E+ v, i" p

! C. S+ H7 N+ j9 ]4 ]/ ~2 {    /* TODO: Add your application code here */
4 c) p$ q$ P* s/ }, V( y# j7 c        1 j1 V% L5 z2 ~7 a6 D* w
        //new part( _+ N8 u! D" [/ a) T8 F" a5 s( t

0 h/ G- G# v0 q9 {3 i' g        tag_t parttag=NULL_TAG;
" H# O2 S) b8 e* H% I  i6 j( t$ P0 C  V4 c7 }
        UF_PART_new("c:\\temp\\plmhome.prt",1,&parttag);
! Z- R4 M, a! F0 S5 t, Y. ^3 L' V+ @
        //creat cyl6 O. O$ g5 Q9 D8 @1 r, d9 K  `2 F' _" z
7 t* A% \% R. l2 R1 b- d
                double origin [ 3 ]={0,0,0};. H% O5 y; S+ V/ ?8 S8 `' K2 @
                char *height={"50"};
- |0 h$ D$ n. I4 S                char *diam={"100"};5 w$ j# T' v) m$ i: h
                double direction1 [ 3 ] ={1,1,1};5 V$ L! b; m, H' T1 a- |; W( p
                double direction2 [ 3 ] ={-1,-1,-1};               
# G" ]2 f$ Y: S; O) o8 j                tag_t cylFeatureTag=NULL_TAG;
7 ^. P) x" G1 v4 D
1 ]0 R5 f' `3 c" q% ~        UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction1,&cylFeatureTag));$ e2 J. C1 W! S0 D5 l* [
        UF_CALL(UF_MODL_create_cyl1(UF_POSITIVE,origin,height,diam,direction2,&cylFeatureTag));
- p( I5 s; @& z+ |4 H2 ^        //creat line4 N+ i# b5 s9 h$ J
        UF_CURVE_line_t line_coords;* d- _) M  P3 h% ?: N
        line_coords.start_point[0]=-50.0;
' X& r; T& s  z; N) L        line_coords.start_point[1]=-50.0;
/ c$ N3 G' M" U/ O% ]. e        line_coords.start_point[2]=-50.0;( N/ X- N, v5 Q6 V) ?; G% S5 S
        line_coords.end_point[0]=50;
0 X2 O3 X$ W. B! X- k        line_coords.end_point[1]=50;, X. ]( {4 J' m9 c7 ?% s9 @
        line_coords.end_point[2]=50;
0 U9 E/ j5 q( u2 Y, d, T  ^7 Y        tag_t linetag=NULL_TAG;6 Q1 Q" Z  b. N7 |4 n! O
' p5 f8 S8 T* Y, G' k$ W, W
        UF_CALL(UF_CURVE_create_line(&line_coords,&linetag));6 X# z' K" t  I1 v4 [# v
        //creat point- A: F+ A% g: }) {+ E& Q
        double pointstarTCoords[3]={line_coords.start_point[0],line_coords.start_point[1],line_coords.start_point[2]};' J* M+ `% T' d
        double pointendcoords[3]={line_coords.end_point[0],line_coords.end_point[1],line_coords.end_point[2]};
) v  r8 J5 p5 n( w! Q; @9 W. G        tag_t pointtag=NULL_TAG;
* T8 ~2 X# u1 |; M+ G" A        UF_CALL(UF_CURVE_create_point(pointstartcoords,&pointtag));/ A9 V7 l% M8 c
                double start[3];
' C4 a' J! f5 u; f2 {9 {' _                UF_CURVE_ask_point_data(pointtag,start);
/ r; E: ]) x3 P4 O% @8 Y        UF_CALL(UF_CURVE_create_point(pointendcoords,&pointtag));  O- n3 x6 b& }, C, q0 {- h  m$ {1 k
                double end[3];
: Y4 J8 H% w- r" F                UF_CURVE_ask_point_data(pointtag,end);, t9 w0 d/ Z6 M7 V2 ^
        char msg1[128];4 Y+ |8 R( Y( c# L# T) r4 l
        char msg2[128];
) {; s8 y! W- U8 R        sprintf(msg1,"start:\NX:%f\ty:%f\tz:%f\n",start[0],start[1],start[2]);
: a+ ?$ [) B$ ?$ Y2 `        uc1601(msg1,1);
1 S# j$ [8 N6 N$ ]+ m        sprintf(msg2,"end:\nx:%f\ty:%f\tz:%f\n",end[0],end[1],end[2]);
- J( n# _( Z6 Q( v" x        uc1601(msg2,1);4 ?( V4 l& E5 ?( \0 S% O$ t
        //mapping point from abs to wcs6 f+ C, \. y; h% [# D" c' q, [8 i

) w4 ^! D) f1 ~$ F4 Q: {# k% u7 k        UF_UI_open_listing_window();
& q2 K& D8 M! F( k        UF_UI_write_listing_window(msg1);! N) P1 f/ Z- r, [7 \( G! `* g
        UF_UI_write_listing_window(msg2);
% r& G; r" \+ b3 U        1 O2 N. U+ Z2 l( ]3 U( Z
        //close+ d$ e. R6 e( Z, W# T  J2 Y
        UF_PART_close_all();& ]- v% n1 o, B# j

; B: K+ S3 v# [    /* Terminate the API environment */
. T$ Q' a. s! s3 g4 v& ?    UF_CALL(UF_terminate());
* k$ h& h) h5 _& x0 I2 y}
7 Q6 Q3 W/ O1 G% T8 n3 d2 U* t
3 F, E9 \1 T: |$ N. y9 k2 o/ S  n) x0 ~/*****************************************************************************
3 F" s$ M  _- _6 C/ [**  Utilities) s; _* R7 y; i' C
*****************************************************************************/
, ?3 K" j6 f- x+ R+ s6 i2 F
$ _0 C( h* z8 e/* Unload Handler" i$ ]/ H# H" H' {# s$ I2 J8 b+ l
**     This function specifies when to unload your application from Unigraphics.
0 l# k; P9 w& Z**     If your application registers a callback (from a MenuScript item or a
0 i, e1 ~1 b* _/ o7 l**     User Defined Object for example), this function MUST return) R% R6 R# p! J" l
**     "UF_UNLOAD_UG_TERMINATE". */
! @  J: a, r% D9 f* Q+ b$ Sextern int ufusr_ask_unload( void )
" B( ~1 Z' O6 b( x' d{$ n4 `4 s% P/ Y( e. d9 w/ Y
    return( UF_UNLOAD_IMMEDIATELY );
6 ~/ _: j# f4 I& z4 Q8 R8 ]7 e}
. ~& p# i3 m. R2 U- _. T7 B3 u  n) f: N" y( F4 V
1 P" j- i6 I) t) m( U: r& p
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

13

主题

13

回帖

275

积分

培训VIP会员

积分
275
 楼主| 发表于 2016-3-20 19:27:35 | 显示全部楼层
本帖最后由 gsmfxsmy 于 2016-3-20 19:29 编辑
1 ^3 C1 u# N0 r/ @7 j$ J, S: c5 o# |5 b! @
L:\1

6 t  E. U( y( ]! K                               
登录/注册后可看大图
* g1 s/ P, c" E" ^
                               
登录/注册后可看大图

2 }7 q& A3 W3 l# t. V8 k! u                               
登录/注册后可看大图
1.jpg
2.jpg
3.jpg
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部