execute ILogic for all open documents

execute ILogic for all open documents

philip.G
Enthusiast Enthusiast
5,292 Views
20 Replies
Message 1 of 21

execute ILogic for all open documents

philip.G
Enthusiast
Enthusiast

Hey There

 

I was wondering. 

Is there a way to execute an I-Logic - script for all open documents? (eg. in a for-loop)

I know there is something similar for all referenced documents of an assembly but couldn't find it for all open files. 

 

I need this because I want to execute an I Logic code in a bunch of drawings but these drawings aren't all in the same assembly. (And I don't want to make an assembly just for executing this script.)

 

Thanks for your suggestions. 

 

Best Regards

 

 

 

 

0 Likes
Accepted solutions (1)
5,293 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable

This is in VBA but can probably be adapted to iLogic:

 

    Dim oDoc As Document

    For Each oDoc In ThisApplication.Documents.VisibleDocuments
        If oDoc.DocumentType = kDrawingDocumentObject Then
            ....
        End If
    Next oDoc
Message 3 of 21

bradeneuropeArthur
Mentor
Mentor

Hi,

 

The following code does this for you:

 

Public Sub Start()
Dim a As Application
Set a = ThisApplication

Dim b As Document
Dim c As Documents

For Each b In a.Documents.VisibleDocuments

RuniLogic "MyRule1", b
Next
End Sub





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

  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
  Dim addIns As ApplicationAddIns
  Set addIns = oApplication.ApplicationAddIns
  Dim addIn As ApplicationAddIn
  Dim customAddIn As ApplicationAddIn
  For Each addIn In addIns
    If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
      Set customAddIn = addIn
    Exit For
    End If
  Next

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 21

philip.G
Enthusiast
Enthusiast

Thanks for the idea, I will check tomorrow!

0 Likes
Message 5 of 21

philip.G
Enthusiast
Enthusiast

wow, this didn't took long for a second answer. 

I will definitely check if these lines of code work!

0 Likes
Message 6 of 21

bradeneuropeArthur
Mentor
Mentor

what do you mean...?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 21

bradeneuropeArthur
Mentor
Mentor
It Works?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 21

philip.G
Enthusiast
Enthusiast
I tried both I logic an vba. neither worked.
I'm not sure what the fault is,
maybee it's just formatting. I will check again in about an hour when I'm at the cad workplace again.
One of the errors i got was that "set" isn't supportet anymore...
But your code seems reasonable to me. I don't think that is were the error occured.

0 Likes
Message 9 of 21

philip.G
Enthusiast
Enthusiast

It worked with the code below from @Anonymous

But I don't know how to call the I Logic with this code. 

 

 

Public Sub Multi_Ilogic()
    Dim oDoc As Document

    For Each oDoc In ThisApplication.Documents.VisibleDocuments
        If oDoc.DocumentType = kDrawingDocumentObject Then
            MsgBox ("It works! OMG!!!")
            -> how do I call an I Logic from the vba-editor?
        End If
    Next oDoc
End Sub

 

 

then I tried @bradeneuropeArthur code. 

Now it worked as well. (My fault, messed it up with Ilogic/vba window ;-J)

But...

nothing happend. 

I inserted some Message-boxes to check if the code made it to the essential parts. And it did. No Problems whatsoever. 

But the Test-Ilogic Script wasn't executed.

The Ilogic-Text-script works. I'm 100% certain. (Its just a messagebox telling me that it works.)

 

I used the code below. I hope someone knows better than me Smiley Wink

 

Best regards

 

 

Public Sub Multi_Ilogic_2()
Dim a As Application
Set a = ThisApplication
'MsgBox "Dim,Set application succesful"

Dim b As Document
Dim c As Documents
'MsgBox "Dim,Set document succesful"

For Each b In a.Documents.VisibleDocuments

RuniLogic "Test", b
MsgBox "run succesful"
Next
End Sub

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

  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
   'Else
    'MsgBox "Inventor document not missing"
    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
  Dim addIns As ApplicationAddIns
  Set addIns = oApplication.ApplicationAddIns
  Dim addIn As ApplicationAddIn
  Dim customAddIn As ApplicationAddIn
  For Each addIn In addIns
    If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
      Set customAddIn = addIn
      'MsgBox "Set customAddIn = addIn"
    Exit For
    End If
  Next


End Function

 

 

0 Likes
Message 10 of 21

bradeneuropeArthur
Mentor
Mentor
How is your external rule named: is it Test.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 11 of 21

philip.G
Enthusiast
Enthusiast

exactly

 

0 Likes
Message 12 of 21

bradeneuropeArthur
Mentor
Mentor
Can you share that too

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 13 of 21

philip.G
Enthusiast
Enthusiast
'MsgBox "OMG It worked!!!"

 

0 Likes
Message 14 of 21

bradeneuropeArthur
Mentor
Mentor
iLogicAuto.RunExternalRule oDoc, RuleName End Sub

You try to run external rule. But it is s document rule
Change to
iLogicAuto.RunRule oDoc, RuleName End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 15 of 21

philip.G
Enthusiast
Enthusiast
  Set iLogicAuto = GetiLogicAddin(ThisApplication)
  If (iLogicAuto Is Nothing) Then Exit Sub
  iLogicAuto.RunRule oDoc, RuleName
End Sub

now it looks like this. but still, no success.

Is maybee the varaible RuleName defined wrong?

0 Likes
Message 16 of 21

bradeneuropeArthur
Mentor
Mentor
iLogicVb.RunRule(“componentName”, “ruleName”)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 17 of 21

philip.G
Enthusiast
Enthusiast

then i put in :?

 

 

iLogicVb.RunRule(“Rule”, “Test”)

 

 

0 Likes
Message 18 of 21

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Complete new:

 

And it works for me

 

Public Sub Internal_iLogic()

Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
            Exit For
        End If
    Next

 
  Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments

  'Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If
 
iLogicAuto.RunRule oDoc, "Test" 'for internal rule
'iLogicAuto.RunExternalRule oDoc, "Test" 'for external rule
'oDoc.Activate
Next
End Sub

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 19 of 21

philip.G
Enthusiast
Enthusiast

Hi @bradeneuropeArthur

 

I changed the code just a touch. now it works for me too!

Thanks a lot for your help. I could have never done this without you. 

 

Below the code I use now. 

 

Have a nice day ☺

 

Public Sub Internal_iLogic()

Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
            Exit For
        End If
    Next

 
  Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments

  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
    'Else:
        'iLogicAuto.RunRule oDoc, "Test"
  End If
 
iLogicAuto.RunRule oDoc, "Test" 'for internal rule
'iLogicAuto.RunExternalRule oDoc, "Test" 'for external rule
'oDoc.Activate
Next
End Sub
0 Likes
Message 20 of 21

bradeneuropeArthur
Mentor
Mentor
Your thanks are appreciated.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes