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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
  ~/ p1 [" D+ w9 B! ]2 q) O" vusing NXOpen;$ c* y; y7 b7 r& n4 y
using System.Collections;
4 Z7 A* j5 V8 u; R  C8 |using System.Management;
4 p" G% h7 w' Y3 [% lusing System.Management.Instrumentation;
8 X2 p- T9 k  t# A9 U0 n* b% H/ Eusing System.Text.RegularExpressions;
1 D7 C( L: {3 I0 f. T% A' }$ {using System.IO;
- a. Z5 f. Y( Z# ~8 Xusing System.Collections.Generic;, s3 _& D( P! a5 ~; q
using System.ComponentModel;, }) a& q) X% P, I- Q
using System.Data;
# w: U$ D+ g/ J- g5 ]3 rusing System.Drawing;$ U2 Y. F* Q, O8 N+ |% D8 E$ a' r+ b7 x2 B
using System.Linq;
4 l& _) f- e! }( L, y5 D! s. Cusing System.Text;4 n# }1 U& w" V3 q7 ~- [
using System.Windows.Forms;
: l0 @# [; N- d& d  ~public class NXJournal555
7 n% M1 W, S5 X{  x, `2 H* J, ^* z, X. c5 q
    public static void Main555(Tag[] bj, int fhsl)
/ [0 E2 s) d8 B4 h2 _3 U    {  ]2 _& o& a5 f1 f
        
9 |$ ?* e3 Z8 _& V: z( b8 \7 M    Session theSession = Session.GetSession();# O3 ?$ \  E& B- n
    Part workPart = theSession.Parts.Work;
7 ]4 ^% P$ A, u! a! ^, W    Part displayPart = theSession.Parts.Display;2 g# Q3 A# i& x) r# B# |
    // ----------------------------------------------6 P& \" k6 \* C- r
    //   菜单:镶块->曲面->Bounded Plane...
4 m) @, y5 Q/ F( K7 J: m    // ----------------------------------------------# b) l$ I2 q) f% N
    NXOpen.Session.UndoMarkId markId1;8 W1 N( ^& L- @/ n8 E; q
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
# c; ?- I; j0 a. c# c  U* A   
* _6 V/ O3 x' j2 Z' m0 t/ l    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;5 ?$ V3 v9 i- v; F4 t
   
% X1 `, ]6 `0 V- ?$ n0 K- z    if ( !workPart.Preferences.Modeling.GetHistoryMode() )! X( l* J' d4 {& n3 N
    {
$ a6 U0 V' m# ~/ g( h* \1 C6 l( T2 v        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
% |' q0 T; K  P# t    }
2 t% Q: F: d0 _& @   
' E% t# Y0 U2 ]  `# d    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
' y/ c7 l; E/ ]+ E1 Y; x    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
" \; |/ {# n7 X' E% P   
+ o# S; H) G$ Y# [0 U    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");8 r2 `2 [( o* C- O2 Y3 o
   
  [; F- H! p" f" m2 |    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);9 W% {$ v& h+ ]  ^
   
& Q- w4 _* j4 k    NXOpen.Session.UndoMarkId markId2;, W0 X  z3 s1 |2 o1 E8 y
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
8 T1 g1 A4 B2 o  t5 w8 e: o    7 t: X* Q. s, ~+ s' e/ l, \
    NXOpen.Session.UndoMarkId markId3;0 @6 d2 n/ v$ D2 O/ y6 `) d7 a
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);  c; q, y2 F. S+ U
    + \) B5 ~3 o- K
    Curve[] curves1 = new Curve[fhsl];
, H- a& E5 {# ~: O7 |2 e! ~    Line zx = null; ;
, @% ]9 y2 n2 K8 a5 V$ W) S    Arc yh = null;$ O) ~: W) q4 f; F; N2 M
    int bj001 = 0;
" K8 a4 ^, l3 R) `. F/ Z    for (int i = 0; i < fhsl;i++ )7 h$ b1 j' z1 R" V7 m& R
    {8 r+ U3 O8 b+ k; v
        try" k; Y/ i2 D8 Y& u- e
        {
- Y7 _# h% d  q" V4 x+ G+ B! ^            Arc body2 = null;
; E: l* E7 ~5 \3 q' f            NXObject object0;5 s; \& ?$ G9 N  y/ P- E
            // Tag body_id = NXOpen.Tag.Null;  v$ o$ o3 i! _( t7 R
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag./ C3 Z/ j2 [" q+ u  _6 Y. N
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
3 o* o: {7 G" d8 K            body2 = (Arc)object0;
, r& k$ h6 ^- b4 [            curves1[i] = body2;
+ y/ W" I* ]9 l5 I* l4 |& u( S5 A+ ~            if (i==0)
; V/ f2 v) q% U            {. T0 k! G) O9 c- }; P  i
                yh = body2;" P  H/ k; O/ [( _
                bj001 = 1;; C8 @* @& d% i7 j) ~' a1 o
            }
$ g+ `$ U6 h7 S8 Z# Q. @, H2 w# s# G) H; P6 \+ D- r
        }9 f$ n; q$ O: I- u- p
        caTCh (System.Exception ex)
5 a+ \: J; s. e* ]9 {        {        , h' s7 C' ~( B6 v% r
        }
0 _$ ^6 `+ C1 S        try" _5 g6 ?9 f: M4 b1 @' u5 I& J, n
        {* W/ `: V/ v' e# @1 f  X9 m  X0 c
            Line body2 = null;/ k# |" l1 T, _3 R+ W; \
            NXObject object0;" i2 N5 E# O& r# V; m2 m. x9 ^
            // Tag body_id = NXOpen.Tag.Null;
/ W2 U* t5 E2 B            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.' e/ _8 f# ^8 ~; l4 [- D' ~
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。5 Q3 y/ l$ X8 R0 ^
            body2 = (Line)object0;
* }, w  t2 M8 y/ p5 l. `            curves1[i] = body2;
9 M/ K. d: g1 V* [' B            if (i==0)* y2 }' b$ c1 Y6 X6 _" p9 A
            {0 C, l+ I" o; |" a& o& I5 N
                zx = body2;
* p3 M! V8 Q8 W# T& s1 B: T. B( m                bj001 = 2;0 H$ E2 f; q9 U6 \, x  z
            }
$ p$ M$ H7 _2 @& s/ q! V. l        }' a$ J  ?  O2 V  H) a1 {& x, {
        catch (System.Exception ex)/ c; ]2 N$ G7 K7 a! @, A; H7 s
        {4 c; _' [7 {- B6 P6 G  ~3 l) a. a: Z  N
         $ i7 d0 ]+ L% l, E
        }
& R. P# v( y6 o
) m$ S, y5 S! j& ]    }, l$ J" Z  p5 c
' J/ e- w, B1 R) A) T" r5 m3 w
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");
2 c! R* Q% B# |) C0 f% M8 ]; K3 p//     curves1[0] = line1;2 `) I8 y3 _" U, V; `- u+ }
//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");
$ @1 N7 e# \# d1 p- c8 [//     curves1[1] = arc1;
* g3 }1 g' C1 ?/ s" B0 k//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");
! y# r" F' q1 F2 {% `9 Y$ J//     curves1[2] = arc2;; u; X. x3 Q  f. F. |6 i% @
//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
. {, O; a/ u  _; o1 s' F  E0 C//     curves1[3] = line2;
: u; g9 K( l- N//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
0 K5 o$ t. O- X3 g//     curves1[4] = arc3;/ O2 S: T( y- [& _( j
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
) A, S( N, A$ f: a0 [//     curves1[5] = arc4;5 k2 H: N" u( `; P
    CurveDumbRule curveDumbRule1;1 \! z% f4 ?$ z: Z+ p
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
/ F' N7 @# v% j  ^    # t- x: s$ v$ B4 I- o
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
' o1 {. Z! S! r% D/ P6 F   
! l1 t1 C# X2 @' f, e% @2 y    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];; ]6 w7 ~" ~# {) _
    rules1[0] = curveDumbRule1;' H: `3 A) L8 U6 Z7 j$ J% S
    NXObject nullNXObject = null;
6 N4 X8 q0 j5 p3 Z) k1 d0 v/ o. U    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);3 g. U7 |# x0 q3 Y7 C; _0 n
    if (bj001 == 1)/ R9 Z8 b. x1 m" ~% }& t$ s- e
    {, D6 d" W* K3 ^; Y
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
/ Y% L* O) w! Z5 {    }# w* {# K% f5 S! e
    if (bj001 == 2)
) N) M: g  i, I3 k: e9 ~    {
7 Q+ I# {+ B( s1 e- R1 n        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
/ _2 ~* A. [. U  d    }- c8 \) }7 P2 z7 l- F
    & W9 B/ D/ z+ H4 _7 H
    theSession.DeleteUndoMark(markId3, null);
+ v5 y3 h3 {' f  S  |0 N/ `$ E4 r   
1 \# K; [  {0 B& g" W    theSession.DeleteUndoMark(markId2, null);
* I- g# M1 x5 m  y- |8 ^3 o    + ?# `: v3 ~& l% M& t
    NXOpen.Session.UndoMarkId markId4;  q7 Q3 L- G/ y( F$ q
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");8 n4 ^' ]! ]) j3 k; v( d: \
    2 G  l4 J4 A6 S
    NXObject nXObject1;9 V! G1 C" `, [, B$ c2 g
    nXObject1 = boundedPlaneBuilder1.Commit();
6 N! A* l' ]0 @: ^    & w  M2 O5 C# f- Z9 O& @4 m0 M6 x
    , f( ~2 ~9 n3 i, Q1 o6 u
    DisplayModification displayModification1;! ?; o+ D6 w, B: ?% L, }3 ]* F
    displayModification1 = theSession.DisplayManager.NewDisplayModification();
( J" Y6 w* f( D. P  h    - b: G3 t+ M% R& f/ m9 A# w
    displayModification1.ApplyToAllFaces = false;* T# h$ i( W5 B& q( n' j/ b; _
    8 Z3 n# Y) W7 P' }  W9 @
    displayModification1.SetNewGrid(0, 0);/ ]3 x7 g+ T2 }. o, V  J4 E7 n" j
   
$ {# g9 q2 H! T" O    displayModification1.PoleDisplayState = false;6 f! m7 n" f1 ~& `4 R5 Y
    9 N* C, Y/ K/ O* X" k1 y. K" E2 T
    displayModification1.KnotDisplayState = false;
+ y6 J) U+ {- s* \/ v, X    & x1 M% v& r/ @( r' Q* h  Y
    DisplayableObject[] objects1 = new DisplayableObject[1];
' b/ J3 a; O# {! L    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;, B) H: s; v5 S( }0 Z
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");8 i' E5 o# p; |* f! C4 p
   
, D4 p6 k# U/ y+ _9 |& m% D. K        objects1[0] = face1;" L+ L& P2 [$ C$ u; y9 F
    displayModification1.Apply(objects1);
  S9 L) S5 N* p; x* f! Z+ r1 B- }    face1.Color = 32767;+ F9 S2 l' |, x* l! \9 ?' J3 D7 @
      _6 i3 f0 t' v' G" c, x6 R4 `0 [# A$ e
    theSession.DeleteUndoMark(markId4, null);
9 h6 Z( J  o+ s: m  M/ \+ {   
: c  U. M) |9 e. l) Q    theSession.SetUndoMarkName(markId1, "Bounded Plane");  L6 ~% k# b) v! S
    , V! X  B3 b1 n. [+ g3 }
    boundedPlaneBuilder1.Destroy();! d- j3 P. H2 f7 F& G7 Y
    $ K3 E2 n) P1 x5 f; T* I  y
       /* if(fhyi==1){
  ^( @+ C9 K+ y9 F* K( p  f  ?9 ]9 x    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}6 y5 q- {/ f' O# D  i6 V
    if(fhyi==2){
) M! z9 G: I0 X  k    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}
! F1 |* E( l) [( U8 d! q) S        */6 Z! A; g# T4 {# A
    // ----------------------------------------------
1 _. O2 u% T( ~' q& M- a3 k    //   菜单:刀具->操作记录->Stop Recording
8 y7 q+ f, X! U4 Z; S* G    // ----------------------------------------------, u7 h9 O/ N$ c4 _, r
    . ?6 [! Q' o  b/ S' o" e  f" u
  }9 E" T1 {: m# ?5 B8 ]
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }4 |) G6 [9 ?; l# s0 Z# b" N
}5 ~' t. F" m! o3 ~. x
这是录制有界平面点选封闭曲线产生的日志
2 w! B. H7 J; |$ ~" s# G# G我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了
0 k& V6 J( E# U6 { NXObject nXObject1;% m, ~( B6 k7 e( v5 t
    nXObject1 = boundedPlaneBuilder1.Commit();; P8 E9 k! W7 M$ E: `
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值1 `6 ~9 q, Q+ `2 R  w: }1 A7 T
. g. T& [6 I: l. ?- l- ]
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了