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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2015-8-22 12:47:05 | 显示全部楼层 |阅读模式

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

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

x
* d, J* y, R8 Z  o' b/ m& S; a% [
Dimension* plmhome::select_a_dimension()" A9 n9 \  Y' l) E/ b/ l' h
{9 M( j' K$ \. u& q. j2 m6 S) |3 l8 v) h
    // ask user to select a label3 k8 p: q1 h$ Y- d/ s
    UI *ui = UI::GetUI();% G5 e) z5 V+ l, ]3 S. r
    Selection *sm = ui->SelectionManager();7 A# w& X% `& |0 O# B9 S
    NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
- |; R" w: C, B3 e' ?( z- N6 ~4 S; N. R5 ~1 i% ?" e8 D
    NXString message("Select Dimension:");
# v  ]- z4 j6 V    NXString title("Select Dimension");
/ v7 P: v# z& c2 ^( a( S    Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
1 T# R, {. L; _    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;/ w3 s6 f' ~; }* g! e8 r0 a+ Z0 P
    bool include_features = 0;+ U( ^) D) d0 |- H
    bool keep_highlighted = 0;
, ^) c6 n5 |. g- s, d+ n3 t3 n4 X! b# D: x9 B& `
    // Define the mask triple(s)$ L/ d, a4 Y2 ]- A' D8 D7 T
    std::vector<Selection::MaskTriple> mask(1);1 ?0 f: S1 O7 Q/ H8 Y. s
    mask[0] = Selection::MaskTriple( UF_dimension_type, 0, 0 );; e# M9 F5 x. m( T9 ]2 O- A
    Point3d cursor;
" t- |0 E. {) C7 D    TaggedObject *object;( f' v7 Q' H" w$ H6 d; j/ z0 V

/ c: g1 T& ^3 k! v/ \- C  w- h2 O    // Select objects using filter defined by mask triples
2 P2 t6 T5 I( [- N3 V    Selection::Response res = sm->SelectTaggedObject(
2 Z! F8 L7 _  e# f        message, title, scope, action, include_features,
( m" z. W4 y4 b+ [  p! a/ C            keep_highlighted, mask, &object, &cursor );
$ o. K, ?. |* _. a1 q- j! q# F7 L) Q0 B# t( r/ k* {
    if( res == Selection::ResponseObjectSelected )
3 B4 t7 h. d  l' K0 R2 ~& E2 ?    {
/ j+ s9 k6 v$ q! F+ E% F        Annotations::Dimension *theDim;
5 w& y; B, P: l& Z. w7 H2 s- F6 Q4 d% T2 o8 ~4 u
        // this doesn't work and 'note' will be a zero pointer, see PR-1850850
0 L! b$ [+ u4 K1 y# p9 r: ~        //note = dynamic_cast<Annotations::PmiNote *>(object);
: O  E( q. W+ ~" b# S) a8 F
) G* c8 Z5 \0 f* m        // this works as a workaround- ^( H5 m4 i% [
        theDim = (Annotations::Dimension *)(object);$ \: W, I" F2 }) e+ J8 ?4 n
        return theDim;" p6 K. k0 r1 K7 k
    }
3 x3 o$ k/ j, O; h$ M4 b4 F
) I7 g6 g3 s) W# w    return 0;/ n- U- a9 T3 \% c4 O  H* C* i
}7 X/ N& H$ n0 U2 S( U
) c% {' _6 ~. B- Z& c8 n1 e. P+ c; M
4 \6 r( w2 ~/ I0 P/ v) @. p
  N& q9 i4 W% w
% [: @- e( u( ?; x. i
void plmhome::do_it()
' k& Z, a% {; a% ^{! B! O; Z+ Y. ]  @1 R; U, f6 g* d  F
    workPart = theSession->Parts()->Work();
/ d# s" J0 t7 i: s6 f% c# j# u    Part *displayPart = theSession->Parts()->Display();
0 o( B' Z5 [* Z- h. J) Y, R    stringstream out;
( ?+ Z+ m4 ~1 O" ?; |: v    Dimension *theDim = 0;
& l9 K3 z" }8 k6 o- T8 \0 [. y# m* g* b6 o) r7 p
    NXString tolTypeStrings[] =
& ?4 ^3 z2 K' {' G; ~    {5 r3 l7 w9 R6 j9 Q) M. m
        "ToleranceTypeNone",
: b+ W% g! l- V/ x2 `8 P        "ToleranceTypeLimitOneLine",
& o, V8 \) O2 ^        "ToleranceTypeLimitTwoLines",6 r2 A0 c( a" k: R1 P+ |
        "ToleranceTypeBilateralOneLine",
8 D2 z6 V" J' W. ~$ J        "ToleranceTypeBilateralTwoLines",+ x$ W% n+ L( B5 u0 j, m  ~) d
        "ToleranceTypeUnilateralAbove",
9 v8 Z" |' V; x3 G        "ToleranceTypeUnilateralBelow",
+ |" g' k, }- ^% h4 W" ], v        "ToleranceTypeBasic",5 V# H# g" w' c: n, q( @$ j
        "ToleranceTypeReference",
1 c& I/ ]  x" Q+ e7 j& e: c; h        "ToleranceTypeLimitLargerFirst",
4 {9 B$ S4 E; U$ q( {        "ToleranceTypeLimitLargerBelow",( W9 r7 n- @& A
        "ToleranceTypeLimitsAndFits",* q/ ~' M* v  [, M0 J8 K
        "ToleranceTypeNotToScale",
: N( d; l8 A7 W2 t% S        "ToleranceTypeDiameterReference",
7 M$ E5 P' w) `& K( v6 _& Y; a& w        "ToleranceTypeBasicNotToScale" 4 S6 x, c; q+ I, h& Y. b
    };6 _1 e2 E9 m9 ]2 D/ @% z; V# e7 \
% C* b' Y! N8 P6 \& R
    while( (theDim=select_a_dimension()) != 0 )
9 R0 `& E/ E% s" n    {' [0 e, A  g& k5 I
        out.str(""); out.clear();/ \* h1 F8 C8 I- F3 B
        if(! lw->IsOpen() ) lw->Open();
, H- A' D: r5 I, t9 h+ R# z
8 I& O) A: Y2 m" {7 P/ U: F. I, J        out << "Selected Object: " << theDim->Tag() << endl;
5 n( v) n3 P4 \8 m+ C6 \! o( n, p2 S, L. }7 |, ^0 _/ Z6 t- r$ Y) f
        std::vector<NXString> mainTextLines; # _3 J4 g4 J2 S& Y- C
        std::vector<NXString> dualTextLines; 0 z4 T6 M" S- z3 ]5 n( M
        theDim->GetDimensionText(mainTextLines, dualTextLines);
0 A; S" m% _1 F* t; E        for( int ii=0; ii<mainTextLines.size(); ii++)
5 T  M$ D# i( e            out << " MainTextLine: " << mainTextLines[ii].GetText() << endl;$ ]# _: i3 l+ _0 ~% A! W0 g8 q
        for( int ii=0; ii<dualTextLines.size(); ii++)
  @2 {8 U3 Z; [9 f! S8 H9 u            out << " DualTextLine: " << dualTextLines[ii].GetText() << endl;7 a) w1 W" d# u9 N4 r$ U5 F" F3 H
0 y- b* d9 p3 E4 f' L+ A7 {4 R- b
        bool refFlag = theDim->ReferenceDimensionFlag();( G0 f8 M+ u* Y& `7 x/ j
        out << " ReferenceDimensionFlag: " << refFlag << endl;
7 i" P7 R# _$ W4 E- D5 @- _& Q( k, O5 \" C' `  B
        int tolType = (int) theDim->ToleranceType();
* s! e7 w& E3 y0 r        out << " ToleranceType: " << tolTypeStrings[tolType].GetText() << endl;
, @+ S  Z1 |2 M, _6 Z& J" k+ Z
; {$ S2 m( p3 o; y$ z        ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);7 ^+ [* l5 L! R: E. a/ i: L7 F
        std::vector<TexTComponent*> textComps = theData->GetTextComponents();
6 \6 K6 p& \% ?$ G4 I        for( int ii=0; ii<textComps.size(); ii++)
4 `& a; T7 [, V5 V3 G$ x        {
% U$ T% g' O9 _+ |            std::vector<NXString> compText = textComps[ii]->GetText();
7 [" w; Y$ X; A0 v8 @) K( u' g            for( int jj=0; jj<compText.size(); jj++ ): _  t$ A/ O$ z2 H6 i
                out << " Component Text: " << compText[jj].GetText() << endl;( @, \3 c& B( c
        }1 p+ r- n; ^) N! I7 {) k% v6 v
  P6 b, g1 |- s7 V
        int subtype;7 q$ Z0 x3 ~2 n
        double origin[3];
- s' d4 d9 p- C$ n$ M$ l5 y        UF_DRF_dim_info_t *info;  ^- o/ V% B2 T7 x6 D: X
        UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));
- @, `. n8 ~! u: w8 F% G5 j5 z        for (int ii = 0; ii<info->num_text; ii++)
/ W; d' }5 C1 H6 {            if (info->text_info[ii].text_type == UF_DRF_DIM_TEXT)
9 e  w% B# r+ o                for (int jj = 0; jj < info->text_info[ii].num_lines; jj++): M% [2 A% @/ Y9 O2 [
                    out << " UF_DRF_ask_dim_info Text: " << info->text_info[ii].text[jj].string << endl;# y$ j  l* \3 m2 j; ~( }+ p. P( V
        UF_CALL(UF_DRF_free_dimension(&info));
$ |9 o$ h7 d6 Y7 ?5 p0 L  _
3 X1 U5 T0 \0 c! ^' F        lw->WriteLine(out.str().c_str());( i9 X6 Q* `' d. n2 q( ~3 y
8 c. g  Z. q. ~$ i9 N
    } // while
5 R/ `/ {  Z3 G, W. \}
2 x! u( F7 w+ U% m8 i4 P& E9 v: B
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了