PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2015-8-22 12:47:05

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

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

x
# U5 D* Y/ _. _; O2 S  m, i5 y, [
Dimension* plmhome::select_a_dimension()
9 o9 R* \: I" {{
  m: G" A! D/ L* s9 w' @( {7 P    // ask user to select a label# w- I  ?; D* l2 W4 v& V* Y
    UI *ui = UI::GetUI();
+ g/ M0 y; ~6 ]# [, W4 h    Selection *sm = ui->SelectionManager();
5 ~8 ~1 x1 T2 }, a' g3 M    NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
& U) t5 g; a0 |" P
/ f8 d) }3 Y. d" N- ~" m    NXString message("Select Dimension:");
7 L  D! g5 E3 p( [6 I% ]9 s    NXString title("Select Dimension");
% e9 i8 I! a; m0 N. ~; K    Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
$ g) m4 {) U* T" Y8 z    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
' @( r1 _- G  h3 }- L& W    bool include_features = 0;
. i$ m1 n* G4 I* R7 `6 a    bool keep_highlighted = 0;
$ n8 ]0 U6 Y' V1 i( Z% s. P2 X. h7 q1 `5 M, \
    // Define the mask triple(s)
7 y9 Q5 y2 ~) E+ B% r    std::vector<Selection::MaskTriple> mask(1);4 y4 v9 {  E+ `! T! P& j4 [- p
    mask[0] = Selection::MaskTriple( UF_dimension_type, 0, 0 );$ K) f: l( ~$ e/ d* `& |
    Point3d cursor;- n! r/ r* w. T& k9 M6 v' o; [
    TaggedObject *object;/ G- D4 q7 X% K. G4 H, d$ B" f
, ]8 ?2 ?+ B; P5 @
    // Select objects using filter defined by mask triples' G; c; F) U+ r/ M( u+ q
    Selection::Response res = sm->SelectTaggedObject(
8 G$ @6 ~- t/ Z4 a( h4 U# G        message, title, scope, action, include_features,
; g8 d* c5 a5 }/ j9 x            keep_highlighted, mask, &object, &cursor );; @" b* q  u, @* ?# W
7 R3 E7 S. i" S- H) H2 e( ]4 n
    if( res == Selection::ResponseObjectSelected )& \. Q  R3 _4 R% |4 A  f* `
    {
8 d% l/ s$ A1 l% z        Annotations::Dimension *theDim;
) }$ f! I6 c1 G: f
0 K) ?# t7 m1 _" \        // this doesn't work and 'note' will be a zero pointer, see PR-1850850
; `: A- t, ?$ R; }" h        //note = dynamic_cast<Annotations::PmiNote *>(object);
7 Z9 A% x* J! ^! |5 @) Y! c( j/ E/ X$ x3 K& [& Q  t/ P
        // this works as a workaround, y: C/ K- e1 \/ u8 J# |/ T
        theDim = (Annotations::Dimension *)(object);
4 O' h. A% u, ]% f' ]$ I% m  b        return theDim;
5 C( A8 r0 t" L! t    }
6 v/ q4 W2 `, N$ H+ K% @- X  d( D* S8 P' ~+ U. _3 @! C
    return 0;
$ o$ k! J- f, {2 k7 L0 C! I}7 E  @8 {  y. h, W  E/ d! G
, I" [5 P3 n1 Q  _" X8 T7 t
/ a+ ~6 y: f3 Z+ j: v; b
! g1 f4 y4 y& m; S3 q5 @

5 F3 |& e. A& h6 ?; ?2 Z- qvoid plmhome::do_it()
- x' y: y! j9 T  {, A# q{7 n% l5 Z1 }4 t& Z
    workPart = theSession->Parts()->Work();
! y+ ]: a9 b% E! w- |" V2 U3 b    Part *displayPart = theSession->Parts()->Display();
: V% j) u. ?3 n) V2 [    stringstream out;
+ r5 ?! C8 f) k* M* A    Dimension *theDim = 0;
( X$ u* P! D* Q( j
, o0 ^. i  z8 C0 s' F2 d5 a, l! f" P. P    NXString tolTypeStrings[] =
0 {; E/ Q: u+ _. `8 {# t0 y    {/ x$ U* y; o$ [' S2 ?8 l1 r0 S
        "ToleranceTypeNone",
$ C- u2 Q1 c; u        "ToleranceTypeLimitOneLine",
: z, F5 v; ~5 M, J& D: h        "ToleranceTypeLimitTwoLines",
) b( L7 n4 Q* p3 E5 S8 m& g        "ToleranceTypeBilateralOneLine",
( d+ F4 S- W2 r& G2 W9 f        "ToleranceTypeBilateralTwoLines",
; u3 R' V4 s' [        "ToleranceTypeUnilateralAbove",
! b4 }. t- a0 Z2 r        "ToleranceTypeUnilateralBelow",
6 }8 r- }( w9 U4 |( G        "ToleranceTypeBasic",
. r) {( Z1 Y. M# n+ x        "ToleranceTypeReference",% }# g" p0 e1 R! U5 H. z
        "ToleranceTypeLimitLargerFirst",6 U' t/ f3 {# F& S: J
        "ToleranceTypeLimitLargerBelow",6 |; V6 C/ h+ W  _
        "ToleranceTypeLimitsAndFits",) J) ]. U1 H4 _2 I9 S
        "ToleranceTypeNotToScale",/ u7 X! p- K9 |; ]7 p
        "ToleranceTypeDiameterReference",
6 k  X5 I! g. X3 I$ O, H% u9 L        "ToleranceTypeBasicNotToScale" , A7 N6 g: G: W% ~( I
    };
& M- N8 `9 B& S( p& T$ a0 a. B' Y, ^( }% ~) h
    while( (theDim=select_a_dimension()) != 0 )
/ F1 Z; j7 h% S+ w# \* _    {% b7 c5 x$ Z0 B& a9 f: T# k
        out.str(""); out.clear();
9 K1 k* i/ t+ X        if(! lw->IsOpen() ) lw->Open();
5 q5 m' A* [% ?- A2 ?4 m2 l+ X: F. H9 O$ n( i
        out << "Selected Object: " << theDim->Tag() << endl;
9 H1 v) Z- s* l
9 y' |# U2 q! X; G! C, t        std::vector<NXString> mainTextLines;
* o4 m6 B# h0 }; @: X        std::vector<NXString> dualTextLines; & H( @% Z' u) B
        theDim->GetDimensionText(mainTextLines, dualTextLines);
1 k5 x/ [3 a% x* j; S9 Z9 Z7 p; m        for( int ii=0; ii<mainTextLines.size(); ii++)
' m6 Z4 x: J7 v4 o7 d9 T            out << " MainTextLine: " << mainTextLines[ii].GetText() << endl;! ?* C9 @$ l+ s8 p8 i: j
        for( int ii=0; ii<dualTextLines.size(); ii++)1 u) p2 k& a6 B: Z7 E" Y
            out << " DualTextLine: " << dualTextLines[ii].GetText() << endl;
. D( |  z% l; G7 S8 z) W% y# n7 o! u; I, b3 C+ x
        bool refFlag = theDim->ReferenceDimensionFlag();
, I+ t8 D/ j8 q        out << " ReferenceDimensionFlag: " << refFlag << endl;
- Q. g# x2 |4 Q/ T8 E7 \& c2 M+ e% Z. T3 q9 d
        int tolType = (int) theDim->ToleranceType();
) ^& U  U, [( r0 |) O        out << " ToleranceType: " << tolTypeStrings[tolType].GetText() << endl;4 E/ @1 f' z3 Q5 v: r7 Y5 Q' Q) ]

* b, N* m. w6 ^' m: ~$ @- ?; G; q; |1 P        ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);
8 q# a* o% q5 [$ j        std::vector<TexTComponent*> textComps = theData->GetTextComponents();
/ c% n5 S6 [9 g- Y* _# N* k) B        for( int ii=0; ii<textComps.size(); ii++)( k7 D1 d% `* @5 V, v! E9 j
        {: m  y; Q# U6 N# _" W
            std::vector<NXString> compText = textComps[ii]->GetText();
; d! X, e5 U+ A            for( int jj=0; jj<compText.size(); jj++ )
) b9 n- ?( Y0 q6 X3 k( @. i& M                out << " Component Text: " << compText[jj].GetText() << endl;5 }5 J" c6 C, W. v
        }
& v/ w# j8 X" ]% t2 a; E9 c( _* z  {" v: @) b& r" i- n" |
        int subtype;* ?# A: ]; G. k; Z+ O
        double origin[3];7 \  p$ c6 A3 K5 F
        UF_DRF_dim_info_t *info;
8 U( V& O1 Q1 U5 L9 @: ~* u        UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));
( G% E/ G" {2 R        for (int ii = 0; ii<info->num_text; ii++)' h" w- s% k! ?1 r  h
            if (info->text_info[ii].text_type == UF_DRF_DIM_TEXT)# u/ j3 a5 p2 C
                for (int jj = 0; jj < info->text_info[ii].num_lines; jj++)
% \8 A: D. M' g- {                    out << " UF_DRF_ask_dim_info Text: " << info->text_info[ii].text[jj].string << endl;
& J1 ~1 Q3 r3 J+ }        UF_CALL(UF_DRF_free_dimension(&info));2 B! H4 X0 R3 w$ o8 g

8 g( J& X$ |. c" N0 J        lw->WriteLine(out.str().c_str());( G& S/ n9 r( M3 `

4 U; V  y, d; j3 v+ p; T+ I    } // while- w# ^" `0 J& I: a* H1 s$ H
}
: ?0 _, c" l( _7 y# l( Y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了