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

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

[复制链接]

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

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

admin 楼主

2015-8-22 12:47:05

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

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

x

# B" K  \3 ?7 o0 bDimension* plmhome::select_a_dimension()
8 |3 s) w7 H! u) V1 B0 c{* P% ?  ]; f8 D2 w7 F, Y
    // ask user to select a label
' J5 q( m/ w4 A    UI *ui = UI::GetUI();# w3 B2 s% D( |  M9 @4 F
    Selection *sm = ui->SelectionManager();1 J3 ]/ P* g) F/ v4 Y
    NXMessageBox *mb = ui->NXMessageBox(); // as of NX5* c( M: a1 `* q' {2 R+ S) W' k

  R; n8 O8 M1 b" ~0 r+ }2 ?( j' q  G& g    NXString message("Select Dimension:");
3 n3 W- `& Y; S" T- c    NXString title("Select Dimension");9 J% f! v: u# i- s
    Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;; f* l6 f1 B" }
    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;( }/ @6 Y: T9 D$ w
    bool include_features = 0;& ~5 \0 S5 c( O0 l! E( V+ J
    bool keep_highlighted = 0;2 ]: ~7 U/ d' y: p0 M) I7 X
7 Z. f; d7 M5 R5 x$ a
    // Define the mask triple(s)2 x0 V4 m1 L0 S: i5 I! y
    std::vector<Selection::MaskTriple> mask(1);; }+ k$ s* v  W( w
    mask[0] = Selection::MaskTriple( UF_dimension_type, 0, 0 );
" l$ o: `$ F3 ?2 r    Point3d cursor;
" e8 j/ X; u5 G' K3 j: F( x+ V    TaggedObject *object;" m8 M' _; W, L

% g6 b  S- B$ N1 z, e; m! q    // Select objects using filter defined by mask triples( l( M  |* v; V) _  @4 D
    Selection::Response res = sm->SelectTaggedObject(' v9 A  b0 G! J: h# {
        message, title, scope, action, include_features,
4 l( D) Q' N) B0 W$ i            keep_highlighted, mask, &object, &cursor );
. @( T1 d1 K4 T( ^: \
- `  [# n3 Q' U' J    if( res == Selection::ResponseObjectSelected )/ Y  p) G' U5 X9 a4 s4 q* q' q5 t# k* {* ]
    {! _0 _4 C8 k3 V( F2 S1 l/ k7 p+ u! i
        Annotations::Dimension *theDim;1 j5 R1 x, H% Z; B, }' e) @% Q
! i( P, g% ~7 _/ u- w
        // this doesn't work and 'note' will be a zero pointer, see PR-1850850! k9 Z- L5 v. Y8 M' P: O
        //note = dynamic_cast<Annotations::PmiNote *>(object);! p% H2 _; ]* d/ f
, L' l# H" q' ~3 d2 s4 @& e9 L
        // this works as a workaround
6 Y$ a( \) p; k5 B        theDim = (Annotations::Dimension *)(object);
2 ~+ y- q: V% n& Y        return theDim;4 h0 s& D) k6 u4 Y. P+ [
    }* P/ E4 O" s' o" U0 O
0 d/ i- h% c& Q
    return 0;
' ~3 j* S5 R4 ?' ^2 Q( Z6 ?- p}
0 ^0 `5 d2 R+ a
, @  I& @6 d/ |) z. r# \  q7 U  a
& J! ^6 N4 p4 h3 K% N
- D$ `% |7 l+ _0 g/ g  I- D
void plmhome::do_it()
$ E7 p) f% W/ h- C. a) T( t{
! w, G$ G8 l3 F, ~    workPart = theSession->Parts()->Work();  I0 T" z5 {. |0 j. e- q3 z
    Part *displayPart = theSession->Parts()->Display();8 Y; s$ z1 n5 F6 C5 g$ x, @5 O
    stringstream out;% G; A6 o% l4 R6 f
    Dimension *theDim = 0;
- p+ X+ d0 `/ y. b+ J) Q% k# c
( i1 y, S3 z* s    NXString tolTypeStrings[] = & K' Y* K# F3 R1 q2 K
    {) |$ @7 A( p8 i) u
        "ToleranceTypeNone",
8 l! F4 K5 v7 a7 K, n        "ToleranceTypeLimitOneLine",
0 c6 G' [! S% X8 ]6 N        "ToleranceTypeLimitTwoLines",
. I, h) i, J( z        "ToleranceTypeBilateralOneLine",
+ O7 C4 m5 ]; u4 p' X$ s8 ]' [        "ToleranceTypeBilateralTwoLines",
4 Y! W2 y+ u: }: n) ?, T' v        "ToleranceTypeUnilateralAbove",
- Y3 `8 H" B7 l  O( i        "ToleranceTypeUnilateralBelow",) F) W$ W* n& g0 o  b' c8 q
        "ToleranceTypeBasic",6 H3 W5 ^0 A3 W+ N6 S* {
        "ToleranceTypeReference",, C5 q- g9 v* Q# S8 G& `# Q* ?
        "ToleranceTypeLimitLargerFirst",
% j: ]% }- t2 |" X$ q% |9 T3 U        "ToleranceTypeLimitLargerBelow",
' ~4 z+ N9 z& `/ ?- {3 m- M! y        "ToleranceTypeLimitsAndFits",# X  X5 X+ k" m0 m
        "ToleranceTypeNotToScale",
5 |  k+ C3 t7 [1 h        "ToleranceTypeDiameterReference",
) X7 Z. ~8 @5 _        "ToleranceTypeBasicNotToScale" * g. M8 R# K6 Q( j% }
    };2 S; s4 \( n7 @8 f

- j* Q9 j! B4 j6 Z  V% Q" |/ }    while( (theDim=select_a_dimension()) != 0 )
  d( }2 x7 D9 l8 ?' G% {    {
, G3 J. s7 M1 I5 [$ F        out.str(""); out.clear();
$ d8 c8 l) S; s/ g, E1 J8 ~7 U        if(! lw->IsOpen() ) lw->Open();
  M" K. C  p4 @7 c) f. a) p
6 ^3 q5 |+ x0 f  U        out << "Selected Object: " << theDim->Tag() << endl;0 {- p/ ~5 e9 e9 x4 g; ^
4 E1 z3 _# I5 D
        std::vector<NXString> mainTextLines; ' g+ I. d. u+ M4 Z1 C# {
        std::vector<NXString> dualTextLines;
+ _/ c; o9 u. |/ [$ P8 j) B& ^: q        theDim->GetDimensionText(mainTextLines, dualTextLines);2 h% S) H3 O1 |* K
        for( int ii=0; ii<mainTextLines.size(); ii++)
  {% r/ q8 W3 q2 K+ r            out << " MainTextLine: " << mainTextLines[ii].GetText() << endl;
6 P& c& a! w- O3 }/ G# B+ r. g        for( int ii=0; ii<dualTextLines.size(); ii++)* u9 I) q  i; V! V
            out << " DualTextLine: " << dualTextLines[ii].GetText() << endl;
5 g6 M" T3 x9 B+ [5 M* j: p
$ i3 L2 k* E7 ?1 Y        bool refFlag = theDim->ReferenceDimensionFlag();
3 [+ K- z: s1 \& m7 l        out << " ReferenceDimensionFlag: " << refFlag << endl;
; S8 ?6 s- k' z! M  W1 F6 R0 s' ?4 M9 ?) E& z) t
        int tolType = (int) theDim->ToleranceType();
$ z' |4 @3 `9 I        out << " ToleranceType: " << tolTypeStrings[tolType].GetText() << endl;4 Y' W/ [' W+ W0 j! _- `% r

# o% h- Z( P' r        ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);
" g4 k7 e. m- h+ {; o5 K* e: B: ^        std::vector<TexTComponent*> textComps = theData->GetTextComponents();
" `  K( [3 X( C5 q; ?5 D0 [+ {        for( int ii=0; ii<textComps.size(); ii++)) I( f* m! I, b. k' [
        {% V* Q' N+ N* e+ g$ a6 F
            std::vector<NXString> compText = textComps[ii]->GetText();
. `% u, y7 w5 F; N4 C            for( int jj=0; jj<compText.size(); jj++ )
+ y% X5 U7 w9 r: _: I                out << " Component Text: " << compText[jj].GetText() << endl;' A( k3 d% r8 M
        }
) |4 {  Q' l0 h& Z0 N5 }. J" q1 |
0 T3 t: w, R. O# q5 q        int subtype;
5 k" A$ a  U/ t        double origin[3];; i0 b% r+ D4 n5 x7 Q* P3 j
        UF_DRF_dim_info_t *info;5 R! p, P0 d5 |7 L7 X' E
        UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));# O3 |' R- l+ o
        for (int ii = 0; ii<info->num_text; ii++)
2 `0 W; j( _8 q% I            if (info->text_info[ii].text_type == UF_DRF_DIM_TEXT)
5 x0 x9 e7 [2 [. Q3 j0 }0 a                for (int jj = 0; jj < info->text_info[ii].num_lines; jj++)
/ D! d. Q/ N- q                    out << " UF_DRF_ask_dim_info Text: " << info->text_info[ii].text[jj].string << endl;9 D6 c" G! W: w5 c# u7 F* k2 `
        UF_CALL(UF_DRF_free_dimension(&info));
( |0 K( D0 L4 l2 x( x$ K$ g* z0 ]' d% g
        lw->WriteLine(out.str().c_str());% Y# ~: p( H( n$ \3 z& W' ^

6 [/ J* \* j* m/ J1 G    } // while- T  w, R1 c7 `3 y
}8 i" L: D5 |9 X# n( _( y$ ^* h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了