Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multi Delete or Change Linked Excel from all parts using Ilogic Rule

1 REPLY 1
Reply
Message 1 of 2
filipapinto
423 Views, 1 Reply

Multi Delete or Change Linked Excel from all parts using Ilogic Rule

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

Labels (1)
1 REPLY 1
Message 2 of 2
WCrihfield
in reply to: filipapinto

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

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report