@jgomis.ext
And here is a partial example of the process I was talking about with storing the 'old' FullFileName, and the 'new' FullFileName pairs in a 2-factor list, for use later, to avoid all of the user parameter stuff. This is not a complete working sample. It is just showing the main parts, because I have no idea how all of your existing code is currently laid out (and I don't really want to 😅), so I am attempting to show you how to modify any code you may already have to adapt this process into it. I prepared two iLogic rules in this example. The first rule represents your current code for copying and replacing stuff in your assembly, but does not include any code for that process, just code for the process I'm talking about. The second rule represents the one that would be used to replace all of the model file references in it, based on the data you gathered in the first rule. The first rule gathers the needed data into a dictionary, then sends that data to the second rule. The second rule looks for that data when it starts, and if received, it will start to loop through that data to replace file references in the drawing. The second rule currently does not know what to do if it does not receive that list of data at the beginning, so it will just exit the rule if that happens.
Here is the first rule example:
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
'create this dictionary 'before' the loop, not inside of the loop
Dim oFileRefPairs As New Dictionary(Of String, String)
'your other code to copy & replace components or file references in the assembly
'as you determine what the 'old' FullFileName was, and the 'new' FullFileName will be
'store them in this dictionary, like this:
If oFileRefPairs.Keys.Contains(sOldFullFileName) = False Then
oFileRefPairs.Add(sOldFullFileName, sNewFullFileName)
End If
'then when done filling that dictionary with the file pairs, send that dictionary to another rule
'the other rule you sent it to will recieve it, then use it to process the drawing by looping through its contents
Dim oDrawingFile As String = System.IO.Path.ChangeExtension(oADoc.FullFileName, ".idw") 'or ".dwg"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingFile, False) 'False = invisible
Dim sOtherRuleName As String = "Replace Drawing Model References"
Dim oArgs As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oArgs.Add("Target Document", oDDoc)
oArgs.Add("File Reference Pairs", oFileRefPairs)
iLogicVb.Automation.RunExternalRuleWithArguments(oDDoc, sOtherRuleName, oArgs)
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
'If oDDoc.Dirty Then oDDoc.Save2(False)
...and below is the second rule example:
Dim oDDoc As DrawingDocument = Nothing
If RuleArguments.Exists("Target Document") Then
oDDoc = RuleArguments.Value("Target Document")
Else
oDDoc = ThisDoc.Document
End If
Dim oFileRefPairs As Dictionary(Of String, String)
If RuleArguments.Exists("File Reference Pairs") Then
oFileRefPairs = RuleArguments.Value("File Reference Pairs")
Else
'NO LIST OF FILE PAIRS WAS RECEIVED
'oFileRefPairs = New Dictionary(Of String, String) 'will be empty
'<!!! you may have to do things differently if this is the case !!!>
Exit Sub
End If
Dim oFDs As FileDescriptorsEnumerator = oDDoc.File.ReferencedFileDescriptors
If oFDs.Count = 0 Then Exit Sub 'no file references to process
For Each oFD As FileDescriptor In oFDs
If oFD.ReferenceMissing Or oFD.ReferenceDisabled Then Continue For
For Each oFileRefPair In oFileRefPairs
If oFD.FullFileName = oFileRefPair.Key Then 'Key is 'old' FullFileName
Try
oFD.ReplaceReference(oFileRefPair.Value) 'Value is 'new' FullFileName
Catch
'what to do when that fails, maybe Logger.Error()
End Try
End If
Next 'oFileRefPair
Next 'oFD
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
'If oDDoc.Dirty Then oDDoc.Save2(False)
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)