Assembly Pattern's Children Components

Hi,

I’m trying to get the assembly pattern’s children components but unsuccessfully.

The code snippet below gets the children successfully (generic method):

private void GetChildren()
{
  Feature selectedObject = (Feature)swModel.ISelectionManager.GetSelectedObject5(1);
  
  object[] components = (object[])selectedObject.GetChildren(); 
}

Here is the complemented code that’s got error on conversion:

private void GetChildren()
{
  Feature selectedObject = (Feature)swModel.ISelectionManager.GetSelectedObject5(1);
  
  object[] components = (object[])selectedObject.GetChildren(); 

  foreach (object item in components)
  {
    Component2 component = (Component2)item; // conversion error
  }
}

The specific assembly’s pattern interfaces do not support any method for getting the children components. Here’s a snippet to gain access to a linear pattern assembly feature:

Feature selectedObject = (Feature)swModel.ISelectionManager.GetSelectedObject5(1);

LocalLinearPatternFeatureData pattern = (LocalLinearPatternFeatureData)selectedObject.GetDefinition();

Forget C# for a second and spin up a new VBA macro.

  1. Select a patterned component instance;
  2. Run a macro that prints the type of the selected objects types;
  3. Inspect the type of the selected objects from the docs, which will tell you the API objects you can inefer from the ISelectionMgr.GetSelectedObject.

By selecting a patterned component instance will return as component type from ISelectionMgr.GetSelectedObject method.

So, if you get the array from IFeature::GetChildren method for the selected pattern feature then it will return an array size of patterned component instances but every array index is an object type. Then if you try to convert that object to component then you will get error. That’s the point.

On the other hand I have been searching for another method to get the relation between the pattern feature and the patterned component instance.

Not too sure I understand your post. Ideal thing is to post some VBA code with an assembly that has some virtual patterned components for anyone to be replicate your issue.

IFeature.GetChildren does not return components, it returns an array of subfeatures.

1 Like