查看: 4873|回复: 4

[解决] 用UF_UI_create_filebox()时UG崩溃了

  [复制链接]

4

主题

4

回帖

83

积分

培训VIP会员

积分
83
发表于 2015-5-1 11:53:07 | 显示全部楼层 |阅读模式

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

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

×

" @/ D+ ~2 Q% Y4 m# `/*****************************************************************************  p2 k: F& Y7 o+ g2 H( q" ~
**9 n# F5 V$ F; h0 U
** createfilebox.cpp. X, M- P5 }6 |- Y' ^0 o
*** y5 Y% |" b+ h2 v
** Description:5 w2 n) n9 K, q6 w1 ]
**     Contains Unigraphics entry points for the application.
) J( @* x  `( D! }**- b6 L5 l$ c  s( x, U
*****************************************************************************/9 Q- f, l3 P$ p, ?9 _$ B
/* Include files */, h$ s3 N& E5 p9 x
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )* _% }/ j5 f& A! h. V
#   include <strstream>" X9 I/ W( `( z' x# r
#   include <iostream>/ S# W( P0 w8 N* _
    using std:strstream;0 N0 t# e% Z% x
    using std::endl;    " W% j. z6 Z) n  Z, R' R+ o
    using std::ends;
- ]+ p, I; S; ^3 Z) e& e9 [    using std::cerr;% Y" J' O3 v( N4 {8 `
#else
* w# _" X2 k( _2 i#   include <strstream.h>' l8 H4 W( G5 P6 B* {& F
#   include <iostream.h>
& a1 ~" S* m2 q1 u#endif
$ g3 z( U0 A* I0 ^. j# w#include <uf.h>
2 G  n0 x; m. M2 L& N#include <uf_ui.h>
4 Y# a  H. x! Q. M& l( _- J#include <uf_exit.h>
& f& @) N4 T9 \2 k( B3 b3 e4 ]#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))* [9 ~  L- Z9 P/ ^: B* R0 l, }/ D2 ]
static int report_error( char *file, int line, char *call, int irc)$ n* T/ }! m3 I
{% S; U2 g7 l5 b' M0 ^& x. \0 X
    if (irc)6 e% ?9 X: M) [( p  D
    {
& n5 n& f( c8 z; R3 ~/ i! |        char err[133],) @9 j5 G7 D$ H7 k7 J; k3 P% T
             msg[133];( O' O7 m) H4 p' A; ]* t0 C
        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",% Q# \: o: b+ Y* E  R+ \, \
            irc, line, file);
1 r5 F% Y% D- s2 a1 ], ]        UF_get_fail_message(irc, err);
: K: P$ i" u1 y2 ~5 D7 u8 u1 d        UF_print_syslog(msg, FALSE);
/ v; A/ x0 v$ F. j/ e9 q$ y0 \        UF_print_syslog(err, FALSE);
2 \3 m4 o2 j+ l        UF_print_syslog("\n", FALSE);
, K6 U8 D  |  ?' w  X& p# q        UF_print_syslog(call, FALSE);! s/ K7 A' i+ `: R( t
        UF_print_syslog(";\n", FALSE);1 G9 ]3 x3 I# _  Q1 }) D
        if (!UF_UI_open_listing_window())
+ @8 e; q9 P* C! N4 H. B1 L        {
) y9 t! J" V- s* x; T/ V# `8 D            UF_UI_write_listing_window(msg);9 C5 h: L7 B  }
            UF_UI_write_listing_window(err);
8 s( W9 h( g; p: y            UF_UI_write_listing_window("\n");& h* f7 W$ G* W! n2 K7 Z+ ~% O
            UF_UI_write_listing_window(call);
9 C& o( M* e, O            UF_UI_write_listing_window(";\n");+ c0 C- X4 U8 W* m
        }
$ R# |; \! B& c9 M. t* D& Y    }
9 ?. O$ B7 c6 L6 X( H) [0 O    return(irc);
2 t2 R1 ]% v# d! r}. T. |$ x: w! h

' C0 D( U. L2 B( f5 n6 H7 G/*****************************************************************************
1 c0 g+ Y' [* J& z**  Activation Methods
+ T/ q: R" R8 y* ~*****************************************************************************/
, `/ T) W2 V6 W: x/ d/ m/*  Explicit Activation( k, Y! u1 D/ Q6 H- Q' g* ~- w' M
**      This entry point is used to activate the application explicitly, as in
, G/ I4 j1 W6 w* \7 R" D4 a**      "File->Execute UG/Open->User Function..." */; v% D# I6 Q1 \5 L' H
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
, h$ N. o' K/ n2 V# B! a+ i{
, m* d! [& s( H4 g    /* Initialize the API environment */1 V1 g- q9 T  F: s- m! {8 C
char prompt_string[]="open file";
/ U& f  Y4 ^" ~7 k9 v4 @5 ?  c char title_string[] = "select file";5 ^3 D8 {$ X6 T; F
char filter_string[] = "*.prt";5 a" ?0 i1 A: o' Q; ^
char default_name[] = "my file";6 M: u+ H1 L3 K& N6 k, V
char filename[256];
; a: ~/ ?: o7 ?8 Y4 M7 V int response;4 x7 z& `3 g' \! P
    if( UF_CALL(UF_initialize()) )
' b& s) g2 e' f1 k    {6 k( \. R' v8 L; c$ D# \# F
        /* Failed to initialize */6 x+ f% ~! o8 q3 N0 ?# r
        return;
+ }$ ~' e  O& [$ }    }
0 i" Y/ e* s, O4 N% T    5 V( `3 Y; F1 c3 s
    /* TODO: Add your application code here */
4 d6 I  S0 J3 w$ p2 n; M$ L2 ] UF_UI_create_filebox(prompt_string,title_string,filter_string,default_name,filename,&response);//UF_UI_create_filebox
$ u, g6 i, l+ X; y    /* Terminate the API environment */4 \1 h3 J, ?' Q+ H2 S- }, i8 _' g  u* r! V
    UF_CALL(UF_terminate());
2 p9 W! ?  ]4 n7 B9 p' }}
1 g( {% e4 h) }: `! l' V8 \/*****************************************************************************9 @- e" ~0 b, }" `
**  Utilities
! G# X" Y& H( M4 _7 ?*****************************************************************************/. J0 o0 }+ y6 `! W3 r6 o
/* Unload Handler
; S$ S- L' g/ ~' t. _: b  v& {" W4 s**     This function specifies when to unload your application from Unigraphics.
/ g* n- m% S/ @8 N0 B**     If your application registers a callback (from a MenuScript item or a7 w+ y6 o* R3 g
**     User Defined Object for example), this function MUST return
* O2 K8 x: d1 n! R- W/ X**     "UF_UNLOAD_UG_TERMINATE". */
* L$ }- h  K: Nextern int ufusr_ask_unload( void )
. c) t$ R+ o! q- @! M" w: c* ~' \{
; u7 @7 e: v+ {8 E  @, s( T/ a: D    return( UF_UNLOAD_IMMEDIATELY );/ Z2 Q! w  e4 n* p
}
, ^! b; n/ i/ _# V( w6 z0 o3 l& z
1 x5 K) M0 q3 x0 A/ Z
CreateFilebox.png
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

320

主题

226

回帖

9784

积分

管理员

PLM之家NX|TC专家

积分
9784
发表于 2015-5-2 20:07:06 | 显示全部楼层
UF_UI_create_filebox 我没有试你这个
" ~! {/ Y& m( k9 a0 E  ]  ]* f6 h9 @8 c  w
不过你加个uf_call或者看下syslog 啥问题
$ p- `* F4 L2 N$ H* n# L) C
: b8 w) F) d  X2 _4 Y( f
该会员没有填写今日想说内容.
回复 支持 反对

使用道具 举报

4

主题

4

回帖

83

积分

培训VIP会员

积分
83
 楼主| 发表于 2015-5-2 20:18:39 | 显示全部楼层
mildcat 发表于 2015-5-2 20:077 G/ V% L8 ^# p
UF_UI_create_filebox 我没有试你这个 2 o5 j* t- I# l. e  G

/ A4 x0 o# Z- {1 {不过你加个uf_call或者看下syslog 啥问题
. T$ t* f' `5 H' f3 [
UF_CALL没有报错。打开文件的对话框也生成了。就是在点击ok之后,UG崩掉了。3 g* e! }3 r3 u) J+ ?3 M
我想用UF_UI_create_filebox()创建一个打开文件的对话框。UG有别的函数可以创建打开文件的对话框?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

8

主题

58

回帖

896

积分

培训VIP会员

积分
896
发表于 2015-5-5 08:31:59 | 显示全部楼层
文星和合 发表于 2015-5-2 20:18/ ?4 }3 t6 B1 X0 A7 Q
UF_CALL没有报错。打开文件的对话框也生成了。就是在点击ok之后,UG崩掉了。! n" h4 f/ \- E6 C1 P! G8 r2 z$ L
我想用UF_UI_create_filebox ...

0 U  b" ?* e' ?5 g" a! F* u$ w4 n6 d& o& l8 p. d, S
#include <uf.h>
3 ~: ?5 n9 ]0 ~2 C% ~# f3 [4 V& u  U#include <uf_ui.h>
- j7 E6 M8 k: l" M* [: f#include <uf_exit.h>; i# g: j! t. E1 p. \
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
; b" `  j: j/ z4 @& u{
3 V. [2 X, M* {9 y" x9 m* Z5 @        /* Initialize the API environment */6 o$ u# R" M4 ~$ l0 G; U  Y
        char *prompt_string="输入文件名";0 J& R$ a6 ^3 y; ^+ R
        char *title_string = "另存为";0 H, m0 a) \0 h: c5 U3 m
        char *filter_string = "E:\\+*.prt";
. T3 n6 Q1 {$ M' y        char *default_name = "OK-PRT";: R% J: |5 `2 q  E
        char filename[256];
% f, W, V9 ]5 N- S- S        int response;) S& {4 O- J8 K& U
        UF_initialize();
) @- T+ a/ P- G& x        UF_UI_create_filebox(prompt_string,title_string,filter_string,default_name,filename,&response);( M  i/ }! |$ ^6 Y) L
        if (response ==UF_UI_OK)
+ [' O7 K9 ^) z; e: F                uc1601(filename,1);$ N  B, L1 X' C5 t& z
        else if(response ==UF_UI_CANCEL)' V' C9 `# X! o. I
                uc1601("取消",1);
1 M2 z- T$ P  q- p        UF_terminate();
4 G: P0 s2 H8 A. \3 w4 w' ^; n}  x9 K) {- F! U; F  a' T6 x
extern int ufusr_ask_unload( void )! Y8 }$ z3 |8 X8 z! m
{9 C% _6 J% e5 C, X! T  A3 i
        return( UF_UNLOAD_IMMEDIATELY );4 {8 t0 b. V) c6 K. P5 l( ?
}

评分

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

查看全部评分

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

使用道具 举报

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

本版积分规则

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