Where is iLogicAutoTest.ivb ?

Where is iLogicAutoTest.ivb ?

CadUser46
Collaborator Collaborator
732 Views
4 Replies
Message 1 of 5

Where is iLogicAutoTest.ivb ?

CadUser46
Collaborator
Collaborator

I am actually trying to find out if i can create/import a ilogic rule into and existing document (to create a document rule) using VBA.  I have been on a merry journey but still cant find what im looking for.

 

API help does not find 'ilogic'.

There is nothing in the VBA library under ilogic.

I can find one post kind of along the lines of what i want. http://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/m-p/317061...

 

So started looking through help which points me to

http://help.autodesk.com/view/INVNTOR/2016/ENU/?guid=GUID-1DF09784-4ABD-4BA8-914B-3172866244EA

then

Users\Public\Documents\Autodesk\Inventor [version]\Samples\ iLogic Samples\API\iLogicAutoTest.ivb

then

C:\Users\Public\Documents\Autodesk\Inventor 2016\Samples\en-US\Where_are_my_Inventor_Sample_files.html

then

https://knowledge.autodesk.com/support/inventor-products/downloads/caas/downloads/content/inventor-s...

 

Still no iLogicAutoTest.ivb.

 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
733 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor

Hi, first of why would you want to copy the rule to the document when you can run it with VBA?

 

You can use VBA to create new rule in document, or...

you can copy all rules from existing "rule-template", even without VBA, using juts iLogic.

 

It will copy ALL rules from source document, all events that has been set for the rules will be copied as well.

See the example below.

 

Imports System.Collections.Generic

Sub Main()
	Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
' Check if the document is assembly
If Not oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Exit Sub
End If
Dim rules As Object rules = iLogicVb.Automation.rules(oDoc) Try ' Name of the copied rule is Info-1, so we'll first check if it exists For Each rule In rules If rule.Name = "Info-1" Then Exit Sub End If Next ' Delete old rules, that are replaced by the imported one iLogicVb.Automation.DeleteRule(oDoc, "Part Number") iLogicVb.Automation.DeleteRule(oDoc, "Vlastn") Catch End Try ' Source document from which the settings will be copied
' It's currently set just for assembly (.iam), but it can vary for all document types
Dim sourceDoc As Document = ThisApplication.Documents.Open("C:\SomePath\SourceDocument.iam", False) Try CopyEventsToDocuments(oDoc, sourceDoc) iProperties.Value("Custom", "Info-1") = 1 Catch ex As Exception MsgBox(ex.Message) Finally sourceDoc.Close End Try End Sub Private Const m_ourGuid As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}" Private savedEnabled As Boolean Public Sub CopyEventsToDocuments(ByVal oDoc As Document, ByVal sourceDoc As Document) Dim sourcePropSet As PropertySet = GetEventRulesPropertySet(sourceDoc) savedEnabled = True iLogicVb.Automation.RulesOnEventsEnabled = False Try Dim filename As String = oDoc.Fullfilename CopyEventsToDocument(sourcePropSet, fileName) Finally iLogicVb.Automation.RulesOnEventsEnabled = savedEnabled End Try End Sub Function GetEventRulesPropertySet(ByVal sourceDoc As Document) As PropertySet Try Return sourceDoc.PropertySets(m_ourGuid) Catch ex As Exception Return Nothing End Try End Function Sub CopyEventsToDocument(ByVal sourcePropSet As PropertySet, ByVal fileName As String) Dim doc As Document = FindOpenDocument(fileName) Dim openedHere As Boolean = False If (doc Is Nothing) Then doc = ThisApplication.Documents.Open(fileName, True) openedHere = True End If CopyEventsPropertySetToDocument(sourcePropSet, doc) iLogicVb.Automation.RulesOnEventsEnabled = savedEnabled Try doc.Save() Finally iLogicVb.Automation.RulesOnEventsEnabled = False End Try If (openedHere) Then doc.Close(True) End If End Sub Sub CopyEventsPropertySetToDocument(ByVal sourcePropSet As PropertySet, ByVal doc As Document) ' If an event-driven rules property set already exists, delete it. Dim oldPropSet As PropertySet = GetEventRulesPropertySet(doc) If (oldPropSet IsNot Nothing) Then oldPropSet.Delete() End If If (sourcePropSet Is Nothing OrElse sourcePropSet.Count = 0) Then Return Dim destPropSet As PropertySet = doc.PropertySets.Add("_iLogicEventsRules", m_ourGuid) For Each prop As Inventor.Property In sourcePropSet destPropSet.Add(prop.Value, prop.Name, prop.PropId) Next EnsureDocumentInterest(doc) End Sub Const iLogicId As String = "{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}" Sub EnsureDocumentInterest(ByVal doc As Document) If (ThisApplication.SoftwareVersion.Major < 15) Then Return ' Inventor 2010 or before If (DocumentHasiLogicInterest(doc)) Then Return Dim dataVersion As Integer = 20090512 Dim newInterest As DocumentInterest = doc.DocumentInterests.Add(iLogicId, "iLogic", DocumentInterestTypeEnum.kInterested, dataVersion, Nothing) End Sub Function DocumentHasiLogicInterest(ByVal doc As Document) As Boolean Dim interest As DocumentInterest = FindDocumentInterest(doc, iLogicId) If (interest IsNot Nothing) Then If (interest.InterestType = DocumentInterestTypeEnum.kInterested) Then Return True End If interest.Delete() End If Return False End Function Function FindDocumentInterest(ByVal doc As Document, ByVal clientId As String) As DocumentInterest For Each interest As DocumentInterest In doc.DocumentInterests If (String.Equals(interest.ClientId, clientId, StringComparison.OrdinalIgnoreCase)) Then Return interest End If Next Return Nothing End Function Function FindOpenDocument(ByVal fileName As String) As Document For Each doc As Document In ThisApplication.Documents If (String.Equals(doc.FullFileName, fileName, StringComparison.OrdinalIgnoreCase)) Then Return doc End If Next Return Nothing End Function
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 5

CadUser46
Collaborator
Collaborator

That'll take a minute to digest that, and i knew someone would ask.  I want to inject a new ilogic rule into an old document.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 4 of 5

CadUser46
Collaborator
Collaborator

Is iLogicVb part of the Autodesk Inventor Object Library?  Why cant i find anything when i search in the library?

 

Owner i just realised what you wrote. I cant use ilogic to update ilogic because it is not there in the first place, and you still cant deploy ilogic configuration paths across multiple physical locations.

 

The ilogic rule is in a template file.  I need VBA to get this rule, and inject into any document of my choosing. 

 

Can you reword some of that in VBA lingo?  I can do the rest, just dont know how to interact with ilogic via VBA. Hence my original question about where is the tutorial file?


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 5 of 5

Owner2229
Advisor
Advisor

Hi, if you don't need the rule(s) in the document, but just run it from VBA then you can use this one below instead. But I haven't figured out how to set up Event Triggers with VBA yet. So if you'd rather import the rules with pre-set Event Triggers then let me know and I'll translate it for you.

 

Public Sub RunMyRuleOne()
  RuniLogic "C:\Path\To\My\Rules\MyRule1.iLogicVb"
End Sub
Private Sub RuniLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document
' Here we set the document where the rule will be started 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
Private Function GetiLogicAddin(oApplication As Inventor.Application) As Object 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'm ussing ribbon button to run this, you can set up one like this:

You already know first few steps, but just to keep it crear.

 

1) In Inventor pres Alt + F11

Window named "Microsoft Visual Basic For Application" should pop up

On left there should be "Application Project (Default.ivb)"

2) Expand it.

3) Right-click on "Modules" > "Insert" > "Module"

4) Paste the code above.

5) Save and close "Microsoft Visual Basic For Application" window.

6) In Inventor in opened assembly go to "Tools" > "Customize"

7) In left tab expand the dropbox and select "Macros".

8) In right tab expand the dropbox and select "Assembly | Assembly"

9) In left tab select "RunMyRuleOne".

10) Click on the arrows leading to right.

11) Click "Apply" and "Close".

12) In assembly go to "Assembly" tab and you should see there "User Commands". (On the right side of Ribbon)

13) The button should be there. Use it to run the code.

 

Or you can try to translate it by yourself, for the sake of training. All you need for that is the Function and Sub from the code I'm sending you now.  😉 It's up to you, I don't mind to do it.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes