Export Solidworks Asm to Xls (does not return the configuration description when it is active)

I have a program that will export the information contained in an assembly to make a file .xls

It works perfectly except that it does not return the description of the configuration when it is active.  


bom-dlb.swp

Do you have a small test assembly with 2-3 parts to provide, in order to properly situate the problem?

Not having the same properties, not sure to understand it well.

And also cause SW version if you can point out the problem (which property you get and which one you want in your xls file)

Hello

If I understood correctly, you have to modify a line in the method below so that the macro goes to look for the information in the "specific to the conference" tab.

Public Sub AddElementBOM(swComp As SldWorks.Component2, nLevel As Long)

    Set swcustmng = swextention.CustomPropertyManager(swConf.Name) 'Va cherche dans l'onglet description des propriete personnaliser
   
    Call swcustmng.Get6("Description", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    vBOM(UBound(vBOM)).m_Properties(4) = sPropRVal
End Sub

Instead of swextention. CustomPropertyManager(""), swextention. CustomPropertyManager(swconf.name)

3 Likes

Attached is an example of assembly

Normally the nomenclature should look like this:

ERP   Code Tree     Description             Quantity  
1 1198        RDL NFE 25-514 M3x8 A2 1                
2 2489        RDL NFE 25-514 M6x12 A2 1                

With the VBA Program it gives this result:

ERP CODE TREE    DESCRIPTION            QUANTITY    
-----1        001198        RDL NFE 25-514 MXX A2 2        


exemple.zip

Hello

So I just tested two solutions. If you want to go through the properties, your table doesn't  work because it doesn't fill in "Description" properties in the files (hence the RDL NFE 25-514 MXX A2 as a result), so you would have to modify this table by adding the $PROPRIETE@Description parameter .

Otherwise you can get the description of the configuration directly, in which case you have to change the code as follows:

Public Sub AddElementBOM(swComp As SldWorks.Component2, nLevel As Long)
    Dim sCompName As String
    Dim i As Long
    Dim swModel As SldWorks.ModelDoc2
    Dim swcustmng As SldWorks.CustomPropertyManager
    Dim swextention As SldWorks.ModelDocExtension
    Dim sPropVal As String
    Dim sPropRVal As String
    Dim bWasResolve As Boolean
    Dim bLinkto As Boolean
    Dim swConf As SldWorks.Configuration
    Dim sDescription As String
    
    sCompName = swComp.Name2
    sCompName = GetRealNameComp(sCompName)
    Debug.Print sCompName
    'Recherche element de tableau correspondant a sCompName si existe increement la compteur
    For i = 1 To UBound(vBOM)
        If vBOM(i).m_CompName = sCompName Then
            vBOM(i).m_Count = vBOM(i).m_Count + 1
            Exit Sub
        End If
    Next i
    'Il n'existe pas je crée l'element
    ReDim Preserve vBOM(UBound(vBOM) + 1)
    vBOM(UBound(vBOM)).m_CompName = sCompName
    vBOM(UBound(vBOM)).m_Count = 1
    vBOM(UBound(vBOM)).m_FileName = swComp.GetPathName
    vBOM(UBound(vBOM)).m_Level = nLevel
    vBOM(UBound(vBOM)).m_RefConf = swComp.ReferencedConfiguration
    
    Set swModel = swComp.GetModelDoc2
    If nLevel = 0 Then
        Set swConf = swModel.GetActiveConfiguration
    Else
        Set swConf = swModel.GetConfigurationByName(swComp.ReferencedConfiguration)
    End If
    
    vBOM(UBound(vBOM)).m_RealName = BOMPartNumber(swConf, swModel) 'La variable vBOM (Nom du fichier) = "BOMPartNumber" (Nom de la configuration)
    Set swextention = swModel.Extension
    Set swcustmng = swextention.CustomPropertyManager(swComp.ReferencedConfiguration)
    'N° Proto
    'Indice MAJEUR
    'Libelle 02
    'Matiere
    Call swcustmng.Get6("N° Proto", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    vBOM(UBound(vBOM)).m_Properties(0) = sPropRVal
    Call swcustmng.Get6("Indice MAJEUR", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    vBOM(UBound(vBOM)).m_Properties(1) = sPropRVal
    Call swcustmng.Get6("Libelle 02", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    vBOM(UBound(vBOM)).m_Properties(2) = sPropRVal
    Call swcustmng.Get6("Matiere", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    vBOM(UBound(vBOM)).m_Properties(3) = sPropRVal
    
    'Set swcustmng = swextention.CustomPropertyManager("") 'Va cherche dans l'onglet description des propriete personnaliser
   
    'Call swcustmng.Get6("Description", True, sPropVal, sPropRVal, bWasResolve, bLinkto)
    sDescription = swConf.Description
    vBOM(UBound(vBOM)).m_Properties(4) = sDescription
End Sub

 

To simplify, I added sDescription and the recovery of the description of the active configuration.

Cyril-f. Thank you for your answer.

I did a test. We're getting closer to the truth.

The result is as follows with the modification to retrieve the configuration description directly: 

ERP CODE TREE    DESCRIPTION            QUANTITY    
-0        Example         Default 1                 
--1        001198        RDL NFE 25-514 M3x8 A2 2        


But there is still a problem. There should be two lines. 

 ERP    Code Tree    Description            Quantity
        1 1198        RDL NFE 25-514 M3x8 A2          1
        2 2489        RDL NFE 25-514 M6x12 A2         1

Hello

So the problem comes from the part of the code below in the AddElementBOM(swComp As SldWorks.Component2, nLevel As Long) module:

    For i = 1 To UBound(vBOM)
        If vBOM(i).m_CompName = sCompName Then
            vBOM(i).m_Count = vBOM(i).m_Count + 1
            Exit Sub
        End If
    Next i

 

The macro doesn't see that there is a different file since it relies on the name of the component which is identical, so it considers that the component already exists and only adds a quantity.

I modified it like this, it works on components with screw/washer type configuration... On the other hand, on a file with a configuration that could be in quantity 2 (open/closed configuration for example) this will not work.

    For i = 1 To UBound(vBOM)
        If vBOM(i).m_CompName = sCompName And swComp.ReferencedConfiguration = vBOM(i).m_RefConf Then
            vBOM(i).m_Count = vBOM(i).m_Count + 1
            Exit Sub
        End If
    Next i

 

It will therefore probably be necessary to add control criteria or to base it on the Solidworks nomenclatures and then export it to Excel.

1 Like

Thank you for your help. I think the right option is indeed to start with the Solidworks BOMs and then export it to Excel.