Inventor 2015 - iLogic –Delete All iLogic Rules in Entire Assembly

Zen Admin
Zen Admin

by Luke Davenport

Problem:

You’ve got a clever iLogic configurator assembly (or part) and you are using it to generate new assemblies on demand. But how can you lock down the configured assembly so that the ‘As Built’ state of the file is maintained?

 

Solution:

Well – this is a big topic. If you are worried about file security your best bet is to get Vault installed and start locking released files properly to prevent edits. However for my loyal readers without the benefit of Vault – it may be beneficial to have the option of ‘stripping’ all the iLogic out of the assembly once generated, thus making edits not quite so simple.

 

So with that in mind the iLogic code below will delete every iLogic rule in every component in the assembly, including rules in the top level assembly itself. It will however, preserve any rules called ‘Delete All Rules’. This exception means that you can name this rule ‘Delete All Rules’ when you paste it into the top-level assembly, and ensure that it won’t delete itself when it runs, causing a lapse in the space-time continuum.

 

Note: This rule will still work if you paste into a single part file and run it, but of course make sure you still name the rule ‘Delete All Rules’.

 

Important:

Cadline won’t take responsibility for accidental loss of iLogic rules as a result of using this code.

Backup ALL part files (not just the top-level assembly) before using.

 

If you use this code on an Inventor file without backing it up first please don’t come running to me!

 

Note: Some code appropriated from J.D.Kriek on the Inventor forum here – http://autode.sk/1vkEBzy many thanks.

 

' Luke Davenport 2014

' Start of iLogic code..................................................................

 

Sub Main()

 

Auto = iLogicVb.Automation

Dim iLogicAuto As Object = Auto

Dim oDoc As Document = ThisApplication.ActiveDocument

Dim RuleColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

 

Response = MessageBox.Show("Delete all iLogic rules in ALL components in this assembly?", _

"Cadline iLogic",MessageBoxButtons.YesNo,MessageBoxIcon.Stop,MessageBoxDefaultButton.Button2)

If Response = vbNo Then

Return

End If

 

DoubleCheck = MessageBox.Show("Seriously?", _

"Cadline iLogic",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)

If DoubleCheck = vbNo Then

Return

End If

 

' Build collection of rules

RuleColl = BuildRuleColl(oDoc, RuleColl, iLogicAuto)

 

' Delete all rules in this document

Call DeleteAllRules(oDoc, RuleColl, iLogicAuto)

 

' Loop through all referenced docs in assembly

For Each oSubDoc As Document In oDoc.AllReferencedDocuments

    RuleColl.Clear

    ' Build collection of rules

    RuleColl = BuildRuleColl(oSubDoc, RuleColl, iLogicAuto)

    ' Delete all rules in this document

    Call DeleteAllRules(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

 

Sub DeleteAllRules(ByRef Doc As Document, _

                   ByRef RuleColl As ObjectCollection, _

                   ByVal iLogicAuto As Object)

   

For i = RuleColl.Count To 1 Step -1

    Name = RuleColl.Item(i).Name

    If Not Name = "Delete All Rules" Then

        Try

            iLogicAuto.DeleteRule(Doc, Name)

        Catch

            MsgBox("Could not delete rule: " & Name & " in document " & Doc.Name)

        End Try

    End If

Next

 

End Sub

 

' End of iLogic code.................................................................

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.