How to tell if an assembly is missing file references via API/iLogic

How to tell if an assembly is missing file references via API/iLogic

DRoam
Mentor Mentor
2,513 Views
9 Replies
Message 1 of 10

How to tell if an assembly is missing file references via API/iLogic

DRoam
Mentor
Mentor

When we open an assembly file with missing references, Inventor displays the question mark to the left of the file's name in the browser tree. I'm trying to figure out how to determine via iLogic/the API whether a document is in this "unresolved references" state. I don't really care about any missing "imported AutoCAD" references or anything like that, I only want to know if the assembly is missing references that would prevent the BOM from opening.

 

The best way I've come up with is to use a function like below to recurse through all file references and check if any of them are missing, and if so check if they're component (part or assembly) files:

 

Sub Main()
	MsgBox("Is missing references: " & IsMissingReferencesRecursive(ThisDoc.Document.File.ReferencedFileDescriptors))
End Sub

Function IsMissingReferencesRecursive(fileDescriptors As FileDescriptorsEnumerator) As Boolean For Each refFileDesc As FileDescriptor In fileDescriptors If refFileDesc.ReferenceMissing Then If refFileDesc.ReferencedFileType = FileTypeEnum.kAssemblyFileType OrElse refFileDesc.ReferencedFileType = FileTypeEnum.kPartFileType Then Return True End If Else If IsMissingReferencesRecursive(refFileDesc.ReferencedFile.ReferencedFileDescriptors) Then Return True End If Next End Function

 

However, I've run into a snag. The "ReferenceMissing" property always returns True for Substitute Level of Details. And I can't figure out a way to determine if a FileDescriptor is for a Substitute LOD. If I could, I would just ignore it.

 

But I'm hoping there's a simpler way. Is there a built-in property that returns whether an assembly is missing references? I couldn't find one but I'm hoping I'm overlooking it.

 

Or at least a simpler/more reliable way than the one I'm using...

 

I appreciate any suggestions.

0 Likes
2,514 Views
9 Replies
Replies (9)
Message 2 of 10

DRoam
Mentor
Mentor

By the way, @MjDeck, I definitely think there's a bug with the "ReferenceMissing" property for Substitute LODs. It always returns true even if the file exists. I attached a sample assembly that demonstrates. Save both files to your Desktop and then run Rule0 in Assembly1.iam to see the issue in action. "ReferenceMissing" returns true but the file does exist at the expected location.

0 Likes
Message 3 of 10

llorden4
Collaborator
Collaborator

I'm interested in this as well, I've attempted similar health check for errors in parts/assemblies but my testing results show that iLogic just fails to run whenever there is any type of "Wizard Doctor" activation.

 

I hope you share you solution if you find it.

Autodesk Inventor Certified Professional
0 Likes
Message 4 of 10

MjDeck
Autodesk
Autodesk

The documentation for FileDescriptor.ReferenceMissing says that "missing" means either unresolved or suppressed. I think a substitute LOD would qualify as "suppressed" as long as it's not activated. The system doesn't look for the file until the LOD is activated.

I'm not sure what the best method is for finding unresolved file references. Here's a straightforward approach that checks the status of the assembly node in the browser. This won't work if the current language is not English, but strings for other languages could easily be added. Another limitation: it won't work on Inventor Server. We should probably add an API property directly on the Document or AssemblyDocument object to check this.

Dim assemDoc As AssemblyDocument = ThisDoc.Document
Dim oPane As BrowserPane = assemDoc.BrowserPanes("AmBrowserArrangement")
Dim node = oPane.TopNode
Dim hasUnresolved As Boolean = node.BrowserNodeDefinition.StateIconToolTipText = "Unresolved"
Logger.Info("hasUnresolved = {0}", hasUnresolved)
'Logger.Info("Node label: {0}, {1}", node.BrowserNodeDefinition.Label, node.BrowserNodeDefinition.StateIconToolTipText)

 

Here's another method, going through the ComponentOccurrences. This might be all you need to ensure that the BOM editor will work.

Sub Main
	Dim assemDoc As AssemblyDocument = ThisDoc.Document
	Dim anyUnresolved = ContainsUnresolvedFile(assemDoc.ComponentDefinition.Occurrences)
	Logger.Info("anyUnresolved = {0}", anyUnresolved)
End Sub

Private _checkedDocs As New HashSet(Of String)

Function ContainsUnresolvedFile(occurrences As ComponentOccurrences) As Boolean
	For Each occ As ComponentOccurrence In occurrences
		If Not (occ.Suppressed OrElse occ.ReferencedDocumentDescriptor Is Nothing) Then
			If occ.ReferencedDocumentDescriptor.ReferenceMissing Then
				Return True
			End If
			Dim fileDocName = occ.ReferencedDocumentDescriptor.FullDocumentName
			If Not _checkedDocs.Contains(fileDocName) Then
				If ContainsUnresolvedFile(occ.SubOccurrences) Then
					Return True
				End If
				_checkedDocs.Add(fileDocName)
			End If
		End If
	Next
	Return False
End Function

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 10

Raider_71
Collaborator
Collaborator

I use this which works quite well. It also checks for model suppression...

 

Dim MissingRefFound As Boolean = False
Private Sub BtnCheckFileRefs_Click(sender As Object, e As EventArgs) Handles BtnCheckFileRefs.Click

MissingRefFound = False

        CheckMissingDocDescriptors(oAssyDoc)
        If MissingRefFound Then
            MessageBox.Show("Missing ref found")
        End If
End Sub

Sub CheckMissingDocDescriptors(oAssyDoc As Inventor.Document)

        Dim oRefDoc As Inventor.DocumentDescriptor

        For Each oRefDoc In oAssyDoc.ReferencedDocumentDescriptors
            If MissingRefFound Then
                Exit Sub
            End If
            If Not oRefDoc.ReferenceSuppressed Then
                If oRefDoc.ReferenceMissing Then
                    MissingRefFound = True
                Else
                    CheckMissingDocDescriptors(oRefDoc.ReferencedDocument)
                End If
            End If
        Next

    End Sub

 

0 Likes
Message 6 of 10

SašoPrijatelj
Advocate
Advocate

Hello,

 

Is there a list of strings for "Unresolved" tooltip available for all different Inventor languages as checking BrowserNodeDefinition.StateIconToolTipText seems to be the most simple and reliable method to find out if an assembly is unresolved?

 

There really should be a simple API property on the assembly object to check this.

 

I had some hope with checking BrowserNodeDefinition.DisplayState but it also doesn't work according to adndevblog this post.

 

Thanks,

Sašo

-----------------------------------------------------------------------
AutoDXF - automatic flat pattern creation and batch export to DXF for Inventor

Please use "Accept as Solution" & give "Kudos" if this response helped you.
0 Likes
Message 7 of 10

llorden4
Collaborator
Collaborator

Here's a quick tip on what I've found to use that is working reliably for me....

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
	If oOcc.ReferencedDocumentDescriptor.ReferenceMissing Then
		'Occurrence reference is unresolved, do something here
	End If
Next
Autodesk Inventor Certified Professional
0 Likes
Message 8 of 10

Mehmet_Fatih_Turker
Advocate
Advocate

Hi all, Im trying to collect parts that are in state of missing referance in a list. While looping through assembly and sub-assemblies, program stucks at Weldment assembly by showing oOcc.Item(0) as "_Weldbead:1" like below and throws error "Error in occurrence 'xxxx.iam': Object reference not set to an instance of an object." 

 

Mehmet_Fatih_Turker_1-1743667763678.png

 

I tried empty weldment iam and did the same.

 

            If oOcc.ReferencedDocumentDescriptor.ReferenceMissing Then
                unresolvedParts.Add(oOcc.Name & " - Missing reference")
            Else

 

Found in chinese forum that

Mehmet_Fatih_Turker_2-1743668155160.png

 
İs there anyway to rectify this error ?

0 Likes
Message 9 of 10

llorden4
Collaborator
Collaborator

It's been a while since I played with this but I believe your mistake here is that your code is adding another occurrence of the unresolved item.  I believe the correct solution here is to use the component replace option instead, even if it's the same file.  Be sure that process includes verifying that the file and path is valid.

Autodesk Inventor Certified Professional
0 Likes
Message 10 of 10

WCrihfield
Mentor
Mentor

This maybe something else I commonly see also.  When you are dealing with weldment type assemblies, and iterating through component occurrences, you may encounter a component occurrence that essentially just represents the 'welds' within that weldment assembly, which does not have a reference to a document/file.  So, in those cases, after checking if the occurrence is suppressed, to avoid that possible error, I then filter for a few specific types of 'definitions' which are often problematic in some situations.  One of those is the 'virtual' type (VirtualComponentDefinition), which is for BOM purposes only, and does not point to a Document or File.  Another is the WeldsComponentDefinition, which is likely what you encountered in this case, representing the welds within that weldment type assembly who's definition type is the WeldmentComponentDefinition type.  That type of assembly also includes the Machining object, and the Preparations object, in addition to the Welds object, but those other two are not handled with their own 'definition' types, like the welds do.  The 'FlatPattern' object is also a type of ComponentDefinition of its own, but we don't encounter those in an assembly directly.

So, I often use lines of code similar to the following:

If oOcc.Suppressed Then Continue For

If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For

If TypeOf oOcc.Definition Is WeldsComponentDefinition Then Continue For

...if my following code is attempting to access and work with their referenced Document, or File objects.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)