In AllReferencedDocuments: Filter out Parts which are referenced because of linked parameters

In AllReferencedDocuments: Filter out Parts which are referenced because of linked parameters

emanuel.c
Collaborator Collaborator
241 Views
4 Replies
Message 1 of 5

In AllReferencedDocuments: Filter out Parts which are referenced because of linked parameters

emanuel.c
Collaborator
Collaborator

I have a function which runs through all referenced documents in an assembly. I basically use this because it is faster that using Occurrences. But it will pull in parts which are referenced because of linked parameters (and possibly derived too, though I didn't check that yet).

 

If assembly has Part 1 and Part 2, but Part 1 has parameters linked to Part 3, I would like to avoid reading Part 3. Just read Part 1 and 2.

 

In a For loop like this how can I filter out parts which are referenced as such?

Thank you much!

 

Dim oDoc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument

For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
	
	'Avoid parts with following properties
	If oRefDoc.ComponentDefinition.Document.IsModifiable = False Then Continue For			
	'If oRefDoc.ComponentDefinition.Suppressed Then Continue For
	If TypeOf oRefDoc.ComponentDefinition Is VirtualComponentDefinition Then Continue For
	If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
	
	' Get the PropertySets object.
	Dim oPropSets As PropertySets = oRefDoc.PropertySets
	' Get the design tracking property set.
	Dim oPropSet As PropertySet = oPropSets.Item("Design Tracking Properties")
	' Get the part number iProperty		
	Dim oPartName As String = oRefDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value
	' Get the description iProperty
	Dim odescr As String = oRefDoc.PropertySets("Design Tracking Properties").Item("Description").Value
	'MessageBox.Show(oPartName)
	
	MessageBox.Show("Part Name: " & oPartName & vbLf & "Description: " & odescr)
	
Next

 

0 Likes
242 Views
4 Replies
Replies (4)
Message 2 of 5

daltonNYAW9
Advocate
Advocate

I dont have any files I can think of atm that have a referenced file attached to them so couldnt test.
Try this:

If oRefDoc.Open = False Then Continue For
0 Likes
Message 3 of 5

emanuel.c
Collaborator
Collaborator

No, that doesn't do it, unfortunately. Thanks though!

0 Likes
Message 4 of 5

daltonNYAW9
Advocate
Advocate

You can try 'release reference' then close all, but you'll probably have to use the occurences to check if the part/assembly exists in the main assembly

Dim oADoc As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oADoc.AllReferencedDocuments

	If oADoc.ComponentDefinition.Occurrences.AllLeafOccurrences(oRefDoc.ComponentDefinition).Count = 0 Then Continue For
	'or
	If oADoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc.ComponentDefinition).Count = 0 Then Continue For
	'	oRefDoc.ReleaseReference()
Next
'ThisApplication.Documents.CloseAll(True)
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Using the AllReferencedOccurrences property is likely your best bet for filtering out referenced documents that are not represented in your assembly as component occurrences.  However, you most likely will not be able to release the reference to that document, or truly close it, as long as your assembly remains open.  However, keep in mind that if every reference to a specific document in an assembly is suppressed, that will unload that document from Inventor's memory.  And when that it the case, they will not show-up in that 'AllReferencedDocuments' collection.  The one referenced document is in that collection because its parameters have been 'derived' into one of the other parts in your assembly.  I am not 100% sure if you can suppress that reference or not, but it might be possible.

PartComponentDefinition.ReferenceComponents 

ReferenceComponents 

ReferenceComponents.DerivedPartComponents 

DerivedPartComponents 

DerivedPartComponent 

DerivedPartComponent.SuppressLinkToFile 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)