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

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

[复制链接]

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

2

主题

21

回帖

270

积分

培训VIP会员

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

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

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

x
/*****************************************************************************, Z0 q# O/ [( g# @- @& [
**
1 X! h7 v- M& W9 l: M" X** test.c
# @5 x! J  o1 t% Q% e( T' T5 A  y& |**
" V: f; i7 Z7 X" Q# f0 u, V0 Y** Description:
$ Y" C) t" s. f**     Contains Unigraphics entry points for the application.6 B2 k- S6 J2 {* _6 q
**
! z- A( {5 M5 {! J/ z: R*****************************************************************************/: \5 J. Z9 g7 |' c
/* Include files */
( B/ n: z3 G- }4 \, r#include <stdio.h>5 A. I, U1 Q0 A/ z, ]$ }+ w
#include <uf.h>
5 n3 `1 T  p. _#include <uf_ui.h>
" M$ [! R0 a# s. K4 \; b& y2 j) W, j#include <uf_modl.h>/ B3 g: j& W/ k/ J
#include <uf_curve.h>2 ?5 J5 g& i4 l! _5 m
#include <uf_part.h>
  [6 C# z* U9 |7 i/ {#include <uf_modl_types.h>
1 O% {1 E! W  z7 J#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
$ D* H& @. }  x" K) Ustatic int report_error( char *file, int line, char *call, int irc)( `9 p, S) Z0 y, F9 L  s3 S, s$ A
{
9 n6 p& W3 B5 F' T    if (irc)
8 ?& o& Q. O3 p$ i- Q    {! C0 ^+ A0 W0 u' }
        char err[133],
  ^: r" S$ I( }             msg[133];
. K4 n( l- u5 j& A7 y$ a        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",& q# V9 S: v4 K- N
            irc, line, file);3 {  T% \% p4 S! m7 P
        UF_get_fail_message(irc, err);
+ ?6 _! V3 p! c        UF_print_syslog(msg, FALSE);
4 d8 E0 \- j0 \7 Z        UF_print_syslog(err, FALSE);
% U1 ]9 v# \) y8 u) q        UF_print_syslog("\n", FALSE);9 q6 {% Y1 J" @2 N" e5 |. D6 y
        UF_print_syslog(call, FALSE);
: B& s6 V$ l" y* J6 o; M        UF_print_syslog(";\n", FALSE);7 K- S- x3 D+ L  u( J1 H% @5 \
        if (!UF_UI_open_listing_window())4 {; Z, y( U+ ^6 ^/ F) r
        {
$ [3 a' r* _& b8 @, Y  |  S            UF_UI_write_listing_window(msg);
8 u* w3 k( }# B( V% O            UF_UI_write_listing_window(err);: H1 S0 d7 k: i5 t$ }% O+ `
            UF_UI_write_listing_window("\n");
& N1 g8 I6 ~; T8 B% D" {1 B            UF_UI_write_listing_window(call);
. Q4 k( n; r1 V4 E5 \6 w6 Y            UF_UI_write_listing_window(";\n");
* N: o8 v( R1 _) ]" g        }
% z: b! g& J$ t+ r: v- |    }. r) M( Q+ r& l8 V8 J
    return(irc);. [2 f$ F) j0 s4 W* M4 b: z& D0 b
}6 g* F9 o- p0 j- y+ M
" S! [+ d( w& m: [
/*****************************************************************************
3 c" L- Q& G9 n! T/ ]**  Activation Methods9 l7 y6 f, B. `+ D
*****************************************************************************/
1 S7 P! ]! m# \5 }1 w/*  Explicit Activation/ D; P! }2 T4 f# H& t* {
**      This entry point is used to activate the application explicitly, as in0 S) u& Z1 }4 c. z' F3 S$ M; T' U8 q
**      "File->Execute UG/Open->User Function..." */. I+ A. A8 d5 P& {8 X
tag_t part_tag=NULL_TAG;
& Q! d% X1 |: A. c$ Atag_t tar_tag=NULL_TAG;7 q7 D$ f% d) L" h$ J2 a
double origin[3]={0.0,0.0,0.0};
; M  p, l& ?  b7 ]) r$ o3 @+ [char *height="30";
+ s& e: C; r3 Q* D# L5 f# u! vchar *diam="100";& ~3 x3 G( w8 M  c! T: ?' K' e& L
double direction[3]={0.0,1.0,0.0};
2 C) V6 P% W' N0 w' W: jtag_t cylinderfea_tag=NULL_TAG;
. g% E7 f! R& S) quf_list_p_t edge_list=NULL;
" X8 X, V9 Z5 s9 {" n) D# ?int edge_count;& g6 j7 s8 `. ?4 o3 Y9 D- G2 b* L
char msg[256];
. u) S0 l" P' @7 cint i=0;
1 S: O% [5 a8 T2 Qtag_t edge_tag=NULL_TAG;
9 T, ~2 ^9 t; Z4 Dtag_t curve_tag=NULL_TAG;
+ F. H% B/ o" K* Qtag_t point_tag=NULL_TAG;' c6 c6 R3 }) ~4 t  U7 G
tag_t line_tag=NULL_TAG;/ ?0 Y: ~0 C  s. I
tag_t point_tag2=NULL_TAG;
8 D: Y7 A0 u4 q# Sdouble cen[2][3];
) E5 Q' V; A4 |UF_CURVE_line_t line_coord;//最好不要定义为指针
- }  ]8 D8 y; h+ Dextern DllExport void ufusr( char *parm, int *returnCode, int rlen )
) N' }, ^4 _6 @: _8 B{
% O7 ?2 b/ Q4 q    /* Initialize the API environment */
# c/ G' c) `* m    if( UF_CALL(UF_initialize()) ) 1 i5 r! ?: M/ k! s9 W
    {
, V$ o7 S" ]" j5 @( i/ }. P0 c        /* Failed to initialize */% Q1 _- }$ u1 @! I  Q& k( {* w
        return;
5 @) E5 H: r6 x' Z    }
; P5 O( k4 p% @$ t: {! M. H! c8 L   
2 B; N, T5 y( ^( Z' q6 |2 v* u    /* TODO: Add your application code here */7 H8 O% a1 ~* v& s$ f2 O0 X" i
//1.create a new part0 \, U% i: i- w5 C
UF_PART_new("C:\\NX_work\\cylinder.prt",1,&part_tag);" Q! @& p( Z$ C& a# x+ X$ `
//2.create a new cylinder0 g# v, B  r" {; l9 c& H
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
, g2 x& f# k2 B' Z+ a //3.get the edge list$ g' t  h. k3 {6 s
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);) h$ X' E; ?* R+ A" d& D
//4.get the edges+ z$ a- {0 u2 `# ~+ O  I
UF_MODL_ask_list_count(edge_list,&edge_count);
; P7 h. m' h3 L8 y1 s" R' ?
) ?7 D9 R* {2 t* Y# V //5.get the centers
  {8 |  ^7 k: B6 \1 s& q) a  u for(;i<edge_count;++i){- S% V1 S6 i% V* R: ]8 y, k
  UF_MODL_ask_list_item(edge_list,i,&edge_tag);
7 ]* Y" \: G7 X: _" d. G  //UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
" y& m. i2 D+ ]8 `/ w7 P0 J  UF_CURVE_ask_centroid(edge_tag,cen[i]);
4 Q8 l/ U, r& t9 w- [8 `; C7 D }
6 s1 {6 x0 @% {7 P0 g" g# ]! m //6.create line
, M# h' P; Z5 C$ U //UF_CURVE_create_point(cen[0],&point_tag);
4 m8 [+ B7 V* S2 w! a* k5 L //UF_CURVE_create_point(cen[1],&point_tag2);
; r' N% c0 O# _, @, E line_coord.start_point[0]=cen[0][0];, @0 G6 S  e/ @( ~/ Y1 {" f: o, @
line_coord.start_point[1]=cen[0][1];/ n; {6 I0 ?; Z* ?7 d3 j* d
line_coord.start_point[2]=cen[0][2];+ K/ \: B7 w2 g  [
line_coord.end_point[0]=cen[1][0];
4 @& i/ s% z1 `9 H$ T% h- d% y$ ~, v- d" m line_coord.end_point[1]=cen[1][1];
  G  B$ r, M/ f" ]+ A line_coord.end_point[2]=cen[1][2];# M- H: |/ X" Z
UF_CURVE_create_line(&line_coord,&line_tag);
" z! Y; A9 [% \0 {2 B4 X //UF_MODL_ask_list_item()
( A2 Z+ J6 k6 U" U0 {2 L+ I& u    /* Terminate the API environment */
' @, `' h$ s6 O    UF_CALL(UF_terminate());; n8 p! ^7 x2 @& I, Y
}& P- k! |* w( q" Y1 V
/*****************************************************************************
0 R! ?3 K) G9 X" {**  Utilities
5 E* s5 d9 f3 E6 `8 v*****************************************************************************/5 M6 A$ O7 E+ m- q$ ?
/* Unload Handler
% }: K5 m8 C$ J) D) }**     This function specifies when to unload your application from Unigraphics.4 c+ q9 v0 a0 N+ p( V' h. x! i
**     If your application registers a callback (from a MenuScript item or a
3 f* A& G/ Y8 `% W, y: z$ b**     User Defined Object for example), this function MUST return6 C5 d* }" e  w6 K9 {
**     "UF_UNLOAD_UG_TERMINATE". */6 Y( }+ J- n( d+ z/ C  D. k7 x
extern int ufusr_ask_unload( void )8 E+ @5 L; \# x) u; p1 e5 u
{6 {* q  a8 ?$ d) d
    return( UF_UNLOAD_IMMEDIATELY );# D  P. X* z+ q) R( d
}9 J  m' y8 T; O8 _3 D
2 ~9 u. p$ ?7 Y0 u  ?

评分

参与人数 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之家站长

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

    我知道了