Replace iLogic Rule in all parts and assemblies

steven.coxVCM6J
Advocate
Advocate

Replace iLogic Rule in all parts and assemblies

steven.coxVCM6J
Advocate
Advocate

Hi all,

 

Is there a way to replace an iLogic rule in multiple parts and assemblies at once?  I have updated my templates but the old rule is still in a LOT of parts created before the new rule.

 

Any ideas?

 

Thanks, Steven

0 Likes
Reply
Accepted solutions (1)
871 Views
5 Replies
Replies (5)

Curtis_Waguespack
Consultant
Consultant

Hi @steven.coxVCM6J 

 

There is, but when you reach this point in your iLogic travels, it's probably best to take a new route.

 

Would it make sense to delete the internal rules in all these files and replace them with a single external rule? This could be set up with an automatic rule to delete the internal rules as the files are opened, or batch process them.

 

That's just food for thought, but below is the code and a simple batch file tool to do what you asked about.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Curtis_Waguespack
Consultant
Consultant

Hi @steven.coxVCM6J ,

 

For updating the internal rules:

 

Attached is an Inventor 2022 file that will allow you to run a rule called "Update Rule Text ***" on a selected batch of files. That rule is the same code posted here.

 

You could also just set this rule up to run the code below on an event trigger, such as "On Open".

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'name of rule to replace
sRuleName = "Test Rule"
sRuleTextFile = "C:\Temp\New Rule.txt"

Try
	oRead = System.IO.File.OpenText(sRuleTextFile)
	oRuleText = oRead.ReadToEnd()
	oRead.Close()

Catch
	Logger.Info("File not found: " & sRuleTextFile)
	Exit Sub
End Try


Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument '<- important that this is activeEditDoc for the batch tool

' Define the iLogic addin
Dim iLogicAddIn As ApplicationAddIn = _
   ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
   
' Get the iLogic automation object
Dim iLogic As Object = iLogicAddIn.Automation

'get collection of rules
Dim ruleName As String
Dim rules As Object
rules = iLogicVb.Automation.Rules(oDoc)

'make sure there are rules in the file
If rules Is Nothing Then
	Return 'exit rule
End If

'set rule text
For Each iRule As iLogicRule In rules
	If iRule.Name = sRuleName
		iRule.Text = oRuleText
	End If
Next

 

steven.coxVCM6J
Advocate
Advocate

Thanks Curtis!

 

I am assuming this will work with Inventor 2023 as well.  I will try this in the next few days as I get caught up on this drawing set.

 

Thanks so much for your help!!

 

Steven

bradeneuropeArthur
Mentor
Mentor

as @Curtis_Waguespack Mentioned and 

Or even you could think about creating an addin!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @steven.coxVCM6J ,

 

Yep, it'll work with 2022 and beyond, I just saved it as a 2022 file because that's oldest version I have loaded at the moment.

 

I just updated the batch file to include the code below, that is a rule to delete a rule of a certain name, as well. In case you decide that deleting the internal rules and using a single external rule is the better option.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'name of rule to delete
sRuleName = "Test Rule"

Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument '<- important that this is activeEditDoc for the batch tool

' Define the iLogic addin
Dim iLogicAddIn As ApplicationAddIn = _
ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")

' Get the iLogic automation object
Dim iLogic As Object = iLogicAddIn.Automation

'get collection of rules
Dim ruleName As String
Dim rules As Object
rules = iLogicVb.Automation.Rules(oDoc)

'make sure there are rules in the file
If rules Is Nothing Then
	Return 'exit rule
End If

'delete rule
For Each iRule As iLogicRule In rules
	If iRule.Name = sRuleName
		iLogicAddIn.Automation.DeleteRule(oDoc, iRule.Name)
	End If
Next