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

[求助] UG录的日志文件有界平面怎么返回Body

[复制链接]

2017-9-15 10:49:42 5544 1

smalfly11 发表于 2014-2-12 23:34:54 |阅读模式

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
: X  J3 J- W/ @" W5 tusing NXOpen;
& e* D% }# S. z# Q) qusing System.Collections;% v8 n. Q7 M' j, ?+ U5 D
using System.Management;
' _. \$ q" k. k( fusing System.Management.Instrumentation;
: r7 o0 r+ Q; M, k( y5 Gusing System.Text.RegularExpressions;4 P2 {1 R& x! z+ ]) E4 l
using System.IO;/ D; O6 j8 C$ i( \
using System.Collections.Generic;& Q0 O# {# ^, z; d3 [
using System.ComponentModel;" W+ d! z2 L9 `6 @4 v$ i9 V8 v
using System.Data;
, Z# Y0 V% n* T. a1 u) j" eusing System.Drawing;
5 ~' k: {( L3 b3 U- rusing System.Linq;+ e7 K3 T2 E  S
using System.Text;- l" @+ I7 M# ]+ r. N: r# @  j
using System.Windows.Forms;
7 [( }" ^& g7 ?  t0 @, ?$ l1 Y0 ypublic class NXJournal5552 X. L0 b( _" E% T  Y/ K6 `) V$ _4 a
{& [9 _# h: d5 D+ g# F4 X  [  }
    public static void Main555(Tag[] bj, int fhsl)( Q5 ~) I/ V' _& x1 \
    {
, b* O6 {8 ]  k" k        % o& C5 [2 F: I( _; a' t- d
    Session theSession = Session.GetSession();: \3 A: I" z( j4 k% A
    Part workPart = theSession.Parts.Work;9 ~0 s# R6 j* b4 f% f% B
    Part displayPart = theSession.Parts.Display;" }0 V! A0 p" F7 I: H6 f
    // ----------------------------------------------4 q0 `) y! O) D" P$ L0 U
    //   菜单:镶块->曲面->Bounded Plane...
# I6 m7 O0 I/ r/ p    // ----------------------------------------------: G8 ^% Z( H# _3 ^
    NXOpen.Session.UndoMarkId markId1;, y- K, S4 c7 C  T! u% |
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");; c0 {  R/ f' U2 y! j
   
1 F0 g! z8 R: x$ l( [" l    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;. _, `' `- h- K
   
; y. {( y( I* w8 K" I    if ( !workPart.Preferences.Modeling.GetHistoryMode() )
1 R( H6 F; k+ z3 N3 |    {6 `2 E! b% V0 Z' I+ M
        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
+ W* B# n  j  ]5 U    }
2 J) i5 B" n9 `$ W* D; T  d( B   
2 V5 s) x- O- X4 _/ h. Q7 b    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
; y3 k8 d  s9 o  I    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
: R0 n" {' ^( {# ^: Z6 ~3 W   
9 s2 n4 o) d7 L( h2 M& N    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");
9 ~. [  g! Z3 c3 d' l   
/ ], F$ R; v" E* v    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
& n( i* B1 \1 H  K. x    $ k! q5 T- L' ]1 `1 R1 U  r
    NXOpen.Session.UndoMarkId markId2;
& r0 O& }' }' q4 q* C% ]3 u% u    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
) V1 S9 U: ?6 f  d$ r3 @   
3 V6 |; q$ L1 c! h0 s. I    NXOpen.Session.UndoMarkId markId3;2 _4 R* ~& q; o/ b9 @9 P* j  S, |$ o5 ?
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
; d* @/ J& c3 {1 d8 N6 K    " M, d: K  ]5 Q, B2 l8 ?- [
    Curve[] curves1 = new Curve[fhsl];
4 Z- _  w6 A! \7 ?( ?; K% p/ ?    Line zx = null; ;* O; t; ~# |7 k+ n& o# b; V
    Arc yh = null;
7 C! K, f; k" \6 x. {    int bj001 = 0;
2 `1 _0 t5 B$ Y* G0 h8 b( _  E+ a    for (int i = 0; i < fhsl;i++ )" p! V1 s0 ]4 \+ d+ [. y) J
    {
' U" ?# ~) `% {- [8 _" W5 V& P- q4 s        try& b! w: W% l) h& y1 p' O
        {
# W! [+ [0 |# W# m! Z6 i* V! g7 h% g9 c            Arc body2 = null;5 x0 i, \3 d; _* ~. Y7 }$ ^  E$ c- C
            NXObject object0;, i* Y* d, A) t  \2 l
            // Tag body_id = NXOpen.Tag.Null;
) W: q3 k+ `- z7 J) W4 N            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
( a8 ^1 q0 L* q0 v5 p* D            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
$ P( k2 c' W3 V$ K+ ~            body2 = (Arc)object0;( M! ~6 F9 I( y* N
            curves1[i] = body2;0 B0 \2 j: x( _* R6 D2 K2 I/ z
            if (i==0)4 A0 t0 J: N5 k9 Y2 F
            {" S2 v& k' [3 e  L3 o
                yh = body2;: X  q1 C' m0 r2 X9 O
                bj001 = 1;/ W, C% s! p" k& B- k
            }4 t9 q3 @/ t- D1 e9 q% f: G
4 x4 v$ G+ y( A7 J9 `' w" a
        }
) C1 Q; o3 w4 O2 t8 l        caTCh (System.Exception ex)
$ e- V1 K0 j6 h* C        {        : J+ w1 w9 v9 a4 l% k- u
        }
- e2 s- @8 N( M9 h. y& W# u        try: `8 _5 X  @7 u* X' ^
        {4 Q1 w/ W1 z: {$ k  S- b
            Line body2 = null;( F( N% k, e3 [6 i% t
            NXObject object0;5 g% i& n; R; _* N6 V" ~
            // Tag body_id = NXOpen.Tag.Null;" I6 ]! t1 \/ j- y1 q2 F+ i
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.+ B1 |  V* S$ C3 G
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。. B) z  i- u" w3 i/ v. q3 H- F
            body2 = (Line)object0;
5 ?7 b4 Q0 }/ z/ X$ j/ D, l, [            curves1[i] = body2;) ^1 Q: i' r  t- e0 F# V
            if (i==0)
" z% F7 h) q- _6 ^; p" q5 e- h9 D            {
& ?1 l0 G! w: C8 w                zx = body2;8 A% s2 `( F/ W! |
                bj001 = 2;
! i% n1 b8 Z2 J, K( ^8 B            }
& ~! y0 G% Y) Q        }
0 j* ]) \: \5 s; |* W        catch (System.Exception ex). M3 a, _8 f# f1 F
        {
  {7 g8 [3 z& @4 ?! ?! |  p         " ^+ k5 ^, b, Z% g! Y9 z
        }
$ }  h" h0 G8 {4 x7 I6 w  c( k" A# q4 V' n+ p
    }' X2 \4 \- k) e
1 p" v9 t! U( J& Z
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");0 F/ `# W3 g" d, ^  S& O- f
//     curves1[0] = line1;
& V+ g" d) A! b3 C: V//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");4 V$ N5 `7 U! X" i
//     curves1[1] = arc1;
. a  Z: a  G! p- Z//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");
! d; G1 P0 x9 _//     curves1[2] = arc2;! F: G6 p+ W, G; v) J6 D( R
//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");- w+ W4 r9 [& o! V8 q' F4 Z
//     curves1[3] = line2;! f: S5 H, z9 O4 A8 E
//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
% I; e9 T9 {8 }% r0 J6 y( D- d//     curves1[4] = arc3;
1 @  G8 Z8 V, o& {; W2 j! \//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
) ^. L5 p/ u0 k7 [7 r4 ], v( D7 Y+ z//     curves1[5] = arc4;
1 B# C! z3 h4 B( R  ]    CurveDumbRule curveDumbRule1;+ u4 }: W. B, j! s. u
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);- d1 c8 E9 @) |' V+ V: l
   
; k" d2 M5 N* n6 J  l* w- N    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);% d4 \; B1 O! H
    ! q- f8 r6 ?! g6 W% ?2 D
    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];2 |# l. @4 t; F# A7 ?) i4 R
    rules1[0] = curveDumbRule1;8 T" g7 B, w' n6 H0 X
    NXObject nullNXObject = null;$ G# }: h" M7 z+ ]
    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
2 ?- c% a# O4 t2 Z/ C    if (bj001 == 1)
' A: x+ u  }" V6 I    {" i' n: I( ?3 \1 G
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
( o: g1 Q+ ^4 h6 y1 S" ^* d    }
" j# g1 C+ x5 }. c% b$ W/ P9 b    if (bj001 == 2)- i7 o  ~! d1 W  b
    {
2 b% S9 t, W5 k6 e  `        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);4 ?5 e9 l" k  V  M) P
    }
( K7 i  A- J- D9 Z& I0 p  r" A   
3 v& p1 L* X/ Z$ g( g    theSession.DeleteUndoMark(markId3, null);
; U; E9 r1 b$ Q2 E* B    - M$ m8 n& O$ k1 V
    theSession.DeleteUndoMark(markId2, null);
, T  e7 j# V' y   
" ~! M) [# Y5 D- ?( o0 K    NXOpen.Session.UndoMarkId markId4;
7 T* p4 S! v0 }8 @8 b* n# R    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");; ~$ K+ a1 J( e0 g5 l9 N) c& x& T( o6 V
    ; y; _8 u% m- a
    NXObject nXObject1;' g& \7 P0 H7 n0 Q
    nXObject1 = boundedPlaneBuilder1.Commit();
. o8 G7 b8 l) i* Y   
) m$ U6 A9 m# d. f- o    . z2 o: y+ B3 H- R/ x& L. F
    DisplayModification displayModification1;
' A8 g7 p8 a& R! t    displayModification1 = theSession.DisplayManager.NewDisplayModification();
3 n  O1 [/ `+ I" S* P   
$ E" Z* Q4 t. v1 m; I. v$ E4 p    displayModification1.ApplyToAllFaces = false;
9 J3 T5 z$ K+ \    9 N1 J+ ~1 B" b
    displayModification1.SetNewGrid(0, 0);
+ @7 X# U4 n+ ^  O6 V   
  ^* I4 d4 p( S    displayModification1.PoleDisplayState = false;
+ J* v* B; A/ M; x+ u+ v4 m   
  ^# h6 ~$ r. I$ s% @# o( @    displayModification1.KnotDisplayState = false;
: r0 l) f( l7 y+ w    & v8 W, Y) x- A3 l/ d; o) h# o
    DisplayableObject[] objects1 = new DisplayableObject[1];
% ^8 l' l9 J- `; t    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;
3 @8 [; t: j) v: ]7 [" p3 A# ^9 {    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
7 L; E* H6 {/ q. ^    : b: P, I2 i: p- Q: @0 z. Q( q
        objects1[0] = face1;
& }5 y; O& r2 ~& z) a7 o8 \    displayModification1.Apply(objects1);  z; K* b7 V, m% f
    face1.Color = 32767;
' t9 v5 {7 x4 h( G- `- H  B   
6 D* p. w: u. J  C9 y    theSession.DeleteUndoMark(markId4, null);
* E( C8 b) q5 L* K( c" _* s/ E    ! w4 H8 }+ f& N3 a" S7 `
    theSession.SetUndoMarkName(markId1, "Bounded Plane");: _  C  y, E) c( w
   
3 C- x! d2 ?# t; ?9 Y    boundedPlaneBuilder1.Destroy();
( m3 f1 R  M9 e3 A3 n    ( ~' d/ I/ `& v/ G2 e7 O2 Z  N
       /* if(fhyi==1){
0 ^1 n" j) k' H/ R' A6 k7 m" ~    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}
3 y0 ~$ e/ v1 E    if(fhyi==2){
5 U$ L3 Q; K& Y! B% `- F    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}( c, T$ `1 N! A, e
        */3 K, t  V# `, r/ H1 M1 S" r6 H
    // ----------------------------------------------
7 [( ~& A$ E& y& ]    //   菜单:刀具->操作记录->Stop Recording$ {( T6 G0 L$ `
    // ----------------------------------------------% _0 e. R# u5 ^  t3 y
    $ S* \) _; `) _& Z$ A" \1 Y" s7 j
  }3 j8 V- z4 p- s
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
; q3 q5 U  f0 S; v! p: E}- S* R7 H5 ?0 L$ x
这是录制有界平面点选封闭曲线产生的日志
5 y) V! C* ?  [( r$ j/ W4 ^, j我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了
: [1 f% G, z5 N/ ?7 X+ g, ? NXObject nXObject1;( X( u2 v: e( m- a) O
    nXObject1 = boundedPlaneBuilder1.Commit();
& r5 Z" f) [' h# S' C但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值
0 H0 J  B1 d  n6 L& ]* w+ s% S9 W6 v/ Q5 {6 Q  o; f
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复1

nxopen 发表于 2017-9-15 10:49:42

nxopen 沙发

2017-9-15 10:49:42

我也遇到同样的问题:NXObject转Body出错
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了