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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;3 W: R( |1 L7 t* O/ {- {8 g( }
using NXOpen;
+ l& G* @1 s$ eusing System.Collections;9 f! c) P# [8 h4 C
using System.Management;- r4 {5 [  O. _
using System.Management.Instrumentation;3 A/ L' V/ c1 E' G& |
using System.Text.RegularExpressions;
7 M4 J1 w3 i3 X( `: ^using System.IO;
7 T5 ~& J7 Y9 Wusing System.Collections.Generic;
' w6 e/ H+ H  k$ M0 y2 b, m  jusing System.ComponentModel;1 z$ ?. T7 f* A, T# K2 X
using System.Data;, Y1 H  J% e" f9 ]+ Q. ^/ N
using System.Drawing;
- k  B2 [4 T$ L7 s& Ausing System.Linq;
4 B% v$ s2 J- l' c- Busing System.Text;
8 v  c1 y4 F3 R9 M5 g1 Yusing System.Windows.Forms;# i# l1 i* q. D7 e5 t
public class NXJournal5556 G2 b5 B( t/ f/ Y- |
{+ Y9 B; E0 n4 K# u. M
    public static void Main555(Tag[] bj, int fhsl)
4 M: O6 G  j5 A1 y5 [+ [    {
* }9 s* m, m7 u# P  d        
1 r: r$ f$ O. [4 y3 H  ~    Session theSession = Session.GetSession();8 f' K6 X8 M( K
    Part workPart = theSession.Parts.Work;. W* o1 b! s6 t: E, X. w
    Part displayPart = theSession.Parts.Display;
9 Z; z) ]+ y" P! n2 V    // ----------------------------------------------
) n  V! H5 o( t  W    //   菜单:镶块->曲面->Bounded Plane...8 Y. S6 k1 `  m8 y3 D
    // ----------------------------------------------: H: E; L& K  [1 s6 T( G/ m
    NXOpen.Session.UndoMarkId markId1;
" V8 E3 p" |0 O5 u: P    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");9 V( q# R' q( d1 Z8 n1 s( e" d
   
. c5 @- O; n3 K1 b    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;
  d, U+ p/ B3 y" C    0 z7 \4 M6 f/ S+ k1 I1 U
    if ( !workPart.Preferences.Modeling.GetHistoryMode() )
; Z2 r  [: X4 H8 n3 c7 B    {5 s* A  @( J) [( d- a
        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
, G! I9 _9 G3 C( B7 b: B' a; [! c    }5 h* q  J' e5 k& B( G8 _" W
    , u( i4 @4 }2 h; h) O! a/ k( A: \
    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;. M' x/ G8 Z; V" M+ j
    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
2 D) g5 W% e7 t3 e    ; {! {5 j3 ?5 Z9 E* U8 {
    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");2 o1 U$ f9 c' ]
   
, C# z2 t1 t0 |8 W    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);  [  U" E6 X4 h  k6 P
   
- S7 t9 ^3 f( w9 c- j' h. |5 M    NXOpen.Session.UndoMarkId markId2;3 v2 N; f2 o8 d/ T5 ^3 X# t/ I
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
, x- U5 l9 }4 R7 v    & |" I# H, S; e( K8 P, u
    NXOpen.Session.UndoMarkId markId3;
, g, s2 `9 k: l" F' B* d    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
! m1 R8 x" u: ?, B   
3 ]/ g- g# d; W0 w/ g" H    Curve[] curves1 = new Curve[fhsl];2 }  N8 K, a8 z. n6 u( W
    Line zx = null; ;
- [0 j' K$ m' x1 T7 U% u. |: g' w2 K    Arc yh = null;
0 `2 q/ R) q" I$ n- F    int bj001 = 0;
& t# {; f( V/ ~, ~2 J  {    for (int i = 0; i < fhsl;i++ )( S7 d) N9 S9 a: D6 a1 Q9 {
    {1 U3 {% E, x- d; r9 l' y& ?
        try
+ }! \: x3 ]' t9 r0 p! x. z9 }$ ~! Y        {
* J0 X) i: M3 |# n5 x            Arc body2 = null;
. J* `- [3 G6 h            NXObject object0;
$ O- t2 ?: p* d/ [; q: {+ z            // Tag body_id = NXOpen.Tag.Null;" L0 l5 V. W) o- X% g& U  x
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
1 X  L: u# h& k1 @9 B& R: `: D            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
. j& m- e9 d. n0 u5 U  r            body2 = (Arc)object0;
+ _. C) X! s' t3 W: F            curves1[i] = body2;5 S0 u9 \/ B7 q# u8 m% b# N
            if (i==0)
7 d7 I. u, Y# ~+ @8 ~' e            {9 g. z, ^$ m( S. q" ~
                yh = body2;
, e5 g1 q2 Z+ {- D4 v                bj001 = 1;
" x/ T* A4 W* K; ?# U) W            }) B! Y) A! F3 u% m3 u" ?# a

& ]" P: b: ^; `7 d+ `& J+ J- K        }
+ F% Y1 |" z# P        caTCh (System.Exception ex). @& W) n" U5 U3 Q3 U
        {        1 z+ j" Z9 l: @5 r# j# l0 o
        }9 m& b( g; Z# L. m' b' y# ?: D3 k+ w
        try
6 w6 n6 e. h: P# @$ g$ T: K        {) C0 k: L/ d3 M% r" x3 e0 L
            Line body2 = null;
; d2 Z/ R  m3 G  ~            NXObject object0;
5 p( j9 {3 b/ p8 W# j4 u' F            // Tag body_id = NXOpen.Tag.Null;$ t1 {0 r" n. {& F
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
9 x( ]8 C2 k; r1 Y3 h; ~1 O2 O            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。5 E3 }, p0 X( O' `
            body2 = (Line)object0;
& @, h5 D' M* t; M% O            curves1[i] = body2;
$ a; i3 W, T5 N            if (i==0)
4 s8 A9 R$ D; t# W8 J6 i; u9 e            {
& f) a' v% b2 b                zx = body2;) \- C0 ?% t' j" @# U$ J8 \8 K
                bj001 = 2;
% D. A2 b) g# n4 Z. Z( r            }
& C9 B' w5 O7 T- V, [0 H9 Q3 a$ ~# d1 w3 |        }
( C' e* m* a; T        catch (System.Exception ex)
5 @6 P" Y9 ^6 k# m$ n- x        {
2 T1 [$ Y% u5 Y# c/ ?1 Y/ b8 E& C+ v         
! o' h/ {+ n; K, ]; r6 s        }, k" v  n" d6 ^1 _
. g1 c, V" Q7 t3 z& U
    }
) P6 j# d6 b0 z. }0 u9 {
( |" O9 j* }' }& k, I2 V& D//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");% B, H2 R! c; f* }7 ~( a" I$ T$ Q! r$ F
//     curves1[0] = line1;
$ K( R# @6 Z: E3 S, H1 ]//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");1 D' h5 x' C4 G) D! x* o1 q
//     curves1[1] = arc1;
9 T5 \8 u& N( c) ^( X//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");  l$ R' V, ?* H0 i- L
//     curves1[2] = arc2;7 x- x, K3 p7 {1 }% ?) u+ Q
//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
1 }7 v$ Y( D4 d4 }//     curves1[3] = line2;# _* B! c5 E  P& ^: j
//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
, m/ U. y* z" I& k//     curves1[4] = arc3;2 ~2 d# b7 R8 s' |
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
: h7 w; s/ E! I6 e. I  Z//     curves1[5] = arc4;0 N% N4 m' G$ d4 `
    CurveDumbRule curveDumbRule1;5 ^  R2 n9 p3 L9 M8 T& v% O
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
$ [$ z. H4 O0 h) T0 i    5 f* F. e2 i# @/ N
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
  L  A6 Z, _& h7 ]   
8 ?! C" m, I# E* z/ n    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];6 }) F# Z, s/ F+ T
    rules1[0] = curveDumbRule1;
% m3 i; E( N9 r    NXObject nullNXObject = null;
3 l# Q# q  r) X' |! ^$ W  c    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
. O# y4 c+ P7 \2 a9 m    if (bj001 == 1), T+ @6 r! n& B# B* q- S1 b1 Q8 y
    {
/ ]: N! s$ W% m8 T4 z; f* z) @( p        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);6 A* q  e- [: D  M
    }3 J. l& [# B9 q% I8 h+ N6 l) t3 ]; a
    if (bj001 == 2)* X. Z& o6 f( D6 V5 g8 o
    {
4 d' }& ?- v  J" {) ~        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);1 a2 k( N/ W! N
    }
- Z* N+ p# \2 l+ ]  M$ i    3 D2 Y4 |  b/ P' G, u
    theSession.DeleteUndoMark(markId3, null);
: W3 k* B# R1 U& S0 o% J    1 F8 v. b) e* g7 [% t) t% H
    theSession.DeleteUndoMark(markId2, null);
. Y& b3 x7 Y. ?! \% t   
  w, k5 r+ c2 ~    NXOpen.Session.UndoMarkId markId4;' `' D) U/ f" N8 b
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");# X. j; y; N) m; G0 L9 v
    8 G- P" f5 v1 |6 `
    NXObject nXObject1;- |) J' o# M& }; ~
    nXObject1 = boundedPlaneBuilder1.Commit();) p& c  v8 i# {& l, M2 y5 K- G
    2 Z; M! Q5 H- _- f# t
    4 Q9 }% u( B4 ?
    DisplayModification displayModification1;* X; |" K6 w7 y0 e
    displayModification1 = theSession.DisplayManager.NewDisplayModification();
. l4 l  _: L$ K* U   
$ L3 G6 U6 ^" L    displayModification1.ApplyToAllFaces = false;
! {/ r1 j6 c$ f  z    ! S9 h' t% n* i
    displayModification1.SetNewGrid(0, 0);) \: B( t9 ]3 B2 A
   
# f' w# m; {* V& l    displayModification1.PoleDisplayState = false;# |: p0 p; g7 p2 n& ~
    0 t" [9 ]! l6 J& V2 z, z6 c
    displayModification1.KnotDisplayState = false;
/ z) P: n2 i/ m   
$ M4 Z' t4 c: Y" s& _" n    DisplayableObject[] objects1 = new DisplayableObject[1];7 L8 Q' b2 n6 h
    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;1 A' X( N1 V, R4 j, l! |0 [$ r
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
% x) t9 a6 C) ^' I. |& X0 @   
" \1 X2 Q/ ]1 n        objects1[0] = face1;" i9 K# K* P2 R5 ]2 O# @5 {
    displayModification1.Apply(objects1);5 e$ R. D' Q' d) T9 H- P, w
    face1.Color = 32767;4 m5 Z5 U. h( L
   
. _: g( }# D8 j5 V$ G+ x. p) v    theSession.DeleteUndoMark(markId4, null);4 q: D$ ~  }( K, f
   
5 y0 m/ s* P5 D+ R9 b4 j( u) S; b    theSession.SetUndoMarkName(markId1, "Bounded Plane");# |$ v7 N; I4 I* E# }' Q& L
    + m  n: I! m# n5 V$ p- \) c
    boundedPlaneBuilder1.Destroy();
2 ?7 e$ }6 L4 Q# I. @/ ^! y4 b   
" z' `/ t# H& ~5 ~) k       /* if(fhyi==1){) o8 v% N/ C: `- G! T* E5 U
    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}  q; K5 r' t8 o! @/ F; i
    if(fhyi==2){$ C1 ^* i" R$ f4 v* M
    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}: U; J& e: P% \( U
        */- N: i2 C0 o& Z0 ^
    // ----------------------------------------------
. S  \# N2 q! h- J! h    //   菜单:刀具->操作记录->Stop Recording
- M  U3 N# i: y; q1 L    // ----------------------------------------------* ~( t% N( y2 |7 F& B$ ^
   
6 E" ~4 O3 Q" j6 _$ h6 W  }
2 A( O8 P7 h$ V  ?* A. r7 w9 v% u  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }. e# z4 N/ J( ]$ V/ k# ~( F3 t
}
9 S" G) C2 ~. E# \6 f& M这是录制有界平面点选封闭曲线产生的日志
9 A, e* {7 ~- N我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了 " W0 @- y5 e8 T  w
NXObject nXObject1;3 I: _* u, R7 ?2 }1 p4 k
    nXObject1 = boundedPlaneBuilder1.Commit();# B& u+ F# q- v! G
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值
0 |8 g' v5 F' x) l+ k  o& S  U4 K" n& j6 ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了