Actually, that example did not attempt to remove the link from the main assembly itself, just its referenced documents. Below is an alternate version of that code in which the code for the primary purpose of the rule has been placed out into a separate custom Sub routine, so that the same code can be ran on the main assembly itself first, then on each of the referenced documents also. The optional second input in the custom sub routine named "sRefFullFileName" is for if you want to specify the full file name (path, file name, & file extension) of the 'master part' that you are expecting the parameters to be linked to. If supplied, it will only attempt to break that one specific link, and no others. If not specified, it will attempt to break the link to all parameters that are derived from parts. Currently, this should not attempt to break the link to parameters that are linked to an Excel file, but it could be expanded further to include that functionality also.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting rule.", vbCritical, "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
BreakLinkToDerivedPartParams(oADoc)
Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
For Each oRefDoc As Document In oAllRefDocs
BreakLinkToDerivedPartParams(oRefDoc)
Next 'oRefDoc
If oADoc.RequiresUpdate Then oADoc.Update2(True)
'If oADoc.Dirty Then oADoc.Save2(True)
End Sub
Sub BreakLinkToDerivedPartParams(oDoc As Inventor.Document, Optional sRefFullFileName As String = vbNullString)
If oDoc.IsModifiable = False Then Exit Sub
Dim oParams As Inventor.Parameters = Nothing
Try : oParams = oDoc.ComponentDefinition.Parameters : Catch : Exit Sub : End Try
If oParams Is Nothing Then Exit Sub
Dim oDPTables As DerivedParameterTables = oParams.DerivedParameterTables
If oDPTables.Count = 0 Then Exit Sub
For Each oDPTable As DerivedParameterTable In oDPTables
If oDPTable.HasReferenceComponent = True Then 'result of derived part
Dim oRC As ReferenceComponent = oDPTable.ReferenceComponent
If oRC.LinkedToFile Then
If String.IsNullOrEmpty(sRefFullFileName) Then
Try : oRC.BreakLinkToFile : Catch : End Try
Else
Dim sFFN As String = oRC.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName
If sFFN = sRefFullFileName Then Try : oRC.BreakLinkToFile : Catch : End Try
End If
End If
End If
Next 'oDPTable
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)