Mass Recovery via Document Manager

Hi all :slight_smile:

Given the responsiveness of everyone on this forum I take this opportunity to ask a question and not stay stuck for hours ...
I am currently trying to recover the mass of the parts via the Document Manager but I am experiencing a slight problem!
To be able to explain in a little more detail, here is the code:

Const key As String = "CLEF_DOCUMENT_MANAGER"

Dim swDmClassFactory As SwDocumentMgr.swDmClassFactory
Dim swDmApp As SwDocumentMgr.SwDMApplication

Dim docType As SwDmDocumentType
Dim FilePath As String
Dim allowReadOnly As Boolean
Dim result As SwDmDocumentOpenError
Dim DocProp As SwDMDocument
Dim Config As SwDMConfiguration
Dim GestConfig As SwDMConfigurationMgr
Dim bret As SwDmMassPropError

Sub Test()

Set swDmClassFactory = CreateObject("SwDocumentMgr.SwDMClassFactory")

    If Not swDmClassFactory Is Nothing Then

        Set swDmApp = swDmClassFactory.GetApplication(key)
        FilePath = "CHEMIN_PRT"

                Set DocProp = swDmApp.GetDocument(FilePath, swDmDocumentPart, False, result)
                Set GestConfig = DocProp.ConfigurationManager
                Set Config=GestConfig.GetConfigurationByName(GestConfig.GetActiveConfigurationName)

                valeurs = Config.GetMassProperties(bret)
                Debug.Print "Masse : " & valeurs(5)
                DocProp.CloseDoc


    Else
        MsgBox "Erreur"
    End If


End Sub

The problem is this: for some parts (without me being able to find any common points between those that don't work) the array ' values ' is filled with 0 while I have no error on the values of ' result ' and ' bret '. And when I open the document on SW and I look at the mass it is not zero, so I don't understand where the problem comes from :confused:
I should point out that I have verified that the version of the part is also correct as indicated in the API Help: GetMassProperties Method (ISwDMConfiguration) - 2022 - SOLIDWORKS API Help

Does anyone have a lead at any rate?

Thanks in advance :smiley:

In terms of configurations?

I'm trying to recover the mass of the part and with the document manager I don't think there is any other way than to go through the configuration of the part in question indeed.

Hello;

Some tips here:

the program is in C# but I think it's not too difficult to convert it to VB...

Otherwise here:

(see footnote for mass calculations).

Kind regards.

3 Likes

Hello;

After some research, it seems that the recovery of masses on configurations is conditioned by the reconstruction of the components.
Unfortunately " Document Manager " doesn't seem to be able to do it, I'm talking about " reconstructing 3D " with Solidworks or, perhaps, assigning Fixed Masses on your components but it's not very holy...

Kind regards.

Thank you for your feedback @Maclane !
I've already based myself on these lines of code already, ahaha :slight_smile: CodeStack is a good reference when you're looking to make macros on SolidWorks!

Regarding your message just below, where can you find this info about the reconstruction of the 3D? because I tried on the problematic files in question to rebuild them and then try to recover the mass via the document manager but always the same...

1 Like

Hello;

I gleaned this information from the official Solidworks forum (3Dexperience) with the filter " SWDM " (for Solidworks Document Manager).

2 Likes