PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2015-8-22 12:47:05

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

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

x

, |( J' `( ]( n% YDimension* plmhome::select_a_dimension()
8 Y  O7 H  ?3 n" s5 Y{
7 d. X8 d% n, Q6 j& v9 `    // ask user to select a label' j7 P. O$ }( W" R3 i/ ~$ i
    UI *ui = UI::GetUI();) N$ V$ d+ U  g  X) S- h
    Selection *sm = ui->SelectionManager();1 u' p/ }! m& w2 a3 p- Y4 t" V
    NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
& `2 P+ S# `; P4 P
( C! k! ?8 N$ h% J, r( L    NXString message("Select Dimension:");
& s. D% @; p: W  r' o$ q    NXString title("Select Dimension");$ f% I7 e6 C) E4 j% o) ]7 x. q( Z  \
    Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;) }* Y9 C; b1 K2 k8 ^
    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;/ ?: n4 h# s1 {; m  Q
    bool include_features = 0;3 l) K2 ^4 {7 t3 T: R' z
    bool keep_highlighted = 0;2 t% B/ M' ]) m& z+ w

/ |% J& p) P- V; f3 D    // Define the mask triple(s)
4 `% v9 D. z5 X  S7 D    std::vector<Selection::MaskTriple> mask(1);2 H& {" m) [; b% o7 T. c
    mask[0] = Selection::MaskTriple( UF_dimension_type, 0, 0 );1 K/ G9 V7 o( w* K
    Point3d cursor;2 x1 l4 ~4 E" e* x' `, F
    TaggedObject *object;
" G- T' _2 s8 t6 R2 D* T
$ v3 E" U' Z9 \! ^/ T    // Select objects using filter defined by mask triples8 E& @1 ], o. X* D2 N6 Y
    Selection::Response res = sm->SelectTaggedObject(
  ~  l8 I2 E6 j+ |, ~( _' j2 s8 |        message, title, scope, action, include_features,3 L: ~# ?, ?3 M" e' E3 @# x# R
            keep_highlighted, mask, &object, &cursor );
$ n% j1 Y/ {, T% L& c& v; d6 \) F2 @8 F
    if( res == Selection::ResponseObjectSelected )) f1 G  ^0 e! I
    {: \0 Z+ J% r2 H7 \1 [8 f5 B! y
        Annotations::Dimension *theDim;- U* ?# t$ `  h* p

. c, ]7 s- T3 y$ A% a8 F2 s; ^/ I; I) c        // this doesn't work and 'note' will be a zero pointer, see PR-18508505 C' C, t' n) t! x: s
        //note = dynamic_cast<Annotations::PmiNote *>(object);
6 }4 }$ d0 ^8 @0 Y/ X4 i; p4 K2 f# H" V+ f/ X( \4 [1 V. y- F
        // this works as a workaround
0 O2 w, f0 {! B1 M4 B/ v- g# s        theDim = (Annotations::Dimension *)(object);3 M/ x- C( O7 f. Q9 J' q/ [) `# e
        return theDim;
: a6 ]8 v9 u5 R( Q$ ]2 Z0 Z. ~: P0 e    }) d( Y- |7 r; x  e4 w* p; T! H
- m1 F8 l- @( h( ]! ]
    return 0;
+ G+ P9 ^2 Y3 G$ Q/ P}  ?$ Q! ~7 A( ~& Z7 W8 A
* }7 I1 x+ ?/ _- _  G; H  p
9 J. {( O" V; s4 ~! R
0 E( w! p7 k& [$ i9 }; o
& o$ U; |* G: u4 v* r
void plmhome::do_it()' B/ _- E1 b, l" A! z/ i
{: u; t% G1 c' I0 b7 V
    workPart = theSession->Parts()->Work();
, i* i, d: l/ C  q    Part *displayPart = theSession->Parts()->Display();
! H5 z1 `2 z5 {) t2 w    stringstream out;
# b, Y9 \$ B/ K" ^2 r    Dimension *theDim = 0;
! f! w/ b* r" F0 M% I
5 H# X6 q1 k+ y8 @; {- f    NXString tolTypeStrings[] = $ X+ |7 N, [, h* H9 h
    {
# G/ A- Z9 k. J! K! _, _# P5 k) y1 y8 L        "ToleranceTypeNone",
: L/ Z" |( E1 u% k( I        "ToleranceTypeLimitOneLine",8 n" ]5 K) g% Z( E7 }5 D% e
        "ToleranceTypeLimitTwoLines",
; _! o$ R! D6 ~# l7 T        "ToleranceTypeBilateralOneLine",: T7 o7 Z# q! _4 W" B
        "ToleranceTypeBilateralTwoLines",
: a8 N8 G; m6 L, b8 a7 L: Y* R        "ToleranceTypeUnilateralAbove",1 g% P. j7 B" }& S) Q9 k; X1 N
        "ToleranceTypeUnilateralBelow",
  i" ^8 ]2 |; Z. Y; N9 z" c- N. S        "ToleranceTypeBasic",
) F# J  {  i7 B" I        "ToleranceTypeReference",
, K1 Z, F9 i0 G. P. \) S6 `        "ToleranceTypeLimitLargerFirst",
; i9 u. R8 s2 Z! r, G        "ToleranceTypeLimitLargerBelow",
' p; R/ Q7 T8 I0 @. S        "ToleranceTypeLimitsAndFits",
" s( U$ V1 s7 I9 a" X$ k' m: l; t% Z        "ToleranceTypeNotToScale",' L, ^' A8 D- Z+ K3 P# {( x; x) |
        "ToleranceTypeDiameterReference",
* t; _' l, ^' V8 Q/ ?2 b; E        "ToleranceTypeBasicNotToScale" / H6 C5 g( c, k: V$ e
    };  L, O0 r2 I0 K1 ]
- S4 H$ @: |7 y* P% T9 Q! b# ~
    while( (theDim=select_a_dimension()) != 0 )
. w$ b: @8 N, a3 b    {" G0 e+ a) ~! e) ]; Q' q, c
        out.str(""); out.clear();4 f& \: B+ x/ g9 c7 _2 w" V& Q  g3 D& T
        if(! lw->IsOpen() ) lw->Open();
: C/ z( o: Q% M# V1 e+ Z
3 Z+ K- x6 l! b5 j( F% ~        out << "Selected Object: " << theDim->Tag() << endl;! V7 X3 P' V( e, i. S9 k* s
% i9 j& T* I$ z$ H8 x5 F3 w
        std::vector<NXString> mainTextLines;
, u% {4 \4 A# V# `8 P) ]        std::vector<NXString> dualTextLines;
1 _8 l+ j# j4 ]( A; P4 \        theDim->GetDimensionText(mainTextLines, dualTextLines);) B" [! z: E0 M! i# a# D
        for( int ii=0; ii<mainTextLines.size(); ii++)7 [! R" }0 _' E, F% r
            out << " MainTextLine: " << mainTextLines[ii].GetText() << endl;$ @8 a1 [/ ~' f3 G
        for( int ii=0; ii<dualTextLines.size(); ii++)
% ]5 n8 p* g+ ?. X            out << " DualTextLine: " << dualTextLines[ii].GetText() << endl;
9 ~: d, _: V$ z0 n4 r1 O- M2 F/ s- O; y
        bool refFlag = theDim->ReferenceDimensionFlag();! `7 [. W9 _- P
        out << " ReferenceDimensionFlag: " << refFlag << endl;0 J8 P0 N- D/ ~1 \( O
1 k3 r' y7 r, h* d$ u
        int tolType = (int) theDim->ToleranceType();3 u$ p. ]( [( o* y
        out << " ToleranceType: " << tolTypeStrings[tolType].GetText() << endl;$ e6 p& T6 Z7 ]

: E" ~( m# d, w4 `+ _  `        ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);  w: A; q& G9 }! P$ @
        std::vector<TexTComponent*> textComps = theData->GetTextComponents();3 \* X, z* e5 \8 ~. e  s
        for( int ii=0; ii<textComps.size(); ii++)1 S# X: M, |2 y- @7 A
        {
4 F' Z2 C5 g) J1 W: _8 }            std::vector<NXString> compText = textComps[ii]->GetText();1 K" N& v' o) f; G* _3 i2 z
            for( int jj=0; jj<compText.size(); jj++ )
. G) k1 M: K8 e, w% U/ ?                out << " Component Text: " << compText[jj].GetText() << endl;
9 z5 p! g) d% D+ K% Q3 `        }/ Z$ f+ i3 o6 X; B3 A# o4 O

; S; @' }2 w  S# P        int subtype;
3 W% q: n. E; L5 e6 R; `        double origin[3];
2 Z6 q' g7 Y4 C  Y# p) J* u        UF_DRF_dim_info_t *info;5 R% J. s& a' g; V3 i2 {: D
        UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));
5 F4 w6 I4 X3 g4 m        for (int ii = 0; ii<info->num_text; ii++)% D0 x: ], O, Z" ?
            if (info->text_info[ii].text_type == UF_DRF_DIM_TEXT)
# u* M1 \6 c6 y$ ?4 ~/ ^                for (int jj = 0; jj < info->text_info[ii].num_lines; jj++)' j* g6 K+ T8 G% J+ {6 u/ ^/ k
                    out << " UF_DRF_ask_dim_info Text: " << info->text_info[ii].text[jj].string << endl;
& s" }3 c2 ]7 [5 h3 T( B        UF_CALL(UF_DRF_free_dimension(&info));
+ S4 ~, p4 Y* d4 u' k  O2 M$ `2 _% Z/ b: W( p/ A6 f
        lw->WriteLine(out.str().c_str());
/ q( {6 a; q1 {
( [+ |) W, n( y! S- }. `    } // while; K  O# w% p1 D. u0 M
}
* ~  b( H# {/ \+ c( @% o& g* n$ W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了