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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
% W+ q8 q" P: s5 D3 v; A) Iusing NXOpen;! T; m* `9 p- r
using System.Collections;
5 s8 S# h; E" I+ w, p2 Lusing System.Management;1 Q5 J! n6 c9 J8 Q2 b4 @
using System.Management.Instrumentation;  ]( H9 x: L- ~9 T; f
using System.Text.RegularExpressions;
0 L& I' Z* K7 c, O8 ^! E9 Qusing System.IO;3 E% z" `$ V, ]/ B' X" L
using System.Collections.Generic;
: c) s8 z" G  c! U! h2 Z7 X4 Xusing System.ComponentModel;. s. m/ t. N3 [2 a, \
using System.Data;
. z. |6 t; y/ d4 W( I7 pusing System.Drawing;# D! w1 _2 R% X$ H# r4 g+ s3 |
using System.Linq;1 k. S* S' a1 a
using System.Text;: r  b) z: _; {3 O) ^& N
using System.Windows.Forms;; ]& W7 e& A! T6 g: x1 I% i2 s
public class NXJournal555( j& @9 X# h5 A1 I3 u/ @
{
& X% u3 l5 r1 }8 L    public static void Main555(Tag[] bj, int fhsl)$ P* }7 @9 U3 j8 G: x4 Z/ k
    {. Y. |% j$ B$ \6 i$ U: G/ n
        
" ^* Y1 ^% I; i6 t$ |: z3 \  A* P    Session theSession = Session.GetSession();! q: V( v& i$ X) k8 P4 J' J- a+ t
    Part workPart = theSession.Parts.Work;
- T4 L; u/ Y4 r" F, r7 M" n" R( M    Part displayPart = theSession.Parts.Display;+ W) B" I3 H# G8 ?# o0 Y
    // ----------------------------------------------
  y! P1 T, g- a5 |8 N    //   菜单:镶块->曲面->Bounded Plane...3 @+ P: Z2 [2 J( S7 }
    // ----------------------------------------------
  b. ^8 o* R) A) K8 u* X+ }    NXOpen.Session.UndoMarkId markId1;* G! p  B8 v: W( B" a( |
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");( |" O/ A' Z' n2 t7 r, @6 L
   
# k; Q2 ~7 W  G7 d    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;
5 ~$ ]& j2 i# E# T   
) }- M2 e' {  V# u5 I. |- e& V    if ( !workPart.Preferences.Modeling.GetHistoryMode() )
% I  @) {% p& c, Z" L! b& M! P    {
( L; z3 N' i3 T% m2 g        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");) P) z- O  A" S5 ?5 P. g, r3 x
    }
+ O9 A3 p* M( `) p7 T   
6 u" q4 E5 x6 p5 v5 ]    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
$ V% w4 |& I! r& M3 j    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
& f, F) B/ C5 G' ~' M   
, C% J; c( x& n8 Y( x0 ~    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");
; o2 X0 ^/ ~7 n0 T    % d! d, d$ d+ n* f7 h
    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);) Y7 f0 K  J* b
   
& h' b: ~. q0 {, I7 G    NXOpen.Session.UndoMarkId markId2;. Q5 [$ C8 @" t% y( f
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
) r/ I5 }$ f& m/ M, U$ Y    3 K# d  d  \$ q
    NXOpen.Session.UndoMarkId markId3;# P2 j% L% `0 p2 e
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);. u6 ]* R9 V, n% w$ T! k6 V" h
    ) P0 B( M# p+ Z7 l
    Curve[] curves1 = new Curve[fhsl];1 A& H# z& h4 g! f
    Line zx = null; ;. I, D# N7 ~& K0 ?4 g1 \7 d
    Arc yh = null;; S: ]( F  r. S
    int bj001 = 0;
6 m' G3 \* z+ v. s    for (int i = 0; i < fhsl;i++ )$ h' ]& t. D9 X3 ?2 \8 i$ t6 p
    {
* o" ?9 t/ A0 I2 i* c/ n        try* x$ q" `; ~- C( p: R
        {
- D) ^: `0 {9 O6 T2 M4 ~3 O/ C$ l8 B            Arc body2 = null;
& i6 ^% j# ^2 V- J" I. m            NXObject object0;! [8 \! G2 d6 j* m2 O! }
            // Tag body_id = NXOpen.Tag.Null;
. b% q* N3 \  R3 J& ~- a0 z  ~/ O            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
# z: z/ ^' J, q, W9 t            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
* n4 D8 L/ N: X) C. _; L  \3 v. C$ {            body2 = (Arc)object0;
  J( H; F8 X8 J  s! u8 a            curves1[i] = body2;
9 }& ]- {0 `: ^            if (i==0)
; U. N1 U. B$ @            {
2 N3 F7 N! F7 C& `0 u# `                yh = body2;2 a' H- A0 H0 }
                bj001 = 1;7 z$ a- ?7 c0 K1 l$ a* I" D
            }) m9 M$ L( g% Q+ R0 W
; U& F4 d. r' t1 G, f
        }
$ a5 i7 S+ W( j8 u: e7 s        caTCh (System.Exception ex)
! [# x/ w$ P# z        {        
* v4 C# B' _" u: ?/ N& [3 O        }% v, C4 F, R+ y4 A+ P$ V8 W
        try  L8 x* f2 n' x! D& k
        {2 c; _  l; Z" f$ [* D+ {
            Line body2 = null;8 |& z7 V1 r6 Y/ r, z
            NXObject object0;
. U, ?: @3 ^1 l            // Tag body_id = NXOpen.Tag.Null;
& x" e- k: `, f1 S& V            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.1 D5 F0 `8 H) Q! s+ ~
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。. Q3 X* C8 t$ c8 T
            body2 = (Line)object0;
5 l5 K: L0 |1 A) t8 }+ Q            curves1[i] = body2;( r1 a  r" Q& C8 o2 i
            if (i==0)
: o# L) J3 ^  Y$ Q- d/ S3 V            {
0 s' }; k% e9 \$ t6 @                zx = body2;
: E6 R; M; Z" _. y0 t' q3 b5 E: s                bj001 = 2;3 K& ?  \" Z( l9 `2 ~
            }
7 {! h/ H1 c! h0 B9 R        }
) J" Q7 u; U. o9 o. _        catch (System.Exception ex)3 J2 V$ Z: C6 G  R6 g
        {" f+ i6 k, y) B, Y% Z3 d- n
         
. x" ^1 n# ^% V, y        }
  F- E" u% W: {" V& @8 H
9 W! b$ J! C: Q9 O2 c    }
$ {8 ^( L* I, p7 j$ N1 u  c& {! R6 Q6 T8 J5 u/ {
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");4 y7 I- B" e% |4 r9 P- N+ \. ^
//     curves1[0] = line1;
6 Z4 U4 h5 J8 u1 O0 b5 Q; u//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");* O' A9 t4 O8 l2 ~- h
//     curves1[1] = arc1;
* P+ |/ p5 Q, |+ c, s7 V4 [+ W//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");: z) e# b# ~; m# q5 ~
//     curves1[2] = arc2;
2 }" ~- H  E/ ]6 _//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
* W( t, h, R! {4 \6 [- D! a0 L//     curves1[3] = line2;/ K& O& x1 K2 G( z+ M" J) \1 g
//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
7 v9 u8 s' w" q5 Q8 z# W//     curves1[4] = arc3;7 {1 k! N$ u* [7 ]3 T
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");: _9 v; `3 T* x4 ?! j
//     curves1[5] = arc4;
/ |# A! ^+ ^* ]9 I: x7 |2 s- s    CurveDumbRule curveDumbRule1;
! s( |' I/ s+ u    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
: ~$ T1 h% |* F    . z% O3 M& v/ P! M* M6 H# t/ J
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);+ r* E- |* P. z+ |' g0 u1 C
   
" [4 \; h5 X" h    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];* C& f  G" j/ f& ?( l% I
    rules1[0] = curveDumbRule1;
& D+ _* h! H) E' y  W    NXObject nullNXObject = null;
6 {  I+ k  m2 Z1 F; a" n1 Q( F    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);8 g7 s* Z! e: c# d& h
    if (bj001 == 1)
: j: W, A8 x+ m5 Z* W; Y' k( D    {
& A9 x0 ^5 B* z: x/ \# ?        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);* `% g: \) r/ V! N) o
    }
# Z. O# m0 R+ A! H' T0 R* y: b    if (bj001 == 2)9 Z4 `7 `0 m6 j1 n# m8 o9 `* }5 ~( o
    {
6 m) c0 U' _8 W3 W        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);" q. c: M8 s$ V
    }
, o! r$ I! o! b7 u6 O    ! d! b" }6 S: z3 a2 C$ q3 w
    theSession.DeleteUndoMark(markId3, null);3 W4 s: y: |8 L9 @' O& P' o  A
   
/ z9 \5 |5 C* p; y4 r4 U    theSession.DeleteUndoMark(markId2, null);
2 R; N! c: ]. w    ! c. m" L( O5 M" R9 n
    NXOpen.Session.UndoMarkId markId4;
5 P5 b9 N0 E0 y4 Z# C" }, S- t    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");, E$ d( Z7 e1 j; r/ J5 A4 [* V
    3 {' _# \: _2 G4 V$ w
    NXObject nXObject1;
  t6 J+ n8 {9 V9 q) m# x    nXObject1 = boundedPlaneBuilder1.Commit();1 \2 e& d3 \  _5 R/ s" a
    8 |. E" s1 z0 f! ^# r" R5 o
    7 r! L" T# h6 S) L( G+ N: d
    DisplayModification displayModification1;4 |, l9 v4 ]: Q! I  P
    displayModification1 = theSession.DisplayManager.NewDisplayModification();
6 R# N' y7 R2 R    6 I+ B3 h9 k) G5 t* U
    displayModification1.ApplyToAllFaces = false;
  I; k2 }& N  @! U    * r( R0 U( W! k: A: J: _1 k
    displayModification1.SetNewGrid(0, 0);1 u, G' g4 a# x! {4 O. ^& T9 q& q9 N
   
+ }, e* p. q- _: ^    displayModification1.PoleDisplayState = false;6 K6 y' ?: o1 W9 r2 T. O
   
' c2 m; ~! B5 S: L7 E    displayModification1.KnotDisplayState = false;
1 j. i/ f! E3 l$ P$ G8 T   
4 @; f/ J' p% k: }: o9 Y6 @    DisplayableObject[] objects1 = new DisplayableObject[1];
: x. O/ |1 l* t    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;! d* c* @% t& V1 O0 w
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");) v7 B. X7 A9 h7 F
   
4 ?$ Z& O4 @6 A  t. B+ `3 K+ b        objects1[0] = face1;
3 ^1 x# P% E* G- ]/ ?    displayModification1.Apply(objects1);
+ v4 C# u( a- Q) E3 b9 }; {    face1.Color = 32767;
5 d2 T8 F4 v/ C) a! z   
: f  a2 l% s( w; m, b) z4 k    theSession.DeleteUndoMark(markId4, null);
" c5 v  _5 ]: h# F   
& B* c6 j; d5 \$ \4 J5 d) R- }6 I    theSession.SetUndoMarkName(markId1, "Bounded Plane");
6 U+ Z7 u+ N# v0 b2 o   
0 o3 O: A* h( f& Y" X    boundedPlaneBuilder1.Destroy();3 X  ^; z* d9 \( w; E
    2 z/ R" n& P8 V; J7 n4 V
       /* if(fhyi==1){- }6 L: |4 i, N" m  w4 Z
    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}  ^3 ~* H5 e' c1 H; B9 j& k
    if(fhyi==2){
& B: D9 G6 f# H9 f) @    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}: ~8 b" B4 N- h+ ^' r
        */! A/ s# i1 S: t7 P8 X
    // ----------------------------------------------
# c: f0 Y+ a- q/ E; _    //   菜单:刀具->操作记录->Stop Recording
: b$ a, H# j( w2 G2 l1 S    // ----------------------------------------------
7 z( n6 ~9 \+ @" L# k   
$ R' X+ g" J  ~, m  }9 [5 ^) P7 A$ L, c9 F  b
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
! N0 [9 ~5 e$ P7 _& [. m3 G8 b# F4 F& }}5 N* Q# u; ~4 R" Z* ^
这是录制有界平面点选封闭曲线产生的日志
+ a7 X! E+ d% g7 e" f+ z% p我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了 4 t# e6 t! c8 G
NXObject nXObject1;( f, ^& s% U. v8 ~7 K
    nXObject1 = boundedPlaneBuilder1.Commit();$ x7 f  e- f; x4 ]. k4 b
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值
: u0 o+ W- L5 c5 L9 s
5 R4 b* n/ f7 B4 I4 s) I! 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二次开发专题模块培训报名开始啦

    我知道了