How do I retrieve the configuration list of a component in an assembly? VBA Solidworks

Hello

I'm looking to retrieve the configuration list of a component in an assembly to modify the custom properties of the configurations of that component from an assembly.

For now, I can make a list of the components of the assembly, but I can't list the configurations of each component. Then, I'll have to be able to modify the custom properties of the configurations for each component from the assembly.

Do you have any solutions?

Thank you.

 

Hello

If you manage to list all the components of an assembly, I guess it's using the "GetChildren" function followed by a loop to retrieve at least the name of the components. If this is the case, you can, in this loop, retrieve the "ModelDoc2" of each "Component2" using the "GetModelDoc2" function and thus from there list the configurations of your "ModelDoc2" using the "GetConfigurationNames" function.
I don't know if it's all clear to you so here's a little example in C# language (no time to translate it into vba):

private void TraverseComponent(Component2 swComp)
{
    ModelDoc2 swDoc;
    object[] vChildComp;
    Component2 swChildComp;
    string namePart = string.Empty;
    Boolean boolstatus;
    string AssemblyTitle = swDoc.GetTitle();
    int i = 0;
    vChildComp = (object[])swComp.GetChildren();
    while (i < vChildComp.Length)
    {
        swChildComp = (Component2)vChildComp[i];
        swDoc = (ModelDoc2)swChildComp.GetModelDoc2();
        if (AssemblyTitle.ToLowerInvariant().Contains(".sldasm"))
        {
            namePart = swChildComp.Name2 + "@" + AssemblyTitle.Substring(0, AssemblyTitle.Length - 7);
        }
        else
        {
            namePart = swChildComp.Name2 + "@" + AssemblyTitle;
        }

        int j = 0;
        try
        {
            boolstatus = swDoc.Extension.SelectByID2(namePart, "COMPONENT", 0, 0, 0, false, 0, null, 0);

            object[] configNameArr = null;
            string configName = null;
            
            configNameArr = (object[])swDoc.GetConfigurationNames();
            for (j = 0; j <= configNameArr.GetUpperBound(0); j++)
            {
                configName = (string)configNameArr[j];
                MessageBox.Show((configName);
            }
        }
        catch (Exception)
        {
            continue;
        }
            
        i++;
    }
}

This is the code style behind the program you'll find here.

Kind regards

3 Likes