Showing results for 
Search instead for 
Do you mean 
Reply

Getting a NXOpen.Body out of a splitbody operation

Hi there, I have another question.

 

Currently Ive programmed a tool which splits a body in half. Now I need that body which was generated to be selected to use it in another method in a class but I cannot find a way to select the created body.

 

I will attach my code:

 

using System;
using NXOpen;
using NXOpen.UF;

    class koerper_trennen
    {
        public void koerper_teilen(Body[] koerper_3, DatumPlane[] ebene4_3)
        {
            NXOpen.Session theSession = NXOpen.Session.GetSession();
            NXOpen.Part workPart = theSession.Parts.Work;
            NXOpen.Part displayPart = theSession.Parts.Display;
            // ----------------------------------------------
            //  Menü: Einfügen->Trimmen->Körper teilen...
            // ----------------------------------------------
            NXOpen.Session.UndoMarkId markId1;
            markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
    
            NXOpen.Features.SplitBody nullNXOpen_Features_SplitBody = 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.SplitBodyBuilder splitBodyBuilder1;
            splitBodyBuilder1 = workPart.Features.CreateSplitBodyBuilderUsingCollector(nullNXOpen_Features_SplitBody);
    
            NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            NXOpen.Vector3d normal1 = new NXOpen.Vector3d(0.0, 0.0, 1.0);
            NXOpen.Plane plane1;
            plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling);
    
            splitBodyBuilder1.BooleanTool.FacePlaneTool.ToolPlane = plane1;
    
            NXOpen.Unit unit1 = (NXOpen.Unit)workPart.UnitCollection.FindObject("MilliMeter");
            NXOpen.Expression expression1;
            expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);
    
            NXOpen.Expression expression2;
            expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);
    
            splitBodyBuilder1.BooleanTool.ExtrudeRevolveTool.ToolSection.PrepareMappingData();
    
            theSession.SetUndoMarkName(markId1, "Körper teilen-Dialogfenster");
    
            splitBodyBuilder1.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = 0.01;
    
            splitBodyBuilder1.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = 0.0095;
    
            NXOpen.ScCollector scCollector1;
            scCollector1 = workPart.ScCollectors.CreateCollector();
    
            //Uebermittlung des ausgewaehlten Bodys
            NXOpen.Body[] bodies1 = new NXOpen.Body[1];
            bodies1[0] = koerper_3[0];
            NXOpen.BodyDumbRule bodyDumbRule1;
            bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true);
    
            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
            rules1[0] = bodyDumbRule1;
            scCollector1.ReplaceRules(rules1, false);
    
            splitBodyBuilder1.TargetBodyCollector = scCollector1;
    
            //Uebermittlung der angegebenen Ebene
            NXOpen.DatumPlane[] faces1 = new NXOpen.DatumPlane[1];
            faces1[0] = ebene4_3[0];
            NXOpen.FaceDumbRule faceDumbRule1;
            faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDatum(faces1);
    
            NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1];
            rules2[0] = faceDumbRule1;
            splitBodyBuilder1.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(rules2, false);
   
            NXOpen.NXObject nXObject1;
            nXObject1 = splitBodyBuilder1.Commit();

            NXOpen.Body splitbody;
            splitbody = splitBodyBuilder1.TargetBody;

            //Schwerpunkt ermitteln
            schwerpunkt_ermitteln sp_erm = new schwerpunkt_ermitteln();
            sp_erm.sp_ermitteln(koerper_3);
    
            splitBodyBuilder1.BooleanTool.ExtrudeRevolveTool.ToolSection.CleanMappingData();
    
            splitBodyBuilder1.Destroy();

            try
            {
                // Ausdruck wird immer noch verwendet.
                workPart.Expressions.Delete(expression2);
            }
            catch (NXException ex)
            {
                ex.AssertErrorCode(1050029);
            }
    
            try
            {
                // Ausdruck wird immer noch verwendet.
                workPart.Expressions.Delete(expression1);
            }
            catch (NXException ex)
            {
                ex.AssertErrorCode(1050029);
            }
 
            plane1.DestroyPlane();
    
            // ----------------------------------------------
            //  Menü: Werkzeuge->Journal->Stopp
            // ----------------------------------------------
    
        }

        public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
        
    }

The code:

NXOpen.Body splitbody;
splitbody = splitBodyBuilder1.TargetBody; 

 doesnt work but I hope you get the idea of what Iam trying to do.

 

Afterwards the body should be used in:

 

schwerpunkt_ermitteln sp_erm = new schwerpunkt_ermitteln();
sp_erm.sp_ermitteln(koerper_3);

Where koerper_3 will be the selected body which was created due to the splitbody operation.

 

Maybe anyone could help me right here? I cannot find a solution for this one.

4 REPLIES

Re: Getting a NXOpen.Body out of a splitbody operation

I've not tested this, but I think it will work. The SplitBody feature has a .GetBodies property that will return the bodies created by the feature. I assume this will return two body objects: one with the same tag as the original input body and the newly created body with a new tag value. Now you need to be able to tell which one is new and which is the original. The split body builder object has a .TargetBody property that gives you the body that was input to be split. Comparing the results of the two properties will allow you to differentiate between the original and newly created body.

Re: Getting a NXOpen.Body out of a splitbody operation

Hello,

 

In C++ you can get it in this way.

 

Features::BodyFeature *newSolids= (Features::BodyFeature *) splitduilder1->GetFeature();
std::vector< NXOpen::Body *> bodies= newSolids->GetBodies();

 

Regards.

 

Miguel Reboreda

Tromosa

SPAIN

Re: Getting a NXOpen.Body out of a splitbody operation

First of all: Thank you very much! Ive managed to get the first object:

 

//Auslesen der Bodies
TaggedObject[] Bodysammler = splitBodyBuilder1.TargetBodyCollector.GetObjects();
NXOpen.Body[] ursprungskoerper = new NXOpen.Body[Bodysammler.Length];
ursprungskoerper[0] = (NXOpen.Body)(Bodysammler[0]);

This is the original Body.

 

Now Iam at the Body which was created through the splitbody feature. So here Iam:

 

NXOpen.NXObject Bodysammler2 = splitBodyBuilder1.GetObject();

I think that this is the object. But how can I convert it into a Body to use it for measuring?

 

Thanks in advance!

Re: Getting a NXOpen.Body out of a splitbody operation

In general you would not need to convert it, if you don't use the methods explicitly available for bodies.

Measuring can be done with NXObjects too.

 

In VB.NET I would use CType() to cast the NXObject to a Body, I don't know the correct syntax for C#.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community