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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
* T) ~- r5 ]$ ~3 M- o$ {7 }using NXOpen;. }$ A  Q( h/ R2 G; ~6 k7 M
using System.Collections;2 \9 t$ [( H* n
using System.Management;
) t; N8 c2 m+ Q; k! F8 U; O# w+ r8 n9 ^using System.Management.Instrumentation;
+ ]7 k. ^7 @7 U2 Vusing System.Text.RegularExpressions;
2 q) B, a# @4 s4 ~$ y) P. Musing System.IO;* {0 T& e2 K* [/ \
using System.Collections.Generic;
1 b" ^! _- L& p; }; Rusing System.ComponentModel;5 v' c: P# l; L
using System.Data;
9 `# Y3 m+ V# s+ E! Qusing System.Drawing;
  e1 L/ m! O+ c5 iusing System.Linq;4 B1 y  H% ]% N/ E; ]& _) j
using System.Text;& Y* a/ }9 g4 u# Y' n
using System.Windows.Forms;
8 Y  H# h* @2 u. v- zpublic class NXJournal555) h' k( ?# n. Z  _6 M6 m
{
# n% G4 {) H/ k& m* H    public static void Main555(Tag[] bj, int fhsl)
7 M: N" @9 ]+ r5 B4 l9 A- C    {2 D4 z7 I, P- g* v
        3 j1 D0 g- P, v2 D% V# w
    Session theSession = Session.GetSession();5 _" S' J1 {; m$ H, Z% z
    Part workPart = theSession.Parts.Work;
0 j, W. B8 u0 y  P1 r/ g    Part displayPart = theSession.Parts.Display;
: ]- h- B  X, _  w9 H2 j    // ----------------------------------------------
4 C5 R' [; ~2 q    //   菜单:镶块->曲面->Bounded Plane...3 w. ?1 z' w2 K1 v, D1 N
    // ----------------------------------------------8 u# I% O; m! w6 D4 F( O& L
    NXOpen.Session.UndoMarkId markId1;9 n  v$ o2 [5 o; C0 Z
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
" y: N2 a  ?4 d7 r, d   
- w- z! P/ I- L- d2 E' A* b/ l! e    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;9 k+ [+ L- c6 g
   
' ~: E* G. B% r, X    if ( !workPart.Preferences.Modeling.GetHistoryMode() )4 j9 _; c  Y1 X6 Z) _: q" D" t) I
    {$ [/ m! X. A& }
        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");4 @7 Z/ L& a& _5 }: A
    }5 c% n0 g6 i6 m8 D) m
    0 O4 w" R: T  @8 f! h, v
    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
- y: N+ L& t" }7 D7 _    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
' i( Y- m& [+ Y) I+ k* `   
; E) {4 g. z/ V/ M3 B    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");
0 p  Q) ?! Z" I: W  P+ @   
, L% x/ Q0 X2 K9 h, d+ E- t    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
+ V; W1 h- c# q, r7 x! o/ V    3 p7 x1 L$ x" x# d
    NXOpen.Session.UndoMarkId markId2;/ F9 J; A+ z. M& \
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");) r* g7 }# `5 I1 U$ o: u& L/ M$ _
   
9 t: f6 l  D1 A- s) t    NXOpen.Session.UndoMarkId markId3;
1 Y. l; I1 P- w, ~& z9 b* ~- q    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
4 q8 H) ]( o# Y% g* u    7 d4 d# M) y& `2 c& v0 b
    Curve[] curves1 = new Curve[fhsl];
5 Y+ K' G* T  s! z    Line zx = null; ;
) b5 z) p- ^* \7 {/ R    Arc yh = null;7 l) U. x$ }* ?! E6 ~
    int bj001 = 0;
1 Q! F1 Q) s% z: W    for (int i = 0; i < fhsl;i++ ): l& R+ y9 p0 V
    {! Q2 z: }/ p; e- |$ v/ V
        try
' ~; f3 Y7 o% M! [9 C        {# ~7 N* p8 ~. g" w. M
            Arc body2 = null;
# A0 L4 h5 Z& B* D3 r! Y: O            NXObject object0;
5 w) R2 y. R1 I            // Tag body_id = NXOpen.Tag.Null;
0 N' r3 Y. E9 q: l3 x7 e* q4 A4 S& z            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.3 _# i$ ~: [' T; b
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。! A& i2 q' l4 E6 d4 _$ Y! g# O7 p
            body2 = (Arc)object0;' P; y( x  ^9 T% c5 N
            curves1[i] = body2;2 ]9 s( r2 W$ i5 w5 N2 I8 C4 D
            if (i==0)( _  {( _+ r: o4 G
            {
* W- P. a$ K  e; u% u. ~                yh = body2;
% o0 i& M* e% _$ G. M8 K                bj001 = 1;
7 w8 f4 Z& Q- ?4 |            }5 O6 [) c! B7 w0 u* C
1 I& g/ f8 @8 D& D! b* Z
        }
8 y! b* {, A( T        caTCh (System.Exception ex)
3 o' e0 v- Z, |! U2 i; m9 J2 X        {        ( e/ P  c" E. A3 a  r- e
        }
# I( {5 D- q, y6 [8 k        try* \! ~; h3 T- m  m4 I
        {
$ A& @  w* ?' w1 \  {% n            Line body2 = null;
5 n9 T" l4 U" W9 M8 L            NXObject object0;  C( K( [; H2 w" Y3 K& f
            // Tag body_id = NXOpen.Tag.Null;( r: w1 F# G3 o9 x
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
% B- P) U; a5 H3 _( E9 c" y& n            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
* @! {0 ^2 {$ ]; i            body2 = (Line)object0;* ^( N" l2 e) Y# K, l
            curves1[i] = body2;
2 p8 g( k! m0 L! @! f            if (i==0)
8 D# [1 h' s3 L& N' s            {
! e# ~9 N* ?$ y" y8 g4 c4 i                zx = body2;" l+ N" b1 r6 L# ]4 X* O
                bj001 = 2;/ a6 Y" q$ U$ W: {% y
            }
9 m1 G" e5 t+ y2 }! p        }
0 X; z& _4 K- N6 n* d0 e6 E# J! d        catch (System.Exception ex)/ B1 R7 ~! a/ M! F# r9 D
        {+ Q( R' h3 H( {% L; K6 |
         - x: O' O  r# f
        }$ D% T% Y  T" @) s

, U$ u3 Q* u1 z! z    }
8 e2 d' Y0 V& w  x* T7 Y, H; P* Q( ~8 b( x+ y. I
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");$ [# y9 X& m5 ~, S$ L
//     curves1[0] = line1;6 K! _, q) O7 ]/ L- [1 S3 l& z# F
//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");
1 J6 k; h% T& E( I9 }//     curves1[1] = arc1;
- Z, w8 I7 Y0 [" x//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");7 r& J$ B6 |' ^8 I1 W9 |
//     curves1[2] = arc2;
$ F) `$ u1 z/ J2 C6 V( T//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
6 \4 c! {; E3 i6 d7 a//     curves1[3] = line2;
5 R8 z8 _, ~" H* j# h) g( F: ?( B//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");! m6 r8 n) k5 O& v) C
//     curves1[4] = arc3;: h3 N& N6 P$ p  f) h2 q* h
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
8 a3 y# y1 }7 A$ Q$ A//     curves1[5] = arc4;4 p/ }0 `# w% h2 Q3 ^
    CurveDumbRule curveDumbRule1;
% H! O. Z! X3 |/ n& R3 I$ f0 f7 `    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);! T- W8 Z6 c8 S
    8 d; M+ L" `  ^$ p% T  w( n0 x
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
9 s! ?2 l0 m1 J   
+ j% h2 f) [8 V    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];- h6 z* A% I* q/ d9 P3 {
    rules1[0] = curveDumbRule1;2 v* V0 Z* p3 O. o2 P
    NXObject nullNXObject = null;
' M7 S% q+ u1 O9 P' S9 @" Z: W  Z! f    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);8 w3 Q3 e5 ^  J
    if (bj001 == 1)& x3 X( S" C% O3 O5 J* M# g
    {* _( S1 w8 S1 K" E6 y3 t0 x2 p
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
* ^8 \1 i/ w1 y! @1 Q3 p% H" R    }
  Q6 h; @4 {* J' F    if (bj001 == 2)
( m+ [8 f" p! E7 m$ i- G" }    {5 s1 d, `  r. k2 Y; ?5 s
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
! Y8 ?$ @$ L  _& P0 T; X! _1 o    }) v, ?" F8 v8 p' _9 S
    & @+ P1 ^4 a" ^  M
    theSession.DeleteUndoMark(markId3, null);
" c% ]7 j+ Y; }' X4 `$ t   
& a4 F/ G& a0 h2 |/ j. o( _- R    theSession.DeleteUndoMark(markId2, null);8 ?- s6 }- d9 A7 Z7 J! Q
   
5 {) o& u* M8 I6 v    NXOpen.Session.UndoMarkId markId4;8 d% P  \! |* G
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");) z2 ?/ u2 u3 }! R- @
   
# _( u" T6 ?2 R5 S; J" Z0 y    NXObject nXObject1;# X& ^: c. A' i- b7 O, d! k
    nXObject1 = boundedPlaneBuilder1.Commit();$ }/ z3 c7 t, t$ ?, c. j1 @$ ^
    / H9 m( k3 x( x1 ?
   
  u0 }% b- I. }- A- p7 R+ v0 x    DisplayModification displayModification1;; N% B: j! ~+ r& a6 @- M$ u
    displayModification1 = theSession.DisplayManager.NewDisplayModification();( T7 }& Q! M! S1 ~4 u% ~1 z9 u/ K
   
( N* f! u. Q) c! p* S( v6 y, b    displayModification1.ApplyToAllFaces = false;! H3 N" B* i4 L5 w5 m& ~# f
    % z8 B7 R8 F: e6 w/ }
    displayModification1.SetNewGrid(0, 0);
9 G7 [0 i! E5 [: s+ r/ H   
- f1 |6 ^, h% `9 r3 J6 L    displayModification1.PoleDisplayState = false;  b0 c* F) V* e  M9 U
   
7 T' E: }) R  E# G    displayModification1.KnotDisplayState = false;
$ U# z8 d; E7 v4 t' O* M3 H   
  y7 t0 j1 o8 H! b; m    DisplayableObject[] objects1 = new DisplayableObject[1];
3 r1 C% [3 m  ?5 A. m# W* r( e    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;
9 ^* o, n& [0 @4 R) s  R3 e! @% s+ s    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
' m2 O/ w& C# y9 \& t   
  A5 A1 Y3 y% |        objects1[0] = face1;" ^9 l9 B' h( N8 g- g3 `0 |; \3 z
    displayModification1.Apply(objects1);
4 W* B8 _. V+ i  l    face1.Color = 32767;" f1 O- n  A  _( S; s: x4 M
   
% S# A8 h6 o5 _( @) i- e$ C) P    theSession.DeleteUndoMark(markId4, null);- A  b7 w7 u0 b- l
    : }/ s% R- ~0 J5 M7 e# p; ?
    theSession.SetUndoMarkName(markId1, "Bounded Plane");9 x4 e+ X6 Y2 p+ v3 B- R5 I1 X) {
   
/ [7 l8 G. `! W7 b! J. Z: t& H( _    boundedPlaneBuilder1.Destroy();$ w0 T" Z4 B) m( y9 A6 h
   
( u2 f, w4 p- n: b3 d8 G# r       /* if(fhyi==1){2 g0 ^* Q- _2 h) r4 M1 {
    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}/ w& R* }6 i& U9 T0 T
    if(fhyi==2){
6 [8 W+ W$ s. N2 m4 e4 H! R    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}) f( W* `; m/ [( o+ h
        */; u* [2 {6 @+ ]4 N% I! D
    // ----------------------------------------------
$ `% C( `" I/ T* P    //   菜单:刀具->操作记录->Stop Recording& _+ d( }3 ?7 p+ ]9 i: h' }
    // ----------------------------------------------) K# K9 S: b: {' C) P4 t4 k1 F
    ! I, `- A; X  \: }
  }
9 j, e8 N+ _9 M5 s+ B9 W& A$ @* [  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
! A  ]; Y+ Z& d6 Q" `- \}) m* E- F) \! W: K3 S6 H) g9 x9 c
这是录制有界平面点选封闭曲线产生的日志
: Y' c* g) @0 q+ P3 t我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了 1 L$ x% j- _3 P, E
NXObject nXObject1;5 n+ z* a" v* Q' B- _2 g1 B
    nXObject1 = boundedPlaneBuilder1.Commit();  U7 I* `. p' a  s$ n4 h; P6 W
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值
- ]0 @  b" r! ~! J& A4 ]& h6 l9 Z/ ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了