ILOGIC ADD RULE IN ASSEMBLY!

ILOGIC ADD RULE IN ASSEMBLY!

Anonymous
Not applicable
1,065 Views
6 Replies
Message 1 of 7

ILOGIC ADD RULE IN ASSEMBLY!

Anonymous
Not applicable

HI!

 

It's possible to add rule in assembly with ilogic?

 

or to rule externalrule in assembly from a IDW?

 

Thanks for your help!

0 Likes
Accepted solutions (1)
1,066 Views
6 Replies
Replies (6)
Message 2 of 7

LukeDavenport
Collaborator
Collaborator

 

Hi Serge 

You can create an iLogic rule with an iLogic rule as shown in my blog here:

 

https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule...

 

Thanks,
Luke

 

Message 3 of 7

Anonymous
Not applicable

Thanks for your reply Luke 🙂

 

Work really great in Document, but Do you think it's possible to run this externalrule in assembly from a IDW?

 

 

0 Likes
Message 4 of 7

adam.nagy
Autodesk Support
Autodesk Support

Did you try? 🙂



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 7

LukeDavenport
Collaborator
Collaborator
Accepted solution

You might be pleasantly surprised Serge 🙂

Message 6 of 7

Anonymous
Not applicable

Hi Luke 🙂

 

I have a little problem with your code, when i have no rule in my part or assembly i have this error message

 

Object reference not set to an instance of an object.

 

Thanks for your help!

 

 

0 Likes
Message 7 of 7

mr_ensing
Advocate
Advocate

@LukeDavenport wrote:

 

https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule...


 

I adapted the above mentioned code for use in the VBA editor.

 


@Anonymous wrote:

 

Object reference not set to an instance of an object.


 

This problem is fixed as well.

 

 

 

Sub AddInternalDummyRuleTest()

    Call AddInternalDummyRule(ThisApplication.ActiveDocument)
    
End Sub

Function AddInternalDummyRule(Doc As Document, Optional OverWrite As Boolean = False)
    'adapted from: https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule-automatically/
                             
    'define the iLogic addin
    Dim iLogicAddIn As ApplicationAddIn:    Set iLogicAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    'get the iLogic automation object
    Dim iLogic As Object:                   Set iLogic = iLogicAddIn.Automation
    'get the list of iLogic rules in the current Inventor document
    Dim RuleList As Object:                 Set RuleList = iLogic.Rules(Doc)
    
    Dim RuleName As String:                 RuleName = "DummyInternalRule"
    Dim RuleText As String:                 RuleText = ""
    
    'loop through all rules in document
    Dim Rule As Object
    If Not (RuleList Is Nothing) Then
        For Each Rule In RuleList
            If StrComp(Rule.Name, RuleName, vbTextCompare) = 0 Then
                If StrComp(Rule.Name, RuleName, vbTextCompare) = 0 Then
                    'a rule with the same name already exists...
                    Exit For
                End If
            End If
        Next Rule
    End If

    If Not (Rule Is Nothing) Then
        If OverWrite Then
            'delete the existing rule
            Call iLogic.DeleteRule(Doc, RuleName)
        Else
            Exit Function
        End If
     End If

    'add the new rule
    Call iLogic.AddRule(Doc, RuleName, RuleText)

End Function

 

 

 

 

 

 

 

 

0 Likes