ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
JDJerome De San Nicolás26/06/2019

Hi all,

I have un little problem with the document manager api : GetExternalFeatureReferences2

let me explain :

I want to get the BOM for an assembly in several configuration, with component name and referenced configuration.

For a simple exemple I have done an assembly with 2 configs and 2 parts (with 2 configs each) it's look like this :

Assy config 1 :

                     Part 1    -    Config 1

                     Part 2    -    Config 1

Assy config 2 :

                     Part 1    -   Config 2

                     Part 2    -   Config 2

                     Part 2    -   Config 2 (second occurrence of part 2 is suppressed in Assy config 1)

And that's how my code works :

the "main" sub ; (how can I format my code in a forum post?)

Sub GetRefWConfigs()

DTGView_Tbl.Rows.Clear()

Dim AsmName As String = IO.Path.GetFileName(TBox_Asm.Text) 'I get the assy path from an userform

swDoc = swDocMgr.GetDocument(TBox_Asm.Text, 2, False, OpenErr) 'get the assy doc
configMgr = swDoc.ConfigurationManager

Dim vConfAsm As Object
Dim conf As Object
vConfAsm = configMgr.GetConfigurationNames2(SwConfsResult) 'get all config

For Each conf In vConfAsm 'loop on all assy configurations

DTGView_Tbl.Rows.Add({True, AsmName, IO.Path.GetDirectoryName(TBox_Asm.Text),
AsmName, AsmName, conf, "", 0}) 'puttin' the result in a datagridview
TraverseCpt(swDoc, 1, conf) 'call the components

Next


swDoc.Save()
swDoc.CloseDoc()

End Sub‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

the "Traverse component" sub :

Sub TraverseCpt(ByVal swDoc As SolidWorks.Interop.swdocumentmgr.SwDMDocument18, ByVal Level As Integer, ByVal AssyConfig As String)

Dim dmSearchOpt As SolidWorks.Interop.swdocumentmgr.SwDMSearchOption
Dim ExtRefs() As String
Dim ExtRefsconfig() As String
Dim dmExtRefOption As SolidWorks.Interop.swdocumentmgr.SwDMExternalReferenceOption2
Dim numExtRefs As Integer

'setting up search options maybe this is not good
dmExtRefOption = swDocMgr.GetExternalReferenceOptionObject2
dmSearchOpt = swDocMgr.GetSearchOptionObject()
dmSearchOpt.SearchFilters = (SolidWorks.Interop.swdocumentmgr.SwDmSearchFilters.SwDmSearchExternalReference)

dmExtRefOption.Configuration = AssyConfig 'assembly config
dmExtRefOption.NeedSuppress = False
dmExtRefOption.SearchOption = dmSearchOpt
numExtRefs = swDoc.GetExternalFeatureReferences2(dmExtRefOption)
ExtRefs = dmExtRefOption.ExternalReferences
ExtRefsconfig = dmExtRefOption.ReferencedConfigurations

For i = 0 To ExtRefs.Length - 1 'loop on component

DTGView_Tbl.Rows.Add({True, IO.Path.GetFileName(ExtRefs(i)),
IO.Path.GetDirectoryName(ExtRefs(i)), IO.Path.GetFileName(ExtRefs(i)),
IO.Path.GetFileName(ExtRefs(i)), ExtRefsconfig(i), "", 0})

Next

dmSearchOpt = Nothing
dmExtRefOption = Nothing
ExtRefs = Nothing

End Sub

And that's what I got at the end (I put the datas in a datagridview) :

the components loop seems only to take un account the last active configuration

How can I use GetExternalFeatureReferences2 with assembly configuration (or tell GetDocument to get a specific config??) 

Do you guys have an idea ?

and thank to all how have read all that !