Accessing All Referenced Documents Including Suppressed

Accessing All Referenced Documents Including Suppressed

Anonymous
Not applicable
2,783 Views
2 Replies
Message 1 of 3

Accessing All Referenced Documents Including Suppressed

Anonymous
Not applicable

Hey All,

 

I am currently working to write some code that will go through a full model and modify the part name of each unique component. Currently for these kinds of tasks I use a function similar to this:

 

Function RecursiveReview(oDoc As Document)

Dim oEachRefDoc As Document

For Each oEachRefDoc In oDoc.ReferencedDocuments
		'Recrusive call of review
		RecursiveReview(oEachRefDoc, TextFileReview, ReviewType, StudioNum)
Next

'Do Work on level

End Function

 

The problem that I have run into is that the Reference Documents does not include all of the suppressed files in the assemblies. Is there any way to collect all documents including these suppressed files?

Accepted solutions (1)
2,784 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

Usually Inventor loads all documents that are referenced by an assembly. The problem with suppressed parts ( and assemblies) is that they are not loaded by inventor. And as you already said the are not in the referenced files lists. The way to find document that are suppressed is by looking at the occurrences in an assembly. occurrences object have an FullDocumentName. with that property you can find all referenced files and put it in a list. if you want to do something with suppressed documents the you will need to load them by opening them.

Have a look at the iLogic code.it will open all documents that are suppressed and therefore not loaded.

Sub Main()
	Dim doc As AssemblyDocument = ThisDoc.Document

	Dim refDocNames As List(Of String) = getRefDocList(doc)

	For Each refDocName As String In refDocNames
		Dim refDoc As Document = getDocument(refDocName)

		' Do the work on your document here
		MsgBox(refDoc.DisplayName)
	Next
End Sub

Public Function getRefDocList(doc As AssemblyDocument) As List(Of String)
	Dim refDocs As List(Of String) = New List(Of String)()
	For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences
		Dim refDocName As String = occ.ReferencedDocumentDescriptor.FullDocumentName

		If (refDocs.Contains(refDocName) = False) Then
			refDocs.Add(refDocName)
		End If

		If occ.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Dim refDoc As Document = getDocument(refDocName)
			refDocs.AddRange(getRefDocList(refDoc))
		End If
	Next
	Return refDocs
End Function

Private Function getDocument(fullDocName As String)
	Dim doc As Document
	Try
		doc = ThisApplication.Documents.ItemByName(fullDocName)
	Catch ex As Exception
		' you could open the files also hidden for speed inprovements 
		' but Then you would need To close them also in some way
		doc = ThisApplication.Documents.Open(fullDocName)
	End Try
	Return doc
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

Anonymous
Not applicable

This actually would work perfectly fine for what I am trying to do, thanks for the help!

0 Likes