Hello
I'm new to using the Document Manager APIs.
There's something I don't quite understand about the GetExternalFeatureReferences3 (ISwDMDocument27) method.
Environment: an assembly with multiple configs, in some configs there are components in the "deleted" state.
Objective: via the Document Manager, for each config, retrieve the list of components (first level), without those that are in the "deleted" state.
Achievement: I use the GetExternalFeatureReferences3 function on the ISwDMDocument27 object, after creating the search options.
' Get external references
dmExtRefOption = dmDocMgr.GetExternalReferenceOptionObject2
dmExtRefOption.Configuration = vCfgName
dmExtRefOption.NeedSuppress = False
dmSearchOpt = dmDocMgr.GetSearchOptionObject()
dmSearchOpt.SearchFilters = (SwDmSearchFilters.SwDmSearchExternalReference + SwDmSearchFilters.SwDmSearchForPart)
dmExtRefOption.SearchOption = dmSearchOpt
' Gets the paths and filenames of the external references,
' whether the external references are broken, and the names of their
' referenced configurations
numExtRefs = dmDoc.GetExternalFeatureReferences3(dmExtRefOption)
extRefs = dmExtRefOption.ExternalReferences
Problem: in the search options, whether I set NeedSuppress to True or False, I find in my list of external references all the components, whether they are in "deleted" or not.
Is there anything I misunderstood about using this feature?
Should I rather go through the extraction of the xml from the head file? ( ISwDMDocument::GetXMLStream)
I need your enlightenment...
Edit: I wanted to put the complete code, but apparently the site blocks it...
In my opinion, the Needsupress function looks for deleted refs, not deleted components.
See https://help.solidworks.com/2022/english/api/swdocmgrapi/SOLIDWORKS.Interop.swdocumentmgr~SOLIDWORKS.Interop.swdocumentmgr.ISwDMExternalReferenceOption~NeedSuppress.html
And more particularly the partoie remarks:
Yes that's what I saw in the doc, but I don't really understand the distinction between "deleted reference" and "deleted component"...? (at least in an assembly)
I'll see what I can do with ISwDMComponent::ISSuppressed
Digging into SolidWorks.Interop.swdocumentmgr, I saw that there were also GetComponents and GetComponentVisibleByDisplayStateName functions on the ISwDMConfiguration17 object
I have the impression that it corresponds better to what I am looking for, I will also look at this side.
I still find that the Document Manager doc is not great, compared to the Solidworks API doc...
Hello
so I go through the getcomponents function (on the config), then I check the status with ISwDMComponent::ISSuppressed.
(I could have stayed with the getexternalreferences3 function, and done the same IsSuppressed check, but the getcomponents function required less code in the end.
Sub Recup_listeComposants()
'reinitialisation de la liste des composants'
ReDim ListeComposants(0)
'drapeaux'
Dim FlagDebut As Boolean
FlagDebut = True
Dim FlagCorrespondance As Boolean
FlagCorrespondance = False
'parcours config'
Dim vComponents As Object
vComponents = swCfg.GetComponents
If Not (IsNothing(vComponents)) Then
Dim swDmComponent As SwDMComponent11
For i = 0 To UBound(vComponents)
swDmComponent = vComponents(i)
'verif composant non supprimé'
If Not swDmComponent.IsSuppressed Then
'ajout à la liste des composants'
'verif si première entrée'
If FlagDebut Then
EntreeListeComposantsNouveau(0) = swDmComponent.PathName
EntreeListeComposantsNouveau(1) = swDmComponent.ConfigurationName
EntreeListeComposantsNouveau(2) = 1
ListeComposants(0) = EntreeListeComposantsNouveau
FlagDebut = False
Else
'verif si entree deja existante (ajout flag)'
For Each EntreeListeComposants In ListeComposants
If (EntreeListeComposants(0) = swDmComponent.PathName And EntreeListeComposants(1) = swDmComponent.ConfigurationName) Then
EntreeListeComposants(2) = EntreeListeComposants(2) + 1
FlagCorrespondance = True
Exit For
Else
FlagCorrespondance = False
End If
Next
'si pas de correspondance, ajout entree'
If Not FlagCorrespondance Then
ReDim Preserve ListeComposants(UBound(ListeComposants) + 1)
ListeComposants(UBound(ListeComposants)) = {swDmComponent.PathName, swDmComponent.ConfigurationName, 1}
End If
End If
End If
Next 'component'
End If
End Sub
In this function I go through the entries retrieved with getcomponents to make a list of the components used (file + config) with their quantity.
There may be cleaner, but it works:)
I'm still interested, if someone can explain to me why the GetExternalFeatureReferences3 function (ISwDMDocument27) doesn't filter for deleted components when you set needsuppress to false (the difference between reference and componant?)
Thank you
Hello
I think there is one that checks the feature manager tree and the other checks the information stored in the file's memory (the asms keep in memory the links to the different files they call). Hence the notion of components and references.
Unless I'm mistaken, DocManager allows you to work on files without opening them, hence probably this behavior in SW on an open file.