smalfly11 发表于 2014-2-12 23:34:54

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

using System;
using NXOpen;
using System.Collections;
using System.Management;
using System.Management.Instrumentation;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class NXJournal555
{
    public static void Main555(Tag[] bj, int fhsl)
    {
      
    Session theSession = Session.GetSession();
    Part workPart = theSession.Parts.Work;
    Part displayPart = theSession.Parts.Display;
    // ----------------------------------------------
    //   菜单:镶块->曲面->Bounded Plane...
    // ----------------------------------------------
    NXOpen.Session.UndoMarkId markId1;
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
   
    NXOpen.Features.BoundedPlane nullFeatures_BoundedPlane = null;
   
    if ( !workPart.Preferences.Modeling.GetHistoryMode() )
    {
      throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
    }
   
    NXOpen.Features.BoundedPlaneBuilder boundedPlaneBuilder1;
    boundedPlaneBuilder1 = workPart.Features.CreateBoundedPlaneBuilder(nullFeatures_BoundedPlane);
   
    theSession.SetUndoMarkName(markId1, "Bounded Plane 对话框");
   
    boundedPlaneBuilder1.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
   
    NXOpen.Session.UndoMarkId markId2;
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
   
    NXOpen.Session.UndoMarkId markId3;
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
   
    Curve[] curves1 = new Curve;
    Line zx = null; ;
    Arc yh = null;
    int bj001 = 0;
    for (int i = 0; i < fhsl;i++ )
    {
      try
      {
            Arc body2 = null;
            NXObject object0;
            // Tag body_id = NXOpen.Tag.Null;
            //theUFSession.Modl.AskFeatBody(bj, out body_id);//把特征的tag放入到body的tag.
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj); //把tag转为body。
            body2 = (Arc)object0;
            curves1 = body2;
            if (i==0)
            {
                yh = body2;
                bj001 = 1;
            }

      }
      catch (System.Exception ex)
      {      
      }
      try
      {
            Line body2 = null;
            NXObject object0;
            // Tag body_id = NXOpen.Tag.Null;
            //theUFSession.Modl.AskFeatBody(bj, out body_id);//把特征的tag放入到body的tag.
            object0 = (NXObject)NXOpen.Utilities.NXObjectManager.Get(bj); //把tag转为body。
            body2 = (Line)object0;
            curves1 = body2;
            if (i==0)
            {
                zx = body2;
                bj001 = 2;
            }
      }
      catch (System.Exception ex)
      {
         
      }

    }

//   Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-7608");
//   curves1 = line1;
//   Arc arc1 = (Arc)workPart.Arcs.FindObject("HANDLE R-7621");
//   curves1 = arc1;
//   Arc arc2 = (Arc)workPart.Arcs.FindObject("HANDLE R-7614");
//   curves1 = arc2;
//   Line line2 = (Line)workPart.Lines.FindObject("HANDLE R-7611");
//   curves1 = line2;
//   Arc arc3 = (Arc)workPart.Arcs.FindObject("HANDLE R-7618");
//   curves1 = arc3;
//   Arc arc4 = (Arc)workPart.Arcs.FindObject("HANDLE R-7604");
//   curves1 = arc4;
    CurveDumbRule curveDumbRule1;
    curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1);
   
    boundedPlaneBuilder1.BoundingCurves.AllowSelfIntersection(true);
   
    SelectionIntentRule[] rules1 = new SelectionIntentRule;
    rules1 = curveDumbRule1;
    NXObject nullNXObject = null;
    Point3d helpPoint1 = new Point3d(0.0, 0.0, 0.0);
    if (bj001 == 1)
    {
      boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, yh, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
    }
    if (bj001 == 2)
    {
      boundedPlaneBuilder1.BoundingCurves.AddToSection(rules1, zx, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
    }
   
    theSession.DeleteUndoMark(markId3, null);
   
    theSession.DeleteUndoMark(markId2, null);
   
    NXOpen.Session.UndoMarkId markId4;
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Bounded Plane");
   
    NXObject nXObject1;
    nXObject1 = boundedPlaneBuilder1.Commit();
   
   
    DisplayModification displayModification1;
    displayModification1 = theSession.DisplayManager.NewDisplayModification();
   
    displayModification1.ApplyToAllFaces = false;
   
    displayModification1.SetNewGrid(0, 0);
   
    displayModification1.PoleDisplayState = false;
   
    displayModification1.KnotDisplayState = false;
   
    DisplayableObject[] objects1 = new DisplayableObject;
    NXOpen.Features.BoundedPlane boundedPlane1 = (NXOpen.Features.BoundedPlane)nXObject1;
    Face face1 = (Face)boundedPlane1.FindObject("FACE 10001 {(0,0,0) BOUNDED_PLANE(20)}");
   
      objects1 = face1;
    displayModification1.Apply(objects1);
    face1.Color = 32767;
   
    theSession.DeleteUndoMark(markId4, null);
   
    theSession.SetUndoMarkName(markId1, "Bounded Plane");
   
    boundedPlaneBuilder1.Destroy();
   
       /* if(fhyi==1){
    NX8_Open_CS_Wizard1.CodeString.yfht1 = face33;}
    if(fhyi==2){
    NX8_Open_CS_Wizard1.CodeString.yfht2 = face33;}
      */
    // ----------------------------------------------
    //   菜单:刀具->操作记录->Stop Recording
    // ----------------------------------------------
   
}
public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
}
这是录制有界平面点选封闭曲线产生的日志
我用自己算的的TAG[]转换成NXObject再转Body存入了它自己创建的curves1 数组 结果画出平面了
NXObject nXObject1;
    nXObject1 = boundedPlaneBuilder1.Commit();
但在这段下面加上 Body face33;face33=(Body)nXObject1 时就出错 生成的文件不会往下走 我本意是想让它返回一个记录生成平面的Body值用于以后缝合用 该怎么改才能让这个函数返回值

nxopen 发表于 2017-9-15 10:49:42

我也遇到同样的问题:NXObject转Body出错
页: [1]
查看完整版本: UG录的日志文件有界平面怎么返回Body