VBA Macro in Drawing - how to get the name of the reference part configuration

Hello

I would like to retrieve the name of the configuration of the part used as a reference in a drawing.

Here's the snippet of code I currently have:
 

We activate the work doc
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set FileSys = CreateObject("Scripting.FileSystemObject")

Gets the full path of the current document, including the file name
PathName = Part.GetPathName
Gets the path to the current document, without the file name:
FilePath = Left(PathName, InStrRev(PathName, "\"))
Gets the file name:
FileName = Right(PathName, Len(PathName) - InStrRev(PathName, "\"))
Typedoc = Right(FileName, 3)

Select Case Typedoc
Box "drw", "DRW"
    
Set swview = Part.GetFirstView
Set swview = swview. GetNextView 'enables/retrieves the first view for custom properties
Set swRefDoc = swview. ReferencedDocument ' We now have swRefDoc the 3D of the drawing
               
We retrieve the properties of the config of the reference part or assembly
configNames = swRefDoc.GetConfigurationNames
vConfigNameArr = swRefDoc.GetConfigurationNames

For Each vConfigName In vConfigNameArr
Debug.Print vConfigName
vCustInfoNameArr = swRefDoc.GetCustomInfoNames2(vConfigName)

 

except that in "configNames" I get all the configs of the part while I would only want the config of the part used in the drawing and then be able to delete my For Each loop.

Thank you for your help, I'm sure it's bogus for you.

and for a part or assembly, I am looking to have the value of a specific property (e.g. Engineering PartNumber) only present in the "configuration properties" for the configuration of the active part.


prop.png

For active configuration:

https://help.solidworks.com/2020/english/api/sldworksapi/Get_List_Of_Configurations_Example_VB.htm?verRedirect=1

For custom property related to configuration:

https://help.solidworks.com/2020/English/api/sldworksapi/Get_Custom_Properties_for_Configuration_Example_VB.htm?verRedirect=1

Hello;

It's quite simple;

    Dim swConfigMgr                 As SldWorks.ConfigurationManager
    Dim swConfig                    As SldWorks.Configuration
....
Set swConfig = swConfigMgr.ActiveConfiguration ' configuration Active
stnameConfig = swConfig.Name 'Active Configuration Name

Regards.

1 Like

Hello Maclane,

That's what I put but it doesn't work.

No_article = Part.GetCustomInfoValue("Default", "Engineering PartNumber") --> it works

No_article = Part.GetCustomInfoValue(swConfig, "Engineering PartNumber") --> it doesn't work (Runtime Error 13, Type Mismatch)

Thank you for your feedback

Hello;

Try with:

Dim swCustProp As Variant
....
 Set swCustProp = swModel.Extension.CustomPropertyManager(swConfig)
No_article = swCustProp.Get4("Engineering PartNumber", False, val, valout)
No_article = valout 'with dim No_article as string

Kind regards

1 Like

Hello Pierre,

In the last line of your previous message, the swConfig variable points to an iConfiguration object (in this case swconfig is the current config), not the string containing its name, hence error 13.
This is probably swConfig.Name is the string to use (also called stnameConfig by Maclane).

Kind regards

1 Like

Thanks to both of you, Maclane & m.blt.
I knew it was something bogus... but not easy for me.