Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Obtaining occurance geometry of Assembly Component

I have added another instance of a component to my assembly which returns to me a Component object. How can I get geometry from the instance of this component. I do not want geometry of the prototype.

 

All I've found in documentation that addresses this has been from the Snap API which provides a function to obtain ALL objects (including occurances) which I can then compare their owning component to the one I was returned. This approach takes almost a full minute to process on my test fixture.

 

I have something like this...

 

NXOpen.Assemblies.Component toolingBall = ImportComponentToWCS("CL-2-SCB", "B");
foreach (NXObject obj in Snap.Globals.WorkPart.Objects)
{
  if (obj.IsOccurace)
{ if (obj.OwningComponent == toolingBall && obj.GetType() == typeof(Body)) { Body body = (Body)obj; body.Highlight(); }
}
}

 

 

Does anyone have something using the NXOpen.Assemblies namespace or even NXOpen.UF.UFAssem that can accomplish this in a more efficient manner? Any suggestions at all would be appreciated.

 
2 REPLIES
Solution
Solution
Accepted by topic author samwiseh
‎09-06-2016 12:31 PM

Re: Obtaining occurance geometry of Assembly Component

[ Edited ]

If you have a reference to the prototype geometry and the component, you can use the component's .FindOccurrence method to access the occurrence geometry in the assembly context. This will find the occurrence geometry directly without needing to cycle through other objects.

 

Edit: I should note that .FindOccurrence may not work well with deformed components or promoted bodies.

Re: Obtaining occurance geometry of Assembly Component

Thank you for the quick response. This was exactly what I was looking for. To help clarify this for anyone else who might run into this, I've fixed it in the code below using the .FindOccurance method.

 

// Get the prototype of the component
Part prototype = (Part)componentObj.Prototype;

// For each body in the prototype, find its occurrence in the component object and add it to the list List<Body> occuranceBodies = new List<Body>(); foreach(Body protoBody in prototype.Bodies) { occuranceBodies.Add((Body)componentObj.FindOccurrence(protoBody)); } // Highlight all the occurance bodies in the component foreach(Body body in occuranceBodies) { body.Highlight(); }