Hi
below C# code will create a body measurement in a part file. It will create a single measurement for all the bodies in the part file.
It will exclude sheet bodies and use solids only. Please let me know if this solve your purpose or not. incase if u run any issue you can compile and create a dll. file attached.
====================================================================================================================
using System;
using System.Collections.Generic;
using NXOpen;
using NXOpenUI;
namespace Mass_Solid
{
public class Weight_link
{
public static void Main(string[] args)
{
Session theSession = Session.GetSession();
UI theUi = UI.GetUI();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
ListingWindow lw = theSession.ListingWindow;
BodyCollection ball = workPart.Bodies; //Collect all bodied in the part
List<Body> slds = new List<Body>(); //Solid bodies list
//Checking the body is soldi or not
lw.Open();
foreach (Body b in ball)
{
if (b.IsSolidBody == true)
{
//lw.WriteFullline(b.Tag.ToString());
slds.Add(b);
}
}
if (slds.Count > 0)
{
int ctr = slds.Count;
NXObject nu = null;
MeasureBodyBuilder mb = workPart.MeasureManager.CreateMeasureBodyBuilder(nu);
BodyDumbRule bdr = workPart.ScRuleFactory.CreateRuleBodyDumb(slds.ToArray());
SelectionIntentRule[] scr = new SelectionIntentRule[1];
scr[0] = bdr;
mb.BodyCollector.ReplaceRules(scr, false);
Unit[] massUnits1 = new Unit[5];
Unit unit1 = (Unit)workPart.UnitCollection.FindObject("SquareInch");
massUnits1[0] = unit1;
Unit unit2 = (Unit)workPart.UnitCollection.FindObject("CubicInch");
massUnits1[1] = unit2;
Unit unit3 = (Unit)workPart.UnitCollection.FindObject("PoundMass");
massUnits1[2] = unit3;
Unit unit4 = (Unit)workPart.UnitCollection.FindObject("Inch");
massUnits1[3] = unit4;
Unit unit5 = (Unit)workPart.UnitCollection.FindObject("PoundForce");
massUnits1[4] = unit5;
MeasureBodies mbd = workPart.MeasureManager.NewMassProperties(massUnits1, .99, mb.BodyCollector);
Measure measure1;
measure1 = mbd.CreateFeature();
mbd.Dispose();
mb.Destroy();
}
else
{
theUi.NXMessageBox.Show("Message", NXMessageBox.DialogType.Information, "This part is not having Solid bodies");
}
}
public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
}
}