Hi @rbertoletti. Here is a similar iLogic rule routine you can try out. It deals with file references directly, instead of just assembly components. It is also recursive, so that it will step down to sub structure references as many times as is needed. This can be a tricky process though, so make sure that every file being referenced by the assembly has a copy file in that sub directory with the same name. It does seem a bit odd to have a whole folder full of files with the same exact names as other existing files. That usually causes problems, so the replacement files usually have slightly different file names. But then again we use one main project file for everything we do, instead of a different project file for every assembly, so it may not be an issue for you.
Here is the file references replacement code you can try out, if you want.
Sub Main
Dim oDoc As Document = ThisDoc.Document
If oDoc.FileSaveCounter = 0 Then Return 'can't access file, if no file exists yet
Dim oFDs As FileDescriptorsEnumerator = oDoc.File.ReferencedFileDescriptors
If oFDs.Count = 0 Then Return
sReplacementPath = ThisDoc.Path & "\LIBRARY\"
If System.IO.Directory.Exists(sReplacementPath) = False Then Return
sFileName = ThisDoc.FileName(False)
RecursivelyReplaceFileReferences(oFDs) 'run custom Sub routine
If oDoc.RequiresUpdate Then oDoc.Update2(True)
'If oDoc.Dirty Then oDoc.Save2(True)
MsgBox("This rule's work has finished.", vbInformation, "Job Is Done!")
End Sub
Dim sReplacementPath As String
Dim sFileName As String
Sub RecursivelyReplaceFileReferences(oFDs As FileDescriptorsEnumerator)
If oFDs Is Nothing OrElse oFDs.Count = 0 Then Return
For Each oFD As Inventor.FileDescriptor In oFDs
If oFD.ReferenceDisabled Or oFD.ReferenceMissing Then
Logger.Debug("ReferenceDisabled or ReferenceMissing, so skipping one.")
Continue For
End If
Dim sRefFileName As String = System.IO.Path.GetFileName(oFD.FullFileName) 'with extension
Dim sNewFFN As String = sReplacementPath & sFileName & "_" & sRefFileName
If System.IO.File.Exists(sNewFFN) = False Then
Logger.Debug("The following replacement file does not exist:" & vbCrLf & sNewFFN)
Continue For
End If
Dim oChildFDs As FileDescriptorsEnumerator = Nothing
If oFD.ReferencedFile IsNot Nothing Then
oChildFDs = oFD.ReferencedFile.ReferencedFileDescriptors
End If
Try : oFD.ReplaceReference(sNewFFN)
Catch e As Exception
Logger.Error("Error replacing:" & vbCrLf & oFD.FullFileName & vbCrLf & _
"with:" & vbCrLf & sNewFFN & vbCrLf & _
e.Message & vbCrLf & e.StackTrace & vbCrLf)
'Continue For
End Try
If oChildFDs IsNot Nothing AndAlso oChildFDs.Count > 0 Then
RecursivelyReplaceFileReferences(oChildFDs)
End If
Next 'oFD
End Sub
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)