Code:
Option ExplicitDim oApprenticeApp As ApprenticeServerComponent
Dim oIV As Inventor.Application
' Quelle vom Original
' https://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/td-p/3170614
' hier umgebaut auf Apprentice, dann auf Inventor
Sub Test_it_IV() 'Versuch Inventor selbst zu starten...
' -> hat in meinem Test funktioniert
Dim sFile As String, sRule As String, bExternalRule As Boolean
sFile = "U:\wtf\part.ipt" 'Dateiname hier
sRule = "Regel0" ' Name der Regel
bExternalRule = False 'Externe oder Interne iLogic-Regel?
'externe Regel nicht ausprobiert
'Start Inventor
Set oIV = CreateObject("Inventor.Application") 'Variable auf ModulEbene
'Document öffnen
Dim oDoc As Inventor.Document
Set oDoc = oIV.Documents.Open(sFile)
'Regel ausführen
Call RuniLogicIV(sRule, oDoc, bExternalRule)
'Aufräumen
Call oIV.Documents.CloseAll
Call oIV.Quit
Set oIV = Nothing
End Sub
Public Sub RuniLogicIV(ByVal RuleName As String, oDoc As Inventor.Document, Optional bExternal As Boolean = True)
'Kopie von "RuniLogic", jedoch mit Verw. von Inventor statt Apprentice
Dim iLogicAuto As Object
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(oIV)
If (iLogicAuto Is Nothing) Then MsgBox "hoppla!": Exit Sub
If bExternal Then
iLogicAuto.RunExternalRule oDoc, RuleName
Else
'internal Rule inside the document
iLogicAuto.RunRule oDoc, RuleName
End If
End Sub
Public Sub RuniLogic(ByVal RuleName As String, oDoc As ApprenticeServerDocument, Optional bExternal As Boolean = True)
Dim iLogicAuto As Object
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(oApprenticeApp)
If (iLogicAuto Is Nothing) Then MsgBox "hoppla!": Exit Sub
If bExternal Then
iLogicAuto.RunExternalRule oDoc, RuleName
Else
'internal Rule inside the document
iLogicAuto.RunRule oDoc, RuleName
End If
End Sub
'Function GetiLogicAddin(oApplication As ApprenticeServerComponent) As Object
Function GetiLogicAddin(oApplication As Object) As Object
'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}")
'Set addIn = oApplication.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") 'groß/klein -> egal!
If (addIn Is Nothing) Then Exit Function
addIn.Activate 'schlägt fehl bei Apprentice!?
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
MsgBox Err.Description, , Err.Number
End Function
Sub Test_it_Apprentice() 'Verwendung von IV-Apprentice
'-> funktioniert nicht, weil sich das iLogic-AddIn nicht starten lässt!
' (habe ich gelesen, dass iLogic nicht mit Apprentice läuft? kA)
' Apprentice hätte einen Geschwindigkeitsvorteil, weil keine Bedienoberfläche etc.
Dim sFile As String, sRule As String, bExternalRule As Boolean
sFile = "U:\wtf\part.ipt" 'Dateiname hier
sRule = "Regel0" ' Name of the Rule
bExternalRule = False 'Externe oder Interne iLogic-Regel?
'Start IV-Apprentice
Set oApprenticeApp = New ApprenticeServerComponent 'Variable auf ModulEbene
'Document öffnen
Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprenticeApp.Open(sFile)
'Regel ausführen
Call RuniLogic(sRule, oDoc, bExternalRule)
'Aufräumen
Set oApprenticeApp = Nothing
End Sub