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

[二次开发源码] NX二次开发源码分享:报告选择尺寸的相关信息

[复制链接]

2015-8-22 12:47:05 3445 0

admin 发表于 2015-8-22 12:47:05 |阅读模式

admin 楼主

2015-8-22 12:47:05

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

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

x
' H% G( {* B: X, o# I- E
Dimension* plmhome::select_a_dimension()
' B& J, G1 H8 h{
+ x- X2 t" x( J* b2 z    // ask user to select a label/ Q3 I7 d9 Q) _' y2 e
    UI *ui = UI::GetUI();
& r) N3 Y: g" x: ~& R    Selection *sm = ui->SelectionManager();
- ~. t4 q1 t& V4 m+ g0 z6 {    NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
+ G+ y7 n; D5 c2 `+ _: r5 W/ {0 Z+ O% J  @9 p& H/ g+ s
    NXString message("Select Dimension:");" @$ J% e$ i9 @; A
    NXString title("Select Dimension");) A! ?. d* `1 k
    Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;, `$ E1 i; f' |( ^* D6 b
    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;$ C; f7 ^" z3 e* R5 w; d9 l% ~
    bool include_features = 0;
! I. f- I. a. Z* A    bool keep_highlighted = 0;' h! u5 R& O% Y& ~1 y

$ t  g% p7 s2 _  x& d; c    // Define the mask triple(s)
  B, m3 a. `$ J& p6 ]# n' U    std::vector<Selection::MaskTriple> mask(1);
/ j- d: b3 h0 j, Y% o7 `8 j    mask[0] = Selection::MaskTriple( UF_dimension_type, 0, 0 );, x8 n8 D4 g- c4 C! Y' Z  t
    Point3d cursor;
" T7 j+ }/ M3 Q& G; R' h5 E; u    TaggedObject *object;1 A' x5 I7 V, w, R

/ c, y( l% a4 `$ Z+ K1 Y9 d    // Select objects using filter defined by mask triples
8 z8 ?- K' R! @% z7 @    Selection::Response res = sm->SelectTaggedObject(& M: p1 w) `& B( g
        message, title, scope, action, include_features,- V4 s* i4 y" G; J2 \3 Z
            keep_highlighted, mask, &object, &cursor );
  M/ w. k  S. u+ a7 W4 P2 J+ m: ^8 R/ F% l- d% R
    if( res == Selection::ResponseObjectSelected )
" Z! D# l$ V; n* p& x* G7 I2 I- t    {
) i- {6 M  K: b! P" ~        Annotations::Dimension *theDim;
! ^) a8 L5 P* D4 _! a' f, O
8 x/ c" ?' n" a" K        // this doesn't work and 'note' will be a zero pointer, see PR-1850850) p- r2 g* B, _+ Q
        //note = dynamic_cast<Annotations::PmiNote *>(object);
) Y, L4 u9 ]4 f& J& w$ U% G) m/ C7 L4 v4 T5 Q
        // this works as a workaround
' d7 ?9 k9 Q/ A  D9 V) {        theDim = (Annotations::Dimension *)(object);8 h6 P3 q% {" }! l
        return theDim;7 x0 B2 }4 f$ B/ b
    }
. B0 M( `/ J) P0 S& e1 K
" e6 y3 ^* F. c! H2 V    return 0;4 l9 Z- E; d9 r$ U; ]5 r0 ~# z+ L
}( X, |' H5 ^& l

3 B' W" r4 f6 Y4 g0 r* n4 g. I& j  H+ m1 ~% [% r
2 m& p' L- {# n+ O
+ V% r) l8 ?) Y/ ~' A
void plmhome::do_it()  D5 ^& v6 S9 Q# W8 }' v9 T
{+ m( x% C8 L3 ~& [
    workPart = theSession->Parts()->Work();
4 d7 d* m  i+ P8 I    Part *displayPart = theSession->Parts()->Display();; h# G* Q1 J7 M9 u
    stringstream out;
6 a* u: K# `5 N9 i: U# U    Dimension *theDim = 0;# |: o: P7 K: Z
' K  B* [  {- m7 b, h) Q9 V
    NXString tolTypeStrings[] = # e4 {+ d6 e/ Q7 n
    {
4 j3 t/ v2 i7 A2 V        "ToleranceTypeNone",
  M9 z0 {/ X1 [        "ToleranceTypeLimitOneLine",
$ e) C6 P* P9 M' o) Q2 P) M        "ToleranceTypeLimitTwoLines",
: f, }" M. b3 |" c, S        "ToleranceTypeBilateralOneLine",4 p" Z! ]) \3 [% i" `
        "ToleranceTypeBilateralTwoLines",: ~0 t( M% U. t- ?
        "ToleranceTypeUnilateralAbove"," U5 j7 j; v& q' ]
        "ToleranceTypeUnilateralBelow",
- q. D+ W+ G$ ]$ [7 J2 {        "ToleranceTypeBasic",
: j3 l7 ^) }8 g/ L        "ToleranceTypeReference",' s9 Q  p+ J- X5 u5 j' d
        "ToleranceTypeLimitLargerFirst",
8 t3 Y/ t% U0 z        "ToleranceTypeLimitLargerBelow",' c7 O1 a9 |+ d  v6 b9 I
        "ToleranceTypeLimitsAndFits",( h0 ^, A& d% E5 B- q
        "ToleranceTypeNotToScale",$ f8 _+ [% S! b2 A. u
        "ToleranceTypeDiameterReference",
5 ]' X( K, }1 b- I" H+ u        "ToleranceTypeBasicNotToScale" 6 x8 I) L0 p- @" C! @
    };$ h6 V4 O, X& j) {, A
1 h( _5 d- o& R3 p
    while( (theDim=select_a_dimension()) != 0 )7 c! @% k7 W( q0 C
    {3 t0 @0 K  |0 K5 e/ n- \, A
        out.str(""); out.clear();% q$ Y% b$ h& a" N
        if(! lw->IsOpen() ) lw->Open();
7 U/ D. ~! B' B; A
* _  T7 `# x2 ?        out << "Selected Object: " << theDim->Tag() << endl;6 W' ~# A2 K  d2 u6 p' m

  W4 V6 K6 k& ^# h* J# [! t/ y        std::vector<NXString> mainTextLines; # ?& D% G: B6 L
        std::vector<NXString> dualTextLines; ! a) Q. S! g9 {1 C6 Y: t. |
        theDim->GetDimensionText(mainTextLines, dualTextLines);7 ~9 g+ G5 Z2 U, r/ P/ z
        for( int ii=0; ii<mainTextLines.size(); ii++)1 A5 E6 z2 ^" `+ w+ S* q0 x6 d
            out << " MainTextLine: " << mainTextLines[ii].GetText() << endl;
8 B( F+ l/ _4 \8 m        for( int ii=0; ii<dualTextLines.size(); ii++)
, M) ~! y* P) w) w: v& |- i            out << " DualTextLine: " << dualTextLines[ii].GetText() << endl;, I+ U3 ~% b3 }" D3 V4 _

4 A, a6 P3 c% A: e        bool refFlag = theDim->ReferenceDimensionFlag();
1 {  t% `- ?7 [4 U. `1 f        out << " ReferenceDimensionFlag: " << refFlag << endl;
- N! j' F; r- c- m. z0 G( D& ^5 ?9 q) e" @  }8 _: {" m, z+ z0 J- r
        int tolType = (int) theDim->ToleranceType();1 p0 k4 L% w7 C( @0 T- J6 j$ m
        out << " ToleranceType: " << tolTypeStrings[tolType].GetText() << endl;  e9 v8 r5 S( |! U
9 f6 F% h  G/ v# m2 ?( O3 C
        ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);0 R+ V+ n5 o9 ]. e9 u0 r
        std::vector<TexTComponent*> textComps = theData->GetTextComponents();7 P9 S# m5 N9 P: g+ P. s
        for( int ii=0; ii<textComps.size(); ii++)4 Q( M9 V, O6 {3 ~! s4 b0 a
        {) h+ Q" j$ _. d2 e5 d" ]: u1 z( D
            std::vector<NXString> compText = textComps[ii]->GetText();# }6 u3 @0 m' w7 N6 o# S$ l
            for( int jj=0; jj<compText.size(); jj++ )9 G% w8 j2 R# R, J
                out << " Component Text: " << compText[jj].GetText() << endl;4 K# v8 F" O) ]3 |# D5 b
        }, k( n2 e1 T0 x8 b8 g7 O
5 d% o: ^% z- q. J4 ?2 Q7 y
        int subtype;6 _# E' b" f1 X: z( v
        double origin[3];
5 `5 E& q1 f( C+ Z" [        UF_DRF_dim_info_t *info;! X( M% U) K& T$ G9 p
        UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));
# J* x9 k" B* N% T        for (int ii = 0; ii<info->num_text; ii++)& e+ m2 }4 y* \
            if (info->text_info[ii].text_type == UF_DRF_DIM_TEXT)% {. Z5 p. e( R# n* U+ O
                for (int jj = 0; jj < info->text_info[ii].num_lines; jj++)
8 V: v! C& s. e/ s# {0 ~                    out << " UF_DRF_ask_dim_info Text: " << info->text_info[ii].text[jj].string << endl;2 N4 }, d8 l! h. C9 w( _
        UF_CALL(UF_DRF_free_dimension(&info));
6 e" H9 T9 N9 ^9 [# h) ~% F7 j
. q+ V6 a! n8 R7 g; Q! g9 W7 V        lw->WriteLine(out.str().c_str());
( Y. [/ T  M6 O& C( l, |1 r
" f7 k# t. a! W$ _/ o    } // while7 m, p7 m3 g; r/ n) H( ~
}
) R5 o3 n" u! L# o* l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了