iLogic rule to suppress all document rules

iLogic rule to suppress all document rules

Lewis.Young
Collaborator Collaborator
2,661 Views
10 Replies
Message 1 of 11

iLogic rule to suppress all document rules

Lewis.Young
Collaborator
Collaborator

Hi All,

 

Does anybody have a working iLogic code that when ran externally, will iterate through every internal rule in a document and suppress them?

I know you can do this by explicitly naming each rule, but in this case that won't suffice

 

After looking through the API object model im starting to think this isn't possible...

 

Lewis Young

Windows 7 x64 - 32GB Ram
Intel Xeon E5-1620 v2 @ 3.70GHz
nVidia Quadro M2000 - 4GB
Inventor Professional 2017.3
Vault Basic 2017
3ds Max 2018

 

0 Likes
Accepted solutions (1)
2,662 Views
10 Replies
Replies (10)
Message 2 of 11

philip1009
Advisor
Advisor

What's the method for suppressing iLogic rules by name?

0 Likes
Message 3 of 11

Lewis.Young
Collaborator
Collaborator

Hi Philip,

 

The rule i use for suppressing by name is as follows:

 

SyntaxEditor Code Snippet

AutoRulesList = New String() {"Rule1","Rule2","Rule3"}

For Each rulename In AutoRulesList

    iLogicVb.Automation.GetRule(ThisDoc.Document, rulename).IsActive = False

Next rulename

On the first line you have to specify the rules, in this case rules 1, 2 and 3.

I'm just trying to find a way where i don't have to specify the names.

 

Lewis Young
Windows 7 x64 - 32GB Ram
Intel Xeon E5-1620 v2 @ 3.70GHz
nVidia Quadro M2000 - 4GB
Inventor Professional 2017.3
Vault Basic 2017
3ds Max 2018

 

0 Likes
Message 4 of 11

philip1009
Advisor
Advisor

I found a site that deletes all rules in an assembly and all referenced parts and assemblies: https://www.cadlinecommunity.co.uk/hc/en-us/articles/202020531-Inventor-2015-iLogic-Delete-All-iLogi...

 

I whittled down the code for getting the list of rules in a collection to peruse, you'd just have to apply your suppress code instead of the delete code:

SyntaxEditor Code Snippet

Sub Main()
Auto = iLogicVb.Automation
Dim iLogicAuto As Object = Auto
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim RuleColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

'This command peruses rules for Top Assy
RuleColl = BuildRuleColl(oDoc, RuleColl, iLogicAuto)

'This Loop peruses rules for All Referenced Parts and Assys
For Each oSubDoc As Document In oDoc.AllReferencedDocuments
	RuleColl.Clear
	RuleColl = BuildRuleColl(oSubDoc, RuleColl, iLogicAuto)
Next
End Sub

Function BuildRuleColl(ByVal Doc As Document, ByRef RuleColl As ObjectCollection, ByVal iLogicAuto As Object) As ObjectCollection
	Dim ruleName As String
	Dim rules As Object = iLogicAuto.rules(Doc)
	If Not (rules Is Nothing) Then
		For Each rule In rules
			RuleColl.Add(rule)
		Next
	End If
	Return RuleColl
End Function

Hopefully this works out the way you want it.  Make sure to test this on some dummy files or copies of the original files so you don't do major damage.

0 Likes
Message 5 of 11

lmc.engineering
Advocate
Advocate
Accepted solution

Hi @Lewis.Young

 

Try this

 

Version:1.0 StartHTML:00000145 EndHTML:00004412 StartFragment:00000294 EndFragment:00004380 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

Sub Main()
    Dim iLogic As Object
    iLogic = GetiLogicAddin(ThisApplication)
    If (iLogic Is Nothing) Then Exit Sub
    Dim doc As Document
    doc = ThisApplication.ActiveDocument
    iLogicAutomation = iLogic.Automation
	Dim ruleCol As System.Collections.IEnumerable = iLogicAutomation.Rules(doc)
	For Each iLogRule As iLogicRule In ruleCol
	'MessageBox.Show(iLogRule.Name, "Title")
	iLogRule.IsActive = False
	Next
End Sub

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    addIns = oApplication.ApplicationAddIns
    Dim addIn As ApplicationAddIn
    addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Return addIn
    Exit Function
    NotFound:
End Function
Message 6 of 11

Lewis.Young
Collaborator
Collaborator

Nice one mate, works perfectly!

 

Lewis Young
Windows 7 x64 - 32GB Ram
Intel Xeon E5-1620 v2 @ 3.70GHz
nVidia Quadro M2000 - 4GB
Inventor Professional 2017.3
Vault Basic 2017
3ds Max 2018

0 Likes
Message 7 of 11

gregor.leban
Enthusiast
Enthusiast

Hello,

 

is there a rule, to also suppress all sub-assembly rules?

0 Likes
Message 8 of 11

lmc.engineering
Advocate
Advocate

Hi @gregor.leban 

 

I've moved the main method of the code to it's own function and am calling it from a loop through all referenced components in the assembly; this way we can call it on the main assembly and it's components.

Sub Main()
    Dim iLogic As Object
    iLogic = GetiLogicAddin(ThisApplication)
    If (iLogic Is Nothing) Then Exit Sub
		
    Dim oAsmDoc As AssemblyDocument
    oAsmDoc = ThisApplication.ActiveDocument
	
	iLogicAutomation = iLogic.Automation
	
	'Suppress all main assembly rules
	Call SuppressRules(oAsmDoc, iLogicAutomation)
	
	'Suppress all component rules
	For Each refDoc As Document In oAsmDoc.AllReferencedDocuments
		Call SuppressRules(refDoc,iLogicAutomation)
	Next	
End Sub

Private Function SuppressRules(Doc As Document,iLogicAutomation As Object)
	Dim ruleCol As System.Collections.IEnumerable = iLogicAutomation.Rules(Doc)
		For Each iLogRule As iLogicRule In ruleCol
		iLogRule.IsActive = False
		Next
Return Nothing
End Function

Private Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    addIns = oApplication.ApplicationAddIns
    Dim addIn As ApplicationAddIn
    addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Return addIn
End Function

 

0 Likes
Message 9 of 11

gregor.leban
Enthusiast
Enthusiast

hi,
this code suppress assembly, but not sub-assembly.
And then I get an error:

Object reference not set to an instance of an object.

detail info of error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at ThisRule.SuppressRules(Document Doc, Object iLogicAutomation)
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 10 of 11

lmc.engineering
Advocate
Advocate

Sorry, that's my bad. I believe this is because some of your parts don't have rules in, and as such throws an error when attempting to suppress something that isn't there. The following should fix the issue.

 

Sub Main()
    Dim iLogic As Object
    iLogic = GetiLogicAddin(ThisApplication)
    If (iLogic Is Nothing) Then Exit Sub
		
    Dim oAsmDoc As AssemblyDocument
    oAsmDoc = ThisApplication.ActiveDocument
	
	iLogicAutomation = iLogic.Automation
	
	'Suppress all main assembly rules
	Call SuppressRules(oAsmDoc, iLogicAutomation)
	
	'Suppress all component rules
	For Each refDoc As Document In oAsmDoc.AllReferencedDocuments
		Call SuppressRules(refDoc,iLogicAutomation)
	Next	
End Sub

Private Function SuppressRules(Doc As Document,iLogicAutomation As Object)
	Dim ruleCol As System.Collections.IEnumerable = iLogicAutomation.Rules(Doc)
	If Not ruleCol Is Nothing Then 
		For Each iLogRule As iLogicRule In ruleCol
		iLogRule.IsActive = False
		Next
	End If
Return Nothing
End Function

Private Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    addIns = oApplication.ApplicationAddIns
    Dim addIn As ApplicationAddIn
    addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Return addIn
End Function
Message 11 of 11

gregor.leban
Enthusiast
Enthusiast

jeeej, it works!
Thank you!

0 Likes