static Body FindBodyByFeatureName(Part part, string featureName) //遍历所有特征,通过名字获取BODY
{
// 获取部件中的所有特征
NXOpen.Features.Feature[] features = part.Features.ToArray();
foreach (NXOpen.Features.Feature feature in features)
{
// 检查特征的名称
if (feature.GetFeatureName() == featureName)
{
// 从特征中获取与之相关的主体
// 注意:并非所有特征都有主体,您可能需要根据特征类型进行判断
if (feature is NXOpen.Features.BodyFeature bodyFeature)
{
return bodyFeature.GetBodies()[0]; // 返回第一个相关的主体
}
}
}
return null; // 如果未找到,返回 null
}
public static int Main(string[] args)
{
int retValue = 0;
try
{
theProgram = new Program();
//TODO: Add your application code here
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
string message = "请选择一个或多个面";
string title = "1面选择";
TaggedObject[] selectedObjects = null;
Selection.SelectionScope scope = Selection.SelectionScope.WorkPart; //先取的范围
NXOpen.Selection.SelectionAction action = Selection.SelectionAction.ClearAndEnableSpecific;
bool includeFeatures = false; //是否允许选择特性
bool ke