Message 1 of 2
iLogic Rule to Resolve Broken Links in Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am having trouble using iLogic to Resolving broken links in a drawing file. I have a code that works but only half way. The first pic is before i run the rule and the second pic is what happens after i run the rule. The rule fixes the broken link to the part, but the drawing views are not fixed. When i save and close the part and then reopen it, the drawing views fix them self.
I would like to have help fixing my code so that it also solves the drawing views.
Sub Main() Dim oDrawDoc As DrawingDocument = ThisDoc.Document Dim oApp As Inventor.Application = ThisApplication Dim drawingFolder As String = System.IO.Path.GetDirectoryName(oDrawDoc.FullFileName) Dim drawingBaseName As String = System.IO.Path.GetFileNameWithoutExtension(oDrawDoc.FullFileName) Dim oFileDescriptors = oDrawDoc.File.ReferencedFileDescriptors Dim targetPart As String = System.IO.Path.Combine(drawingFolder, drawingBaseName & ".ipt") Dim targetAsm As String = System.IO.Path.Combine(drawingFolder, drawingBaseName & ".iam") Dim newModelPath As String = "" Dim updatedRefs As New List(Of String) Dim failedRefs As New List(Of String) Dim skippedRefs As New List(Of String) ' ---- Step 1: Fix file references ---- For Each oFD As FileDescriptor In oFileDescriptors Dim refPath As String = oFD.FullFileName Dim refFolder As String = System.IO.Path.GetDirectoryName(refPath) Dim refFileName As String = System.IO.Path.GetFileNameWithoutExtension(refPath) ' Replace if folder is different OR file name does not match drawing base name If String.Compare(refFolder, drawingFolder, True) <> 0 OrElse _ String.Compare(refFileName, drawingBaseName, True) <> 0 Then If System.IO.File.Exists(targetPart) Then oFD.ReplaceReference(targetPart) newModelPath = targetPart updatedRefs.Add(oFD.FullFileName & " → " & targetPart) ElseIf System.IO.File.Exists(targetAsm) Then oFD.ReplaceReference(targetAsm) newModelPath = targetAsm updatedRefs.Add(oFD.FullFileName & " → " & targetAsm) Else failedRefs.Add(oFD.FullFileName & " (Tried: " & targetPart & " and " & targetAsm & ")") End If Else skippedRefs.Add(refPath) End If Next ' ✅ Update all sheets if references were changed If updatedRefs.Count > 0 Then For Each oSheet As Sheet In oDrawDoc.Sheets oSheet.Update() Next End If ' ---- Final document update ---- If updatedRefs.Count > 0 Then oDrawDoc.Update() ' ---- Summary message ---- Dim msg As String = "" If updatedRefs.Count > 0 Then msg &= "✅ Updated file references:" & vbCrLf & String.Join(vbCrLf, updatedRefs) & vbCrLf & vbCrLf End If If failedRefs.Count > 0 Then msg &= "❌ Failed to find replacements:" & vbCrLf & String.Join(vbCrLf, failedRefs) & vbCrLf & vbCrLf End If If skippedRefs.Count > 0 Then msg &= "ℹ️ Already in correct folder:" & vbCrLf & String.Join(vbCrLf, skippedRefs) End If If msg = "" Then msg = "No references found." MessageBox.Show(msg, "Reference & View Replacement Summary") End Sub