Retrieve/Write custom properties with Excel without DSO method (Inactive since 2015)

Hello

I had made a snippet of code to retrieve custom properties in Excel and update them without opening the files with the following code:

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPackAndGo As SldWorks.PackAndGo
Dim openFile As String
Dim myFileName As String
Dim pgFileNames As Variant
Dim pgFileStatus As Variant
Dim pgSetFileNames() As String
Dim pgGetFileNames As Variant
Dim pgDocumentStatus As Variant
Dim status As Boolean
Dim warnings As Long
Dim errors As Long
Dim i As Long
Dim j As Long
Dim namesCount As Long
Dim myPath As String
Dim statuses As Variant

Public Chemin, OldFile As String
Public Ligne1, DernligneASM

Sub ListerOldFichiers()

Dim Fichier As String

Range("A2:B1000") = "" 'Vidage des cellules

Chemin = CheminUser
OldFile = Dir(Chemin & "*.sldasm")

'Appel de la progressbar

UserForm1.Show vbModeless
UserForm1.ProgressBar1.Value = 0

Dim ProgressBar, barre

UserForm1.ProgressBar1.Value = 10

'Ecrire les noms de fichiers dans colone A

Ligne1 = 2 'Départ pour rentrer les noms de fichiers

    Do While OldFile <> ""
    
        Cells(Ligne1, 1) = OldFile
        OldFile = Dir()
        Ligne1 = Ligne1 + 1
    
    Loop

DernligneASM = Range("a65536").End(xlUp).Row

Dim Dernligne2
Dernligne2 = Range("a65536").End(xlUp).Row + 1

OldFile = Dir(Chemin & "*.sldprt")

    Do While OldFile <> ""
    
        Cells(Dernligne2, 1) = OldFile
        OldFile = Dir()
        Dernligne2 = Dernligne2 + 1
        
    Loop

UserForm1.ProgressBar1.Value = 50


Dim Dernligne3
Dernligne3 = Range("a65536").End(xlUp).Row

Ligne1 = 2

For Ligne1 = Ligne1 To Dernligne3
        
        Dim DSO As DSOFile.OleDocumentProperties
        Dim File1, OldDes, k, PropName, Compteur
        
        File1 = Cells(Ligne1, 1).Value
        
        Set DSO = New DSOFile.OleDocumentProperties
        DSO.Open sfilename:=Chemin & File1
        
        Compteur = DSO.CustomProperties.Count
        
        If Compteur <> 0 Then
        
            For k = 1 To Compteur - 1
            
                PropName = DSO.CustomProperties.Item(k).Name
            
                If PropName = "Designation-1" Then
                
                    OldDes = DSO.CustomProperties.Item("Designation-1").Value
                    Cells(Ligne1, 2) = OldDes
                
                End If
                
            Next k

        End If
            
        DSO.Save
        DSO.Close
 
Next

'Fini de remplir et Decharger l'userform

barre = 100
UserForm1.ProgressBar1.Value = barre
Unload UserForm1
ProgressBar = 0 'Réinitialisation

MsgBox "Remplissez la colonne des Nouveaux noms a attribuer puis cliquez sur ''Renommer''"

End Sub

 

My concern is that since SW2015, we can't do these steps since the DSO method doesn't work anymore.

My question is: How can I do what I was doing with DSO with SW2016 (or SW2015)?

Thank you

 

With macro I don't know any other will surely guide you, but as you have the mycad tool you can also do it with smartbom which exports you a nomenclature with the chosen properties and this without knowing programmed in vba or other.

Hello

To retrieve, by macro, custom properties in Excel and update them without opening the files, you will have to "play" with the "Document Manager API" (see here), which requires obtaining a license number (see here). Then here you will  find an example of code (in C#) to adapt.

The sbadenis solution seems to me to be much simpler and faster to implement and uses tools that will be maintained over time.

Kind regards

Hello and thank you for your info.

The thing is that I don't just recover data to put it in Excel... I rename all my files, while updating their properties and I give the links back to the MEPs.

As far as I know, the MyCad tools don't do that and SW Explorer doesn't give the link back to the MEPs so it's not super practical...

The advantage of this method was that the readability in Excel is just perfect for this kind of processing. See the image in the attachment instead.

 

 


capture.jpg
1 Like

With project manager in this case you can rename in bulk according to certain rule and modify certain properties according to certain rule as well. And of course you get the MEPs.

And if you can't do what you want, the project manager combo to copy, rename en masse, then batch properties to modify the properties.

To test it will only cost you a little time and if necessary we will explain how to do it.

Hello

I don't want to rename according to rules actually.

Let's imagine that my client is slow to provide me with plan numbers according to his data management system. So I'm going to start (or even finish) my study with filenames that will have names such as: Axe, Inf Housing, Upper Rankcase, etc...

Once it tells me that my files (PRT, ASM and DRW) should be called for example: 2543-40001; 2543-40002; 2543-40003; 2543-40004; etc... I must be able to rename the files while keeping the links and respecting its numbering.

That's what my EXCEL macro allowed me to do, which listed the file names by putting the properties in front of each part and then, I just had to say which number went in front of this or that part... same for the properties... and all WITHOUT opening SW!

The only time I needed SW was to restore the links of the MEP.

With a project manager, I don't think I can be that flexible!

1 Like

Answer with Project manager you can rename en masse according to rules or as you wish rename room by room according to what you want.

In 1 you choose the part or assembly to rename in 2 renaming rules to apply (in your case no rules)

In 3 the results of the rule applied or if no rule manual renaming possible.

In 4 apply the modification for all the pieces with the ruler or for the part and move on to the next one.

 

For the rules possibility to rename according to a counter, a property...

The simplest one is to try it on a small assembly, I am convinced that you will be able to realize your need.

And if necessary, the forum is there to help you!

FYI, Project Manager is not only very complete, but also very flexible!

 


project_manager.png