Message 1 of 4
How to call Global Rule from a Macro?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to create a macro for drawings that simply advances or retreats the current drawing by 1 sheet. I found this iLogic code to do that, courtesy of nbonnett-murphy :
Prev sheet rule:
Sub main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
i = i + 1
If oSheetName = oSheet.name Then
If i > 1 Then
oDrawDoc.Sheets.Item(i - 1).Activate
Else
MsgBox "Reached First Sheet"
End If
End If
Next
End Sub
Next sheet rule:
Sub main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.Name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
i = i + 1
If oSheetName = oSheet.Name Then
If i < oSheetCount Then
oDrawDoc.Sheets.Item(i + 1).Activate
Else
MsgBox ("Reached Last Sheet")
End If
End If
Next
End Sub
I then found this macro code to call the rules courtesy of MJDeck :
Sub RuniLogicRule()
Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim ruleName As String
ruleName = "Rule0"
Dim rule As Object
Set rule = iLogicAuto.GetRule(doc, "Rule0")
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If
Dim i As Integer
i = iLogicAuto.RunRuleDirect(rule)
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function
This works great for the document that the rules belong to, but the macro can't find the rules when it is used in another document. I am wondering, how can I change my macro code to search for a global rule stored on my C drive? Is this even possible? I would love to have prev/next sheet hotkeys available in any drawing I happen to open.
Your help is appreciated!