Showing results for 
Search instead for 
Did you mean: 

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.


Re: Obtaining occurance geometry of Assembly Component

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

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(); }

Re: Obtaining occurance geometry of Assembly Component


This thread from a year ago just seriously helped me with almost the same task.  Here is a snippet of the code I used to finally get this working in Python:

self.allSolidBodies = self.theWorkPart.Bodies
self.assemRootComponent = self.theWorkPart.ComponentAssembly\
if self.assemRootComponent:
    self.allComponentsPresent = self.assemRootComponent\
solidsAndComponentsToFit = []
for eachBody in self.allSolidBodies:
if self.assemRootComponent:
    for eachComponent in self.allComponentsPresent:
        if (not eachComponent.IsSuppressed) and (not eachComponent.IsBlanked):
            if eachComponent.IsOccurrence:
                prototypeOfObject = eachComponent.Prototype
                bodiesOfPrototype = prototypeOfObject.Bodies
                for body in bodiesOfPrototype:
                    bodyOcc = eachComponent.FindOccurrence(body)

Please feel free to tell me I did this the hard way, I'd love to know if there is a shortcut function already available!


Re: Obtaining occurance geometry of Assembly Component

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Having taken a quick look at your code, it looks like you are trying to get all the occurrence bodies in the assembly. The easy way to do that is to use the .CycleObjsInPart method, looking for body objects in the assembly part. The .CycleObjsInPart will return occurrence bodies where the .Bodies collection will not. You can find some VB code in this link; it is fairly short and straightforward and shouldn't be too difficult to translate to Python.


One of the pitfalls of your current strategy is that the prototype bodies in the component part file are not required to show up in the assembly as an occurrence body. Depending on the reference set in use, some (or all) of the prototype bodies may not have a corresponding occurrence body in the assembly.