Hi,
I want to create a rule to delete or change the excel file linked in all parts. Run it on the top assembly, and then automatically it will delete/change the linked file (Excel) in every single part and sub assemblys.
I believe de code is this:
changeOK = GoExcel.ChangeSourceOfLinked(partialOldName, newName)
*I don't understand nothing aboud coding...
Thank you
I've never tried it before, but you can try this iLogic rule.
It is only designed to replace the source Excel file (assumes one exists), and doesn't try to delete it.
You didn't specify what conditions you want to check for when you would prefer to delete it instead of replace it.
Here's the iLogic code:
(Lines starting with an apostrophe (') are just comments, and don't effect the result of the rule.)
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
oADef.re
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
'checking its type
If oRefDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Continue For 'skip to the next oRefDoc
End If
'make this the 'active' document temporarily,
'so the following method will hopefully work on it, instead of the main assembly
oRefDoc.Activate
'if you specify an empty string for the first name, it will replace any reference that is currently there
'replace the second name with the path and name of your new excel file.
Dim oChanged As Boolean = GoExcel.ChangeSourceOfLinked("", "C:\Temp\NewExelReference.xlsx")
'it will be True if it succeeded
If oChanged = False Then
MsgBox("It failed to change the source Excel file for:" & vbCrLf & _
oRefDoc.FullFileName,vbOKOnly+vbInformation,"")
End If
Next
There is likely a better way to check for this link, but since I rarely attempt to manage it by code, I haven't seen another way yet.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you have time, please... Vote For My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.