Here is one example code you can review and try out. I tried to include lots of 'comments' right within the code to explain what each line of code is attempting to do. I hope this helps some. I created a separate Function just for extracting the FullFileName(s) of any/all 'derived in' source files from any given Inventor Document. So, it iterates though all referenced documents one time just to collect those source file's FullFileNames to a collection, then you can iterate through them again to do what you want with each of them, while avoiding those source files.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
'initialize the global variable for the collection of Strings
oDerivedInSourceFiles = New HashSet(Of String)
'get the collection of all referenced documents to a variable
Dim oRefDocs As Inventor.DocumentsEnumerator = oDoc.AllReferencedDocuments
'iterate through all referenced documents once to find all 'derived in source files'
For Each oRefDoc As Inventor.Document In oRefDocs
'this joins the ones returned from the custom Function into our main collection
oDerivedInSourceFiles.UnionWith(ExtractDerivedInPartSourceFiles(oRefDoc, oDerivedInSourceFiles))
Next 'oRefDoc
'now iterate through all referenced documents again, and do what you want
For Each oRefDoc As Inventor.Document In oRefDocs
'if this referenced document's FullFileName is in our collection,
'then it is a 'derived in source file', so skip over it
If oDerivedInSourceFiles.Contains(oRefDoc.FullFileName) Then Continue For
'<<< YOUR CODE HERE FOR WHAT YOU WANT TO DO WITH EACH REF DOC >>>
Next 'oRefDoc
End Sub
'variables declared between routines are 'global' (can be accessed by all routines)
'create a new collection of Strings, which does not maintain order, and does not allow duplicates
Dim oDerivedInSourceFiles As HashSet(Of String)
'this will try to extract any/all 'derived in' part component source file(s) FullFileName
'the Optional input/output HashSet can be used to add to an already existing HashSet
Function ExtractDerivedInPartSourceFiles(doc As Inventor.Document, _
Optional ByRef existingSet As HashSet(Of String) = Nothing) As HashSet(Of String)
'if this is not a 'Part', then this method is not intersted in it, so exit, and return Nothing
If Not TypeOf doc Is Inventor.PartDocument Then Return Nothing
'create a PartDocument type variable, and set this document as its value (enables recognition)
Dim oPDoc As Inventor.PartDocument = CType(doc, Inventor.PartDocument)
'get all of this part's 'derived in' part components
Dim oDPCs As DerivedPartComponents = oPDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
'if there are none, then we are done here, exit routine, and return Nothing
If oDPCs.Count = 0 Then Return Nothing
'create a new collection of Strings, which does not maintain order, and does not allow duplicates
If existingSet Is Nothing Then existingSet = New HashSet(Of String)
For Each oDPC As DerivedPartComponent In oDPDc
'if it is no longer 'Linked' to the source file, then no useful info here
If Not oDPC.LinkedToFile Then Continue For
'if 'Link' is suppressed, then may not be able to access useful info here
If oDPC.SuppressLinkToFile Then Continue For
'get the DocumentDescriptor (describes native document reference)
Dim oDocDesc As DocumentDescriptor = oDPC.ReferencedDocumentDescriptor
'if missing, unresolved, suppressed, or disabled, then skip this one
If oDocDesc.ReferenceMissing OrElse oDocDesc.ReferenceSuppressed OrElse oDocDesc.ReferenceDisabled Then Continue For
'get the FileDescriptor (describes reference to a file)
Dim oFD As FileDescriptor = oDocDesc.ReferencedFileDescriptor
'if missing or disabled, then skip this one
If oFD.ReferenceMissing OrElse oFD.ReferenceDisabled Then Continue For
'add this File's FullFileName to our collection
existingSet.Add(oFD.FullFileName)
Next 'oDPC
'return that collection to the method that called this method to run
Return existingSet
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)