I want to check what is the body type of the body I'm working with in a BodyCollection
(If the body is Sphere
).
How do I write that?
This is what I tried:
public void ChamferAll()
{
int subtype = 1;
string offset1 = "5", offset2 = "0", angle = "5";
BodyCollection bodyCollection = theSession.Parts.Work.Bodies;
List<Tag> edgeTags = new List<Tag>();
foreach (Body body in bodyCollection)
{
if (body.GetType() == NXOpen.Features.Sphere)
continue;
else
{
Edge[] edges = body.GetEdges();
foreach (Edge edge in edges)
{
edgeTags.Add(edge.Tag);
theUFSession.Modl.CreateChamfer(subtype, offset1, offset2, angle, edgeTags.ToArray(), out Tag chamferTag);
}
edgeTags.Clear();
}
}
}
body.GetType()
returns the type of the body, e.g., sheet or solid. "Sphere" is not a body type.What you can do instead is use
body.GetFeatures()
to get a list of the features associated with that body. Then select the first returned feature, and try casting it toNXOpen.Features.Sphere
. If that works, the body you've got is a sphere. If the cast doesn't work, you have something other than a sphere.