Macro Runs - But not when Hot Key is used

Macro Runs - But not when Hot Key is used

RNDinov8r
Collaborator Collaborator
346 Views
1 Reply
Message 1 of 2

Macro Runs - But not when Hot Key is used

RNDinov8r
Collaborator
Collaborator

So, I used the code found here with super minor modifications: https://forums.autodesk.com/t5/inventor-customization/inventor-pro-2014-ilogic-assign-a-keystroke-to... and the method described in message 4 of 4 to set up my hotkey and create the "macro".

 

My iLogic Code works correctly (changes dim styles) and the macro runs correctly when I run it thru the macro menu under the Tools Tab. 

 

When I initially run the macro, I get this error

ExternalRuleNoExist.png

 

 

 

 

 

 

 

But if I manually run the rule once, I don't get the error when I run the macro.

Someone suggested changing:  iLogicAuto.RunExternalRule oDoc, RuleName to  iLogicAuto.RunRule oDoc, RuleName

but that had no effect.

 

Once I do get it working, I have an assigned Hot Key and it works as well.

 

This is the Module in my Main VB Project:

Public Sub HoleDimStyle() '<--- This is what you would tie to a button in a toolbar.

  RuniLogic "HoleDimeStyle" 'there was a type that is why it is Dime and not Dim...

End Sub

 
Public Sub RuniLogic(ByVal RuleName As String)
  Dim iLogicAuto As Object
  Dim oDoc As Document

  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If

  Set iLogicAuto = GetiLogicAddin(ThisApplication)
  If (iLogicAuto Is Nothing) Then Exit Sub

  iLogicAuto.RunExternalRule oDoc, RuleName
End Sub

 

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns

'Find the add-in you are looking for
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

I have verified multiple times, that external iLogicRule is loading correctly..i.e. it "exists" in the document before I run the macro. 

0 Likes
347 Views
1 Reply
Reply (1)
Message 2 of 2

TechInventor20
Advocate
Advocate

 

Sub HoleDimStyle()


Debug.Print "*Reset k factor* start!"

Dim RuleName As String
'**************Location of the Rule you want to use + rule name
RuleName = Inventor_zoeklocatie & "AuTTeK\Orginele bestanden\Reset_kfactor.iLogicVb" 'ilogic regel

'*****this lets the rule run
Dim Fname3 As String
Dim RuleName2 As String
Fname3 = ThisApplication.ActiveDocument.fullfilename
If Fname3 = "" Then
MsgBox "Document eerst opslaan"
Exit Sub
End If
Debug.Print Fname3

Call RunRule1(Fname3, RuleName)

'***** updaten *****
Line_update:
ThisApplication.ActiveView.Update
ThisApplication.ActiveDocument.Update

Debug.Print "*Reset k factor* EIND!"
End Sub

0 Likes