Message 1 of 2
Rule to backup all rules in active document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have created a rule, which every rule in active document saves as Word document.
A lot of times it happens that when recoding rule, it does not work so you have to return to old code (or compare it with old code). This rule makes backup creation really easy.
I think that this would be interesting for others. Let me know if you used this rule and if it helped you 🙂
Imports System.Threading.Tasks
Class Create_backup
'Rule, which for each rule in active document copies the rule code and saves it as word document (by rule name) in defined folder
Sub Main()
Dim iLogic As New Object
iLogic = GetiLogicAddin(ThisApplication) 'Calls function defined bellow
If (iLogic Is Nothing) Then Exit Sub 'If ilogic is not returned, exit sub
Dim oDoc As Document
Dim Text2 As String
Dim RuleName As String
oDoc = ThisApplication.ActiveDocument
Dim ruleCol As System.Collections.IEnumerable = iLogic.Automation.Rules(oDoc) 'gets ilogic rules in document
i = 0
Dim objWord
Dim objDoc
objWord = CreateObject("Word.Application") 'create Word object (opens word)
For Each iLogRule As iLogicRule In ruleCol
objDoc = objWord.Documents.Add 'create new Word document
Text2 = iLogRule.Text 'save rule code to variable Text2
objDoc.Content.InsertAfter (Text:=Text2) 'insert Text2 to word
RuleName = iLogRule.Name 'get ilogic rule name
objDoc.SaveAs("C:\Rules\" & RuleName) 'save word document which contains rule code
objDoc.close 'close word document
Next
objWord.Visible = True 'make word visible
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object 'function to get reference of iLogic object
addIns = oApplication.ApplicationAddIns
Dim addIn As ApplicationAddIn
addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") 'load ilogic addin
If (addIn Is Nothing) Then Exit Function 'if ilogic addin not found, exit function
addIn.Activate 'activate ilogic addin
Return addIn
Exit Function
NotFound:
End Function
End Class