Retrieve the preview image in PDM

Hello

I would like to find a way to find the location or way to use the preview image of a part or assembly that is displayed in the PDM tab in SolidWorks.

This would make it possible not to have to regenerate these images for later use (in the documentation for example), but would allow an image to be directly available.

If anyone has an idea, thank you in advance!

1 Like

Hello

The image must be the one encapsulated in the Solidworks file. This is the one that is generated during registration. A priori impossible to recover now (since Solidworks encrypts the .sldprt, .sldasm and .slddrw files).

On the other hand I don't have this 3D view in my EPDM 2022 Sp3.0. Is it a novelty or is it a parameter that I can't find ??

2 Likes

Hello
Normally it's visible and has always existed if my memory serves me correctly.
It may be hidden, as the 3 visible elements (arbo PDM, ISO view and trunk info) are resizable.

Hello @Cyril.f
Well done: the features were superimposed...

Thank you

2 Likes

Hello
I searched so by macro we can recover the preview image. Below is the snippet of code to run from Excel:

Sub TestExportBitmap()
Dim sFilename As String
Dim file15 As IEdmFile17
Dim folder              As IEdmFolder6
Dim vault               As EdmVault5

Dim Image As stdole.IPictureDisp

Set vault = New EdmVault5

vault.LoginAuto "<Nom de coffre>", 0

sFilename = "xxx" 'Renseigner le chemin d'accès au fichier
Set file15 = vault.GetFileFromPath(sFilename, folder)
Set Image = file15.GetThumbnail2(file15.CurrentVersion)

stdole.SavePicture Image, "C:\PDF\Test.BMP"
End Sub

EDIT: This snippet of code is very basic, depending on the need I can embellish it with features. As coded, it only retrieves the image from a predefined file and in its locally loaded version.

4 Likes

Thank you, it's perfect that way!

Thank you for sharing @Cyril.f !
On my side I have a small problem concerning your piece of code... that I can't seem to solve and I wanted to know if you had a similar problem or not at all...

I am currently trying to retrieve the part previews of a set via a bill of materials exported from PDM to Excel with a column containing the " IDs " of each file.
And when I run the code, I get an error on some file on the line ' Set Image =...  ›:

and when I try to retrieve via a macro from SolidWorks the preview of these same parts, I also get an error:

Do you have an idea where the problem could come from?

Hello
The file may not be locally cached.
I don't use this macro so I would need the complete code to test and see where the problem can be.

1 Like

Not stupid for the fact that it's not in local cache... I have to look at how to load them locally before getting the image to test!

Here is the detail of the code in question :slight_smile:
Just to give some explanation, this puts the file preview image in a comment of an Excel cell (Column F) based on the ID of each file (Column B)!
Just change the PDM vault name and file path for the image and it works :wink:

and here is my Excel file structure from which I launch the macro:

Sub TestExportBitmap()
Dim sFilename As String
Dim file15 As IEdmFile17
Dim vault As EdmVault5
Dim Image As stdole.IPictureDisp

Set vault = New EdmVault5

vault.LoginAuto "NOM_COFFRE", 0
CheminImg = CHEMIN_IMAGE

For i = 2 To Cells(1, 1).End(xlDown).Row

On Error Resume Next
        
        Set file15 = vault.GetObject(EdmObject_File, Range("B" & i).Value)
        Set Image = file15.GetThumbnail2(file15.CurrentVersion)

        stdole.SavePicture Image, CheminImg

        If Dir(CheminImg) <> "" Then

            If Not Range("F" & i).Comment Is Nothing Then Range("F" & i).Comment.Delete

            Range("F" & i).AddComment
                With Range("F" & i).Comment.Shape
                    .Fill.UserPicture CheminImg
                    .Width = 300
                    .Height = 250
                End With

        End If
        
    Kill CheminImg
    Set Image = Nothing
    
On Error GoTo 0
    Next

End Sub

The result:

We can see that there are no comments on some parts and therefore the preview...

1 Like

Hello
You must use the vault BatchGet method. CreateUtility, personally I used this piece of code:

Sub PDMBatch()
Set PDMBatchGetUtil = vault.CreateUtility(EdmUtil_BatchGet)
PDMSelItems(0).mlDocID = File.ID
PDMSelItems(1).mlProjID = Folder.ID
PDMBatchGetUtil.AddSelectionEx vault, File.ID, Folder.ID, iNbVers
PDMBatchGetUtil.CreateTree 0, EdmGetCmdFlags.Egcf_AsBuilt
PDMBatchGetUtil.CreateTree 0, EdmGetCmdFlags.Egcf_SkipExisting
PDMBatchGetUtil.GetFiles 0
End Sub

With iNbVers = version number of the file to be obtained.
The AsBuilt retrieves the file as saved in the vault (version links) and the second SkipExisting option allows you not to load the files already locally (I did this because I had the whole vault in scan so faster).
To see if you also need a cache flush function between two gets, this code works:

Sub ClearCache()
Set ClearLocalCache = vault.CreateUtility(EdmUtil_ClearLocalCache)
ClearLocalCache.AddFolder (cCoffre)
ClearLocalCache.CommitClear
End Sub

cVault = Name of your PDM vault

1 Like

Well I tested and it doesn't change anything ... impossible to have the image on some parts :confused: However I checked well, I have the files in question locally.
I don't see where the problem comes from!

Hello @yves-marie.freyssinet

If you have access to the archive server (so hack reserved for an admin) you can always go and get the images you are looking for.
Previews are in the directories that store the versions of the files.
In practice it seems to be jpg renamed to .img (just to be painful to open);

Nb:

  1. the storage logic on the archive server is weird: you have to have the file ref (the ID) but in hexadecimal (otherwise it's not funny) and the files are classified in 16 directories.
    all files with the same ID ending are in the same directory. In the image above, the hexadecimal ID of the file ends by 4, so the directory is classified in the directory ending with 4.
  2. The name of the image files is even weirder: it may be a chrono number and there may be a SQL table that makes the link between the name of the file/its version and the preview file. You have to rummage through the sql tables to find it I think.
1 Like

Thanks for the @froussel track! But unfortunately I don't have access to the archive server... :confused:
But it's still good to know that the images are there! Maybe it will help someone else :slight_smile:

Hello
I just tested and I actually have the same problem on some files. I haven't found where it comes from yet (for now, the only thing I see is that the file where it crashes is converted to the 2023 version, which is not the case with the test file I was pointing to when I proposed the code). No more ideas than that for the moment.
Edit: @froussel , well seen, I'm so used to Thumbs files having nothing to do with image files I've never dwelt on it. For the numbering yes it must be for a link with the SQL database, on the other hand with the dates of registration of the files we can get away with it (not checked in the case of files converted to version replacement if the image was regenerated).

So I answer myself, I think I've found it. I just looked in the file folder that is returning the error and I don't have an image corresponding to the date the file was saved.
So the vault seems to be doing well but via the APIs it doesn't work.

1 Like

Thanks for the investigation :slight_smile:
Well, I think it will remain a mystery in this case... I would have liked to have had more explanation of why and how in the PDM API help but there is nothing!