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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;
1 l) z1 b  ~5 w8 h1 V  Jusing NXOpen;8 i  v5 ~" D7 T4 D
using System.Collections;
( h( D1 c' x' _  ?( Y# ^: y5 `using System.Management;" Y/ t- I0 q# V5 E
using System.Management.Instrumentation;9 K* X( T" T$ T
using System.Text.RegularExpressions;9 ?  J; m9 J4 e, z
using System.IO;
9 s: H1 T  e9 H/ Zusing System.Collections.Generic;' w- a3 Y/ W( r3 _, }
using System.ComponentModel;3 l/ u$ e" E& d
using System.Data;" J4 X+ B6 y+ S/ }' X' @8 N* o, s
using System.Drawing;, Y+ }% {5 V8 m2 M- ~. O* J
using System.Linq;- n* H8 Y+ @$ @, d% S: g( h# G
using System.Text;
7 e+ F, y; G" s5 f2 x6 x! @using System.Windows.Forms;
8 w: m1 d2 V6 M- i- z& {: Xpublic class NXJournal555
1 K# Q' g! U" b. O) u{7 x9 |' x. c$ e
    public static void Main555(Tag[] bj, int fhsl)
0 S' j& K8 e8 P1 A# D  x    {" B- }  h& [' X9 j: e. y
        $ e" l' B( V( K6 C( ^" R9 B$ t
    Session theSession = Session.GetSession();0 S: [' ?; g1 [
    Part workPart = theSession.Parts.Work;2 ~0 k: p) Q1 w: ~  `. A
    Part displayPart = theSession.Parts.Display;; N0 _. j7 M! c/ m" u3 t
    // ----------------------------------------------5 y& b1 b) [7 H1 z  B: Z9 g' Y
    //   菜单:镶块->曲面->Bounded Plane...
5 j  K' n( \- H/ ]& J/ q$ j    // ----------------------------------------------2 B$ h# |. K5 @. L& `
    NXOpen.Session.UndoMarkId markId1;) [; ^8 Y. t1 ~2 X+ K
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");9 H5 D5 x( H- ^) i
    - X$ w# s& t! e* [7 m1 m
    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;# ?+ k8 l& S) ^( @
   
% _# d, o, H8 x( ?+ V+ L    if ( !workPart.Preferences.Modeling.GetHistoryMode() )9 e' n8 i8 z) G! m: F6 y
    {
8 Y4 T  \7 N9 L7 [. G        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");) L" w, z. I; V+ G
    }4 w% E% S( I: T% J+ ^  ^
    / L7 X' {: e/ Z+ a4 b
    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
! x- R+ S; t3 W( e* u7 f2 D7 y; W    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);; k& \4 f" l8 V/ n
    4 I2 U' G4 o5 e) ?" _  V- W
    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");& `4 p4 ?  p$ l$ S; Q1 E
    . X6 h; R% i; r- \% u1 Z6 |
    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
9 Z" t4 ], F7 [. i$ B  I    4 s& p8 {8 \6 h6 [5 L
    NXOpen.Session.UndoMarkId markId2;
0 M% `8 h) ], f+ I2 z    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
( m2 O' ~1 c1 u5 t; K0 U   
, n) F0 O; H# U, @% _  J5 V& e1 i# u    NXOpen.Session.UndoMarkId markId3;  u7 Z) k" X" _4 J
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);) B1 [+ k1 p, ]% A$ B6 q$ w9 v
   
  h$ r* V3 a6 r7 g# @% Q; m, f    Curve[] curves1 = new Curve[fhsl];3 V& ?7 r, P+ G) V4 d9 b9 Q
    Line zx = null; ;
, a9 O; p- u- ?, s1 x  [7 b, J+ k    Arc yh = null;$ T# E+ w+ p3 q/ A0 m+ H
    int bj001 = 0;6 R' b0 N( S) j' P2 x! O+ A$ s
    for (int i = 0; i < fhsl;i++ )# H$ j# f) C" n1 c$ |
    {
2 \: s5 [' F& P        try
# w- {; I4 S7 m  @; T        {
: P9 y8 t: z# l  R+ {2 b( }* S! m            Arc body2 = null;
; o6 c3 O- {$ x, p: i            NXObject object0;6 F: E( n- S5 B
            // Tag body_id = NXOpen.Tag.Null;
" C5 K1 r' a6 L  y7 x, Y9 C, a            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
& w! i2 I1 w) r9 i. W            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
7 F% m" s. a- m) k- F. Z% K, u& K            body2 = (Arc)object0;
9 y( \# p% J4 c1 A0 v            curves1[i] = body2;
5 z# Q( U% I3 P% U9 _( Y! X            if (i==0)5 Q/ i0 a2 i4 f- ]) }
            {4 p+ y$ x9 U5 R, D, n4 y& k
                yh = body2;5 l& [7 F1 L! D3 d( ]( V/ t" c$ h( h
                bj001 = 1;+ s% S& ^7 q9 \) S) O
            }5 X) z5 G  l% L3 U! E1 w0 A
' V! w4 w1 ?' h% C
        }
5 x' ~: J5 G5 M5 i        caTCh (System.Exception ex)
7 \* D: t; F( q8 [' p8 t1 ^        {        9 ]. R2 h! t* a- p: g! m
        }( R/ w: y! G3 Y% h6 _
        try1 L7 I! A# t- Q# @1 W4 x2 X0 f
        {
# x" h( }( P' f8 }' v+ m( `% l            Line body2 = null;" }; X: [1 S# Q( ^
            NXObject object0;1 e2 o4 K/ d! p( W9 ~' Z
            // Tag body_id = NXOpen.Tag.Null;) t& r7 b$ J7 Q4 @
            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
+ G- M- W! [: L) E            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
8 `+ ]7 n8 A5 c1 ~; s) O- J            body2 = (Line)object0;* A4 v( x' H- @# h4 c: Y
            curves1[i] = body2;2 }1 D( v& b4 _
            if (i==0)
  Y% J, _# r% {  M1 V            {- q. _1 v  V/ ?
                zx = body2;
2 j# U5 s* ?* O8 O                bj001 = 2;" w- K0 B7 T, r/ C9 E2 f; x/ \' t& R
            }
- i" I9 I$ p/ G; Z# `  y8 t        }
/ i  |' ]) I2 `1 @; {        catch (System.Exception ex)3 t$ X* ^9 q' D- G: k5 S9 ~8 C3 g2 R3 k
        {
5 v3 h' g  j& g  A0 |# T" q3 G         5 |. Q5 U7 ]9 k+ q2 _4 }' O
        }! G4 l" K$ ~/ ^1 M1 b

: e. F8 P* e. x% e    }
/ C0 T( l0 x* f" |
% v' S9 r- V) {: I, ]* i- U//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");
0 }5 ~* z9 s; o2 v3 L//     curves1[0] = line1;/ f5 `* M3 N. K0 r+ `
//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");/ w& ]- c' @7 _3 z4 @0 @+ [% z9 z
//     curves1[1] = arc1;
# D- n0 k( q- ^+ @//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");
; {! W" c% `3 m. }4 P4 K$ a//     curves1[2] = arc2;
9 u$ d5 O+ M- r. ?6 o2 ^: q) H//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
: [+ ]8 y! Q" L9 p2 v5 [) O+ m+ \//     curves1[3] = line2;
: a* |) D7 x, t6 K7 M. p* L//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
. m0 F# i5 p+ z  Q- N$ l4 m! C//     curves1[4] = arc3;* \$ n; O6 U* j. @2 E# Z  B1 r
//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");" O5 c" q- `% Z' [( R7 D# W
//     curves1[5] = arc4;
9 n/ W0 w9 W1 A2 T0 s    CurveDumbRule curveDumbRule1;
: k8 Q, i; v' P5 X    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);) ~- j/ Y9 p% m. B, T9 e
   
9 q4 q2 \: q. Y3 n9 j6 z    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
, k* e! _! y4 Q# e' S1 h   
5 Q2 Z+ N$ W  z% e0 J, o/ ?8 k    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];2 L  h$ O4 `+ N# B! F+ b
    rules1[0] = curveDumbRule1;
' @% D2 v0 X# Q/ O) v    NXObject nullNXObject = null;6 z, K  h2 Y2 ?4 J  t; ]( @
    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);& Y% ]; T2 Y1 }, _
    if (bj001 == 1). ^' z( P  c" q# ^
    {+ T# @$ [  ^8 v' J7 r6 }& O
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
( Q1 m9 V& D! ?: f' H' u: j1 j  g    }8 c5 e& K  g& Z# G) m+ p+ |" u
    if (bj001 == 2)
$ f3 l# _0 r6 c1 j, |    {7 X* m! @, T" ?6 X
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
0 x$ O) v- D& x8 a& J2 J* w$ X  u    }
# A' f  F; L) b$ j3 ]! ~   
9 _7 b, S8 I$ B    theSession.DeleteUndoMark(markId3, null);
5 f" G) c8 h6 g2 P2 L  f' D   
  H1 b  D4 J; y6 v8 Q6 K% s    theSession.DeleteUndoMark(markId2, null);% i1 V, Y7 F; s1 E$ e
   
% z( y  \7 p3 g  J' ?    NXOpen.Session.UndoMarkId markId4;; t! w! l  A5 b9 O( w. S- b, {
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");
4 V8 k% r. q# D  y0 x    9 ~6 L$ x; A7 t1 c" ?
    NXObject nXObject1;
: d9 M5 X! E# ^    nXObject1 = boundedPlaneBuilder1.Commit();
5 g% R. Z; H: H2 @8 Z+ A2 A   
2 |. C1 Y5 v0 m( k   
7 b, I9 b& v0 e0 E    DisplayModification displayModification1;
, D2 t: ?- u. u# G5 t: t; Z! h1 p    displayModification1 = theSession.DisplayManager.NewDisplayModification();
0 A+ W! x' ~" s  m* I    - c9 Q# G3 H- N( J" d4 U
    displayModification1.ApplyToAllFaces = false;
" Q8 Y4 m- s5 Z3 f% h    ) F% v9 O) p% G) ~
    displayModification1.SetNewGrid(0, 0);
6 p% y  L& C7 D' S- ?! O   
3 a* |, m% w( G9 T/ A    displayModification1.PoleDisplayState = false;2 b8 W1 p' y! r7 w+ r' y! q0 |' n
    % I0 @+ C' H+ M% P$ E# q
    displayModification1.KnotDisplayState = false;0 `8 z; e& h! x" O8 P! P
    6 u" m0 ^% C! n: P1 j  A
    DisplayableObject[] objects1 = new DisplayableObject[1];
/ e: P9 ^0 G0 @, p8 |" ]    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;: `2 O2 f) f! y& D
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
" C+ t! @: J9 u- I) I/ I   
. \1 f/ G# c/ D7 m1 a        objects1[0] = face1;
/ o: n: [# Z1 G3 w: T8 q4 X    displayModification1.Apply(objects1);
& f3 D  f, d0 q3 n    face1.Color = 32767;
8 z! E+ V9 q# r    # b4 W4 K; S5 T6 g$ K
    theSession.DeleteUndoMark(markId4, null);
6 S  _9 m( S  P; d( U      p6 L6 w4 a! H! _- `, H( I" [
    theSession.SetUndoMarkName(markId1, "Bounded Plane");2 H; Z, H1 A) R& v! x
   
1 B+ A) k" I9 w4 N; g    boundedPlaneBuilder1.Destroy();, U, X, a7 O2 n& U; V8 [
   
' C3 m, E3 `: p4 O       /* if(fhyi==1){# G, I0 h+ B- Y; b! H5 ~
    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}
, W$ x2 p8 M, z% }, Y    if(fhyi==2){+ G: h! u% L( y- A! E/ B
    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}$ d/ z! b* @3 A% k3 I
        */, h; T$ D" v6 n" E( f" }
    // ----------------------------------------------
% ~+ C/ t) `" @1 A; ?    //   菜单:刀具->操作记录->Stop Recording
# u% |/ F1 V6 w3 q9 k    // ----------------------------------------------
# d9 c3 K3 i8 K* ^8 B& b   
& T5 D: J% R1 H& T  }3 E4 v$ z) W: M. l/ X
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
1 D+ L0 @+ t2 c/ d}% N" i/ E- ~0 A' Y6 I5 l
这是录制有界平面点选封闭曲线产生的日志
0 S! \9 o$ T/ J* k7 A我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了 4 g5 S4 ]4 A2 \
NXObject nXObject1;
  t8 H; f2 {3 z8 W) V    nXObject1 = boundedPlaneBuilder1.Commit();" L- u- a1 R6 M. D: E
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值
7 I3 P' H* E+ @/ a' t! N& e6 T6 w1 O+ B' ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了