PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

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

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

smalfly11 楼主

2014-2-12 23:34:54

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

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

x
using System;& A% U0 a3 K' `3 \; B' \6 ^. T. }
using NXOpen;- O# h& c' R- U0 c
using System.Collections;4 A4 J) u/ l4 P/ i5 M3 q" E
using System.Management;* D0 R1 T& ^4 B( Q1 n9 l8 b
using System.Management.Instrumentation;& I5 _0 }' ?4 D: _' A$ R7 R
using System.Text.RegularExpressions;! G* A7 n% h) f  @: V/ x3 d( I
using System.IO;
5 ~2 R  e3 p" ?! O: n1 Husing System.Collections.Generic;" ?  U7 _+ k  b4 ^
using System.ComponentModel;
* l# V* f! X  S; k! cusing System.Data;3 O# |  ?' U' `0 n0 \8 t  B
using System.Drawing;7 M( @" x2 S2 ^: |) a+ f2 \
using System.Linq;
9 H% \& G7 Y) M/ w/ ~" @using System.Text;! v5 a% O2 k/ v- n. z0 w% u
using System.Windows.Forms;- J/ q, P1 _" o; c- x5 ?  A. \
public class NXJournal5558 I  \$ x* o! n- k0 z* G$ `
{
$ C/ v: ?9 @4 f$ ?1 R* G6 P1 u    public static void Main555(Tag[] bj, int fhsl)6 @% I( p* F+ j* Z4 f3 ^) l
    {+ U3 p" |6 b6 F
        
0 C* U5 [0 `/ k6 A* r" O    Session theSession = Session.GetSession();1 g2 Q/ F" P8 Z% F5 D6 U
    Part workPart = theSession.Parts.Work;+ J! A) H+ M, ]: k0 \$ j, H
    Part displayPart = theSession.Parts.Display;0 J( c; D3 Z/ X4 S3 j
    // ----------------------------------------------1 h" \- V; S& X/ D9 O' a" H
    //   菜单:镶块->曲面->Bounded Plane...2 A, j0 U: t  |: E
    // ----------------------------------------------; I/ q6 g6 ~) u' A& T
    NXOpen.Session.UndoMarkId markId1;
8 m6 \( U" l& o. ]+ a! O    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");' R. g. L$ N7 k% C' m
   
$ {" e, o  Y" y( {) I/ x    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;
: P8 q; h" a; B8 I   
6 |: y4 _; w! b% e. h    if ( !workPart.Preferences.Modeling.GetHistoryMode() )& s! B! Z# O, x: }0 ^
    {
9 t# c2 d" ^# |9 P        throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");! c6 M& }# S3 u6 P$ J) ]
    }% F- n6 y3 r" X. q/ m
    0 j- D* j5 H% K+ k* M  s$ [) u( d
    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
# Z$ X! O2 ~- G% y' _, `# p- y    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);9 v# K0 A; N% Y+ L7 f0 D9 q! E! H
    , G1 F2 ~2 J; U4 D6 V% K. g$ q
    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");, P1 L9 ]3 w! X/ R" A
   
0 R/ R& m5 _% f" A2 X  o    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
. \) n! H' `( c$ Q; Q7 d   
0 P5 T! \1 {0 K: g. {, d$ h    NXOpen.Session.UndoMarkId markId2;6 j2 Y5 q/ Y7 J6 L
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");# E, E+ \  |; S! M% `% }
    # E) A3 q$ ?1 G$ S
    NXOpen.Session.UndoMarkId markId3;/ A+ s) T6 i- A0 c9 [2 N
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
6 S2 j$ {3 [% C! e0 _8 H9 V& u   
* G+ {: O- i3 ]" z    Curve[] curves1 = new Curve[fhsl];- R$ |/ V/ P' k* [3 X" y
    Line zx = null; ;' I8 C- i( f  {) S3 R
    Arc yh = null;
9 K5 M) L6 H3 v0 G- D' @    int bj001 = 0;
0 s9 C: K. W' r/ {4 K3 m    for (int i = 0; i < fhsl;i++ )
: A$ t, j% s3 a8 O2 N; D    {
$ Y! Q% N' p& n* j        try
! H% T: I. M9 p0 C        {3 S) m0 D; q$ ^
            Arc body2 = null;# d2 {" c' X4 M: w4 ^# \
            NXObject object0;! Z( R% N, W1 v; n
            // Tag body_id = NXOpen.Tag.Null;
0 h2 }* z8 t2 Q, H/ L0 `            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.
9 g/ O& c- T+ T( N# k3 B            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。1 D+ G' v4 l, v" u3 p; a" p# N4 y4 r
            body2 = (Arc)object0;
2 G) c: a; ]7 g            curves1[i] = body2;8 e6 c, r$ I7 R9 a4 d/ h
            if (i==0)
! Q/ @& K4 h6 _: j  q  }            {* d5 W$ a+ \& G& {$ i
                yh = body2;' \6 Q8 a+ z+ L
                bj001 = 1;9 Q9 W1 E: R4 r/ I
            }
0 m0 d$ r: h! Z/ O' K) M/ X' b& s. d- e
        }, `: [' I( _& _! g5 Z% |
        caTCh (System.Exception ex)' O$ V0 L! s! I- }2 o
        {        . @( r/ s! T3 _/ H. U8 w- Q
        }; l, N6 Z1 E# S% {) y' I1 m  d
        try4 }8 {& X* c. h2 m
        {8 Q& ?' L. W& j; f. Y9 N0 S1 Q- r
            Line body2 = null;
* Z- E8 F. d( C+ v$ y3 w7 v            NXObject object0;6 t) M: X/ a$ q
            // Tag body_id = NXOpen.Tag.Null;
7 ^1 l. B4 M! h* f            //theUFSession.Modl.AskFeatBody(bj[0], out body_id);//把特征的tag放入到body的tag.4 \: P$ h/ y: ~
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj[i]); //把tag转为body。
( M$ l! G+ a: g0 e! f, x( F            body2 = (Line)object0;
3 i* n, a! j4 |  z. Q, _7 e            curves1[i] = body2;
5 f, U+ A' p( ~2 t3 ?, e6 J            if (i==0)- {. l7 {3 L4 y. |' U
            {$ ~. n8 z4 }5 M8 X+ y
                zx = body2;8 H# V$ _/ N# c
                bj001 = 2;" c! _5 e, V5 h& n0 y& u6 a
            }
: d9 ~( R5 R" ]8 e        }
! o7 i$ S; q3 I! e( {        catch (System.Exception ex)3 N5 i1 O. X5 p
        {
, H1 x. k' y$ T& V! ]         4 p4 B# k$ O* Z9 ?  @8 d
        }
1 t+ A- f! S- }- i' c2 N4 N/ |
& v# e+ K$ ~( X: X( F2 A    }
  V# R- h' }& {9 t+ g& ^8 d& K) p: ]' y/ {0 j
//     Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");& ]. E' ?& Q7 i* n. C% ]
//     curves1[0] = line1;# ~4 c! d, ^0 S( A" ~+ e
//     Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");/ f7 b6 `$ X: N1 N3 I$ m9 i! y4 a
//     curves1[1] = arc1;
, y, `3 I: N/ G. j3 K//     Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");7 [0 S9 X$ }" _& e- Z
//     curves1[2] = arc2;: A* I! M+ u( K% D* R) S
//     Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
, Q0 v' O! o! s$ f. a//     curves1[3] = line2;
# `$ A8 }0 v. O" }+ c, L//     Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");8 J' I+ V/ {$ t9 ~" \
//     curves1[4] = arc3;
. q$ @' A% _( v7 P  d# `//     Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");. K$ m2 L- v" \" n2 l
//     curves1[5] = arc4;
; E# u& u/ [4 J    CurveDumbRule curveDumbRule1;1 C" z3 u' ~$ q( A( J
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
1 b3 k% o5 }9 T1 F- a$ b3 F% l7 p   
9 [! g8 h. V& h* T    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
' W6 I' p% K, H$ J( s   
" ~. K! @/ V2 f! _) H    SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
) P5 _: Z  L1 c' c2 Q# \    rules1[0] = curveDumbRule1;$ R: V. x, Z+ N0 c& l) X0 }8 h7 ^! O
    NXObject nullNXObject = null;
6 }; l# j0 C- q- l% c4 n5 p5 D    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);# k& B0 }. y) V- c7 ~
    if (bj001 == 1)
+ ^1 ^. Z  F$ V& _    {$ j& l  S* j5 U% h) A
        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
7 `9 E$ \  ^9 A; s; O+ E    }
$ }. q, K' |2 a    if (bj001 == 2)3 M1 c# B2 w; d3 R/ R
    {
& `; j# x9 c8 m5 u( H) h5 x" J        boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
( a$ z+ y& R5 {/ m: N  `- O    }  z$ }: k" F+ y1 j; d0 r  |! `
   
( ]' g% t; ~7 V; D0 s7 `    theSession.DeleteUndoMark(markId3, null);
& d! i: s/ a- E; S   
5 S# c& ?* T- W! o" K# f    theSession.DeleteUndoMark(markId2, null);+ r/ ~8 C# C) N; M$ `3 P4 {* }
   
( P/ s; t/ W9 B/ f4 q: x$ m+ w( T    NXOpen.Session.UndoMarkId markId4;
- Z6 c# z$ p1 ~" H6 F    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");
, }7 W! d2 z) y# D* G9 S8 w    : J" i6 e" _* m! N. c6 r" \
    NXObject nXObject1;& ^2 A3 q! @  x$ z
    nXObject1 = boundedPlaneBuilder1.Commit();' H; t- E7 B+ Y) M
   
: Y, V9 h- Q- T* |- k7 k. _    7 x; O) I9 a8 Q2 X9 K( t
    DisplayModification displayModification1;
  P4 B4 E8 S; ?    displayModification1 = theSession.DisplayManager.NewDisplayModification();
2 [  y' `* Z8 \  Q+ [8 }- o    ( I# @% I; |% U4 ?
    displayModification1.ApplyToAllFaces = false;* N8 i2 {8 q6 i! D  `, K+ D
    : g: n# |0 g$ l
    displayModification1.SetNewGrid(0, 0);  O& o7 Y9 O1 s* y" m8 j( F
   
& |8 W( c0 x, `2 M% W6 M    displayModification1.PoleDisplayState = false;) W3 R" v0 h1 b
    / n7 y: p; N; B3 ^* n9 h
    displayModification1.KnotDisplayState = false;
! _4 m0 ^4 J7 w   
, U/ L7 J' J# s- A! h" M; o, k6 L# Q    DisplayableObject[] objects1 = new DisplayableObject[1];
% o8 c7 p; ]0 A7 d% p    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;
) f  r: E1 h- o    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
( R. A& g! e* W# O. M2 B    1 N8 u! c3 m4 G8 J$ u2 Z
        objects1[0] = face1;
; G: V# ]  u1 `    displayModification1.Apply(objects1);! }7 q9 q3 n9 f
    face1.Color = 32767;, D1 A7 U. u/ n. s/ Q) a
    " V) \8 L* k# Y( Q+ A! b* e
    theSession.DeleteUndoMark(markId4, null);$ B+ q7 w3 e. t# j: K; v
   
, y. f/ t" |7 F' h* R    theSession.SetUndoMarkName(markId1, "Bounded Plane");
: K3 e5 p  q* M2 _8 g- W- b   
5 m: h: z6 h- N, q. g8 l    boundedPlaneBuilder1.Destroy();( ]' y8 k" E+ T; o+ f9 \
    ' ^4 v. c2 h$ C6 Z0 I
       /* if(fhyi==1){
( p; c  y- L! _# t& X" v  l0 P    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}
0 ~( M! `( `! ^: ]    if(fhyi==2){8 S, _2 z7 L# p( c& ^3 O% m
    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}
7 l5 y; @4 \, Z; e        */- N2 r% _  {4 t, ]2 H1 L' ]- q
    // ----------------------------------------------
* L+ U  T  g' A  h    //   菜单:刀具->操作记录->Stop Recording. [& ^3 w' c) h: r# f
    // ----------------------------------------------
. }% n( r7 W7 y% U2 a6 Z   
, `' E% X5 @# h4 t" B  }& m1 o# U9 a( t" Q; v
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
( O2 M; r2 C2 G}
4 [! K) Z2 a) Q" z# n这是录制有界平面点选封闭曲线产生的日志
& z' [1 v8 D; M% e; ~2 N我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1[i] 数组 结果画出平面了
& Y6 N$ i' z0 R4 ?; S NXObject nXObject1;4 }# ?5 ?/ X3 u4 u. u/ I+ a- h
    nXObject1 = boundedPlaneBuilder1.Commit();
0 g6 r$ n  L# u! J' |) q但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值  用于以后缝合用 该怎么改才能让这个函数返回值- ^5 r# F$ L4 [: x" k& w

$ K4 i' c; o/ k* ?& f* i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了