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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
3 k" z3 E' E2 P% {! F: f) `using NXOpen;+ a' G0 E& k& S. a7 l$ S
using System.Collections;) G9 q. `/ P" X  O6 \0 K* f/ E) E$ E
using System.Management;* J0 b( X( o! M4 `, X. y: }
using System.Management.Instrumentation;7 m" Y3 [! b7 k/ W& c7 l
using System.Text.RegularExpressions;, Q* N' B7 a) G5 v' [3 i( `
using System.IO;
8 e- d5 M& G" g# b9 }, s- Busing System.Collections.Generic;# g/ o* v- W+ m7 j" l( j1 k$ _
using System.ComponentModel;
$ Y& @9 `/ Z* j, J7 x% Pusing System.Data;: Y; `7 d; Q! I/ b. ^  s! d8 m
using System.Drawing;
# v7 H# v" Y: Z6 ?using System.Linq;
( Q* H9 l4 c8 Iusing System.Text;
: {& D* u2 B  t  B( b1 jusing System.Windows.Forms;% ^2 }- b" R2 i
public class NXJournal555- g: Z. j  B! r' C; [2 [- N' y
{5 L! P, e. @% Y, W0 }2 s" o4 a
    public static void Main555(Tag[] bj, int fhsl)
) m2 T7 T, {5 c5 u& H( |    {
5 A' N: j8 D4 n7 j        
0 Z3 `) K+ b7 o, Z3 c" K    Session theSession = Session.GetSession();
/ Q4 b, c, j4 J0 G, u    Part workPart = theSession.Parts.Work;, j/ g! _3 a5 E* S1 I/ y, }
    Part displayPart = theSession.Parts.Display;
. ^- E; V) }0 {* [" @, U    // ----------------------------------------------
$ _1 I9 H% ~4 F$ p* [5 d( L+ @    //   菜单:镶块->曲面->Bounded Plane...
, G- L! S/ E& R2 z* v$ R    // ----------------------------------------------
; }# v; C+ Y$ o, F4 x5 O; |' f    NXOpen.Session.UndoMarkId markId1;
0 G8 z) f8 F+ @7 @2 s" Q" M    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
4 K4 s/ K/ _0 Z* g% q( P) E% g    5 C9 V$ t. n0 c8 [7 ~* H/ |
    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;0 F2 x7 P- x4 f! ?2 o) X2 {& T
   
# S$ e0 x2 y+ W+ s% u" D    if ( !workPart.Preferences.Modeling.GetHistoryMode() )9 `6 U0 U) J! S; J7 p
    {
7 t3 T4 S' l- D# U3 [        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");. p5 f+ m. o& V8 m
    }
7 C: _/ u7 Q0 F) G6 h6 q   
8 _. \7 C, o- G- Y' s- Y. p    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
5 ^; ^( H# X# X! u    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);* g  F( d  `- w. F/ `" x0 R- d2 \
    5 J* [: m- I3 n- x1 W- B- o
    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");* r! Q- p9 [7 V& f7 \8 o$ a- h4 N/ F6 ^
    4 P( x. k7 ?1 D% r" V
    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
2 a" h) C6 L$ J) B* e- A   
$ p% g' v! w& I2 z    NXOpen.Session.UndoMarkId markId2;) H( M" y+ e+ [0 J
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");' W, r1 c! b* S8 x% b  f
   
  @; E+ @! c) `    NXOpen.Session.UndoMarkId markId3;( D$ D; |' a2 P& g+ M
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);( f0 ^4 t4 I1 o! l. I5 q
   
; U, b6 s% C" Z* z/ T$ w    Curve[] curves1 = new Curve[fhsl];- b5 V/ V3 \) w; Z& W  {. y* X( X
    Line zx = null; ;
- \2 u8 z- u3 ~' V3 o% i    Arc yh = null;
( M5 ^7 D6 x1 g7 M; [$ E( L    int bj001 = 0;
1 _/ C9 O9 I2 Z% }! P- `    for (int i = 0; i < fhsl;i++ )4 w5 n1 H! K$ u% o5 b
    {% G4 T# F( h  F8 @
        try- x2 v" r, A. p
        {
+ h( _# s8 V8 [( b1 u# G" M8 k) G            Arc body2 = null;
: Z: \) X0 Y. @" G" c! P# _2 ~. d; r            NXObject object0;6 M$ S+ a* I) c3 r( z9 N/ q. z
            // Tag body_id = NXOpen.Tag.Null;
% m3 g( U; B6 X: z& M- Q& p' Y9 k            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag." B( v  V. u) n% h
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。$ `+ A3 y6 k- G
            body2 = (Arc)object0;
" c0 h' u- I0 O            curves1[i] = body2;0 S5 _! O, r, c1 G  r5 l
            if (i==0)
+ W" ^2 G7 n2 [/ z# H! P            {' `& k. o0 f; r1 X' M1 o
                yh = body2;
  I' j5 |5 Q, S3 S1 ?) t                bj001 = 1;
0 c9 @1 t7 E1 f            }6 H0 ~6 W& B: B( Y
7 |7 _4 N4 A) G6 K  T
        }
! W( G$ b) r: \& ~5 k" G% d% C2 ~        caTCh (System.Exception ex)1 Q. o. e; F+ l3 T6 }$ i$ G
        {        
, n" h* ]. N$ N+ z3 q+ P. S        }
0 R0 q+ I6 G( e- H        try, W" T! j6 R' v, P" k. \% {
        {
. Q0 D! U, T% ~$ k/ P3 x. p            Line body2 = null;
  j  F1 a5 ~. p. [            NXObject object0;4 J5 i4 M* ]2 w, D' V) O
            // Tag body_id = NXOpen.Tag.Null;
7 b3 ?" p: j+ I  N" `            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
4 y: h* r% o. R6 `, K  ]            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
6 w; W  P+ W$ E            body2 = (Line)object0;4 e6 U0 [9 s! n. y: M2 v9 ^
            curves1[i] = body2;9 J" `' ^+ F1 L! j9 C2 {+ M1 n
            if (i==0)# p2 ]' R/ q9 X4 p
            {
9 Z6 Q6 N5 {+ I' s2 b                zx = body2;7 V% v1 m/ @- E$ M! a7 m' r
                bj001 = 2;
' u6 s+ _3 o; x6 A# b+ L4 p            }
7 U1 P1 H- _" T        }
1 ~7 f7 j( E& R        catch (System.Exception ex)' ~" o- C- K- @9 v( e* l
        {
5 l( Q0 U' h* m+ Q         
  {: m+ o5 k$ f. S5 W        }
* w1 A& [6 Q& F$ h9 k9 X2 {1 M, {( z; y( w
    }* M. Z, X" v6 Q+ g
, m/ v4 U0 p" F
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");. g1 }8 Z9 z8 J/ m% V: L9 m2 Q
//     curves1[0] = line1;
0 e3 |& c" l2 o+ G  ^% C/ d1 k- z5 l//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");! C. w  F# o$ }( _' k6 }3 Z5 y
//     curves1[1] = arc1;
2 N( E7 o, x6 b2 t% w//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");
1 I. j, K9 h1 o' j2 \" e//     curves1[2] = arc2;
, u- _" O. n/ f5 o1 x! W//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");; ]# C6 i8 ~9 [: A6 A
//     curves1[3] = line2;$ t$ I& u! L% |7 l# t5 e, _
//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");/ ]% v  X( i8 Z( a
//     curves1[4] = arc3;; }) i! _4 Z% U: b% I
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
3 \: V$ z# X, o3 X) z1 E5 \//     curves1[5] = arc4;7 [* c; e( H3 J, |, l) t' I
    CurveDumbRule curveDumbRule1;  s, D+ X% Z. E& q( P/ u
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
/ v& ^# @3 v1 V" D" u1 j    ' m: `, V- \5 X# @+ X
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);* h% S# E1 i6 J
    : @; ~( y9 A& Q( p) d3 m5 q
    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
. a8 |- }, O1 o; o    rules1[0] = curveDumbRule1;+ n& Y; D7 Y5 J
    NXObject nullNXObject = null;6 g/ ~6 ]3 [' v
    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
  w5 v6 A. u, A' V    if (bj001 == 1)
! z( _% m5 f; c! |4 u+ w- |1 v    {
& s$ m8 u/ E8 l! ]        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);/ b4 c. i7 @8 m1 B0 t
    }
; C& }' Q+ [4 q9 }3 N- [    if (bj001 == 2)
5 }/ t6 l: T6 e2 B    {0 d7 c4 _1 m0 d* f- b/ ~' i2 j
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
# D  [) d7 s& b* G9 X" ^# N4 v/ K    }* s, Z1 v. e- W$ p7 X
   
! C# j9 u' v0 N4 g  I7 D1 {  ]    theSession.DeleteUndoMark(markId3, null);
  X3 t$ o4 n# f" b0 O    4 ?& l8 |: \1 O; s% e6 h. @( D
    theSession.DeleteUndoMark(markId2, null);
5 t& F, t: K/ F% i) X1 z& v- x   
. J2 i0 q+ ~; H! u5 D+ p    NXOpen.Session.UndoMarkId markId4;/ J: r$ B0 _; x' V/ u
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");) w) r" z0 U2 T: H" N0 T
    " p& }2 |- o& T- Z: [( @
    NXObject nXObject1;
7 l$ f* v% e6 m$ }    nXObject1 = boundedPlaneBuilder1.Commit();5 L+ ~% q; U+ x$ u2 X7 [
   
" [- i/ C* W# m, M/ E9 G% m4 {/ h1 c    $ v9 b% }4 J% z
    DisplayModification displayModification1;6 L: F9 r" D  f1 Q: I0 }8 k. d( y
    displayModification1 = theSession.DisplayManager.NewDisplayModification();9 R4 |# q' h5 Q  }6 }4 C
    1 n) q0 A" X4 E* `$ X; N
    displayModification1.ApplyToAllFaces = false;
; c7 J6 ]% h0 T    ' g! V: ?5 V! d7 T  i  [
    displayModification1.SetNewGrid(0, 0);
0 i: b+ z/ e  R8 J7 J    2 {* B4 k# @1 [6 w8 a
    displayModification1.PoleDisplayState = false;/ r: \$ D3 }. h$ e$ N
   
6 r, y$ z- S2 t4 ]+ x+ r( l( z$ X) }) S    displayModification1.KnotDisplayState = false;
5 F# V7 d# s  [8 j; d+ s% S    ! t% d4 k) M3 _
    DisplayableObject[] objects1 = new DisplayableObject[1];
/ _9 u$ p, M6 q  P2 L    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;- }' Q) Y# B+ g& I" V% ~# p' t
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
" G* g% r1 d! N) q- U. t2 }& U. C1 v    1 x) M  Q) U! n# Z' p3 f
        objects1[0] = face1;) A1 T0 K! z( s: V
    displayModification1.Apply(objects1);5 X  q. W: e+ X) _4 u5 d
    face1.Color = 32767;
  R3 W  o; W. D7 F0 X    ( n, l% `0 J7 f' x4 j: U+ U
    theSession.DeleteUndoMark(markId4, null);
0 H! R; j( f* X9 I, T   
" b( @1 |/ {6 b( R$ p    theSession.SetUndoMarkName(markId1, "Bounded Plane");
) u2 {" _* D- Z    * `- t- p' c  A9 L4 j, u
    boundedPlaneBuilder1.Destroy();
" d8 O3 r9 w8 A6 k7 ~& ~% X   
6 ^/ o" s" ~/ B: _& t% P" u, O- ?       /* if(fhyi==1){
1 F( j% x( n. h& t# K# ]- \; Y    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}0 q: M. |# h: `4 t; T: O! b
    if(fhyi==2){( y% Y/ w$ x1 y8 {
    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}3 y& \9 T# g' Y% f6 @' f
        */4 d4 ?, x( R7 Z  y: K% P0 J+ I2 H
    // ----------------------------------------------2 ^& c0 L8 C9 [5 C# o9 x
    //   菜单:刀具->操作记录->Stop Recording1 _  Q+ @2 i7 b! n) V; V& L
    // ----------------------------------------------
# M) M0 r5 T/ Z6 @  y% o    4 P2 `# H% `% b5 M$ S' }
  }! }# @* u  Z" I+ G
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }  B0 e8 |) W/ r' a0 P$ \' j9 f; L
}
! U2 c# q# Q7 b9 a4 q这是录制有界平面点选封闭曲线产生的日志
# v3 s& m4 C, G6 A( ^+ H5 h我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了 . A- K8 ?. G+ R  p. Z$ a
NXObject nXObject1;+ G7 N; G  h; J* q% x# @8 D
    nXObject1 = boundedPlaneBuilder1.Commit();7 n/ [! `$ @7 r4 t
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值' k$ z# \( k. f- ~8 B( f7 a- |3 \
( [4 p; R5 J" x( c5 q) 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二次开发专题模块培训报名开始啦

    我知道了