Run Rule on Revision Change

Run Rule on Revision Change

jmfowler1996
Advocate Advocate
1,146 Views
10 Replies
Message 1 of 11

Run Rule on Revision Change

jmfowler1996
Advocate
Advocate

Hi guys.

 

Basically, I need to run an iLogic rule when the revision of a drawing changes.

 

 

 

 

 

Context:

 

There are three relevant properties:

1. The default project revision number

2. A custom override revision number

3. The master revision number, which is displayed on the drawing.

    This displays the default revision unless an override is specified.

 

 

my iLogic rule for setting the master revision is:

 

If iProperties.Value("Custom", "Revision Override")="" Then

iProperties.Value("Custom", "Master Revision")=iProperties.Value("Project", "Revision Number")

Else

iProperties.Value("Custom", "Master Revision")=iProperties.Value("Custom", "Revision Override")

End If

 

and I need this to run when the default revision is changed.

 

It's a real shame there isn't an event trigger for this.

 

 

 

Any ideas?

Thanks in advance,

Jonathan

0 Likes
1,147 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

I'm just shooting out the office right now and haven't had a chance to try this out, but have a look at this if you haven't seen it already

 

hopefully should help!

 

 

http://forums.autodesk.com/t5/inventor-forum/ilogic-increment-revision-letter/td-p/4636499

0 Likes
Message 3 of 11

jmfowler1996
Advocate
Advocate

Hi there.

 

Thanks for the reply.

Unfortunately, that link solves a different problem.

 

To clarify, I am no trying to change the revision on the revision table. I already do that manually.

I am trying to make sure that when I manually change the table's revision, the title block updates to suit.

Currently, I manually change the revision on the revision table, and then run a rule to update the title block.

I don't want to have to run the rule every time the revision is changed, however.

 

I am wondering if there is some VBA code or something to run the rule for me, each time the revision changes.

 

If there isn't a way to do it, I think I might resort to a rule which toggles between the auto and override revisions by changing the parameter which the title block displays.

 

I know i'm not explaining this very well, so if anyone has any questions, I will do my best to respond in reasonable time.

Thanks again!

0 Likes
Message 4 of 11

bshbsh
Collaborator
Collaborator

Here's some VBA code. Sorry I'm not really into ilogic, but hope this helps.

You will need a class module and a code module.

This goes into the class module (which I named "cEvents" - can be anything if you match the name in the other code to it.)

 

' This is the Class Module Code!
' Class Module name: cEvents

Private WithEvents oAppEvents As ApplicationEvents
Private WithEvents oDocEvents As DocumentEvents
Private Sub Class_Initialize()
    Set oAppEvents = ThisApplication.ApplicationEvents
    Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
End Sub
Private Sub oAppEvents_OnActivateDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
    If BeforeOrAfter = kAfter Then
        If DocumentObject.DocumentType = kDrawingDocumentObject Then
            Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
        Else
            Set oDocEvents = Nothing
        End If
    End If
End Sub
Private Sub oDocEvents_OnChange(ByVal ReasonsForChange As CommandTypesEnum, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
    If BeforeOrAfter = kAfter Then
        If (ReasonsForChange And kFilePropertyEditCmdType) = kFilePropertyEditCmdType Then
            Dim MasterRevision As Property
            Dim RevisionOverride As Property
            Dim RevisionNumber As Property
            On Error GoTo quit
            Set MasterRevision = ThisApplication.ActiveDocument.PropertySets.Item("Inventor User Defined Properties").Item("Master Revision")
            Set RevisionOverride = ThisApplication.ActiveDocument.PropertySets.Item("Inventor User Defined Properties").Item("Revision Override")
            Set RevisionNumber = ThisApplication.ActiveDocument.PropertySets.Item("Inventor Summary Information").Item("Revision Number")
            If RevisionOverride.Value = "" Then
                MasterRevision.Value = RevisionNumber.Value
            Else
                MasterRevision.Value = RevisionOverride.Value
            End If
quit:
        End If
    End If
End Sub

And this is your ordinary VBA macro code:

 

 

'This is the Code Module!

Dim oEvents As cEvents    'make sure "cEvents" here matches your class module name!
Public Sub RevisionChangeEvents()
    Set oEvents = New cEvents   'make sure "cEvents" here matches your class module name!
End Sub

And to use it, you will have to run the sub RevisionChangeEvents once. This will initialize the two events. One fires if the active document changes (and disables the other event if the new active document is not a drawing). The other fires if the active document somehow changes, and if the change is a document property event (ex. any kind of iProperties modification) then it will update your custom iproperties.

 

 

Message 5 of 11

jmfowler1996
Advocate
Advocate
Hi.

I really appreciate your help.
I'll check this out early next week and come back with the results.

Thanks!
Message 6 of 11

jmfowler1996
Advocate
Advocate

Hi again.

Sorry for the delay, but I have been ridiculously busy and have also had to make some changes to the code.

 

I wasn't able to get that code to work, unfortunately. I also decided it would be simpler to just get to code to run an existing iLogic rule, so I altered it to just run my iLogic rule instead:

 

 

Code Module:

 

'This is the Code Module!

Dim oEvents2 As cEvents2    'make sure "cEvents2" here matches your class module name!
Public Sub RevisionChangeEvents()
    Set oEvents2 = New cEvents2   'make sure "cEvents2" here matches your class module name!
End Sub

-Code module as before, I have just used oEvents2/cEvents2 as cEvents2 is what I named my edited class code.

 

 

 

Class Module Code:

Private WithEvents oAppEvents As ApplicationEvents
Private WithEvents oDocEvents As DocumentEvents
Private Sub Class_Initialize()
    Set oAppEvents = ThisApplication.ApplicationEvents
    Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
End Sub
Private Sub oAppEvents_OnActivateDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
    If BeforeOrAfter = kAfter Then
        If DocumentObject.DocumentType = kDrawingDocumentObject Then
            Set oDocEvents = ThisApplication.ActiveDocument.DocumentEvents
        Else
            Set oDocEvents = Nothing
        End If
    End If
End Sub

Private Sub oDocEvents_OnChange(ByVal ReasonsForChange As CommandTypesEnum, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
    
    If BeforeOrAfter = kAfter Then
    
    RuniLogic "Revision"
    
        'If (ReasonsForChange And kFilePropertyEditCmdType) = kFilePropertyEditCmdType Then
            'RuniLogic "Revision"
        
quit:
        End If
    End If
End Sub


Public Sub LaunchRevisionClass() '<--- This is what you would tie to a button in a toolbar.
  RuniLogic "Revision"
End Sub
 
'Public Sub LaunchMyRule2() '<--- This is what you would tie to a button in a toolbar.
'  RuniLogic "MyRule2"
'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.RunRule 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

-Class module runs my iLogic rule

 

 

 

The problem I now have is that as you said, the rule will run whenever there is any change in the document. This is a bit inconvenient since I would like to run a few additional rules, one of which activates each sheet in turn and adds a revision table (and deleting any existing ones). I don't want this to happen unless the revision has changed.

 

Is there any way to have the code trigger only when the revision is changed?

Thanks!

 

P.S. I still don't know why I wasn't able to get the other code to work, but this seems to work fine, other than that it triggers too often.

 

 

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

Have the rule run when there is a change in document but use a try catch. If the properties don’t change then it will not run thru the rule. I think that will be your easiest fix.

 

I hope this helps.

Message 8 of 11

bshbsh
Collaborator
Collaborator

@jmfowler1996 wrote:
I wasn't able to get that code to work, unfortunately.

Hi,

sorry to hear that. Why didn't it work, what did it do? Any errors?

I see you commented out a line, I guess that's what was causing you problems. Unfortunatelly that is exactly the line that filters out events so that the rest of the code will only run on iproperties change events, but not on other events. This is what didn't work I guess? Did it not trigger or something?

0 Likes
Message 9 of 11

jmfowler1996
Advocate
Advocate

Okay, I think I see where it is going wrong.

 

When I use the line

If (ReasonsForChange And kFilePropertyEditCmdType) = kFilePropertyEditCmdType Then

the rule would not run at all.

 

However, I have now found that it does run, in the condition that the revision has been manually changed via the project tab of iproperties.

That's the thing- I don't manually update the revision. The automatic revision changes to the active row (most recently added). I think this was an option in application options somewhere. I can't remember.

 

Either way, the problem is that my rule will only trigger if the revision is manually changed, and not when I update it by other means.

Is there an easy fix for this?

 

Thanks.

0 Likes
Message 10 of 11

bshbsh
Collaborator
Collaborator

Oh I see. I thought your Revision change is also written back into some of the IDW's iProperties too, not just in the Revision table. (That's what we do.)

The easy fix would be then if you changed your revisiontable-changing macro to do something with the iproperties as well. Something "dummy", for example, read any of the existing iproerties (eg. the Description) and write it back as is. I guess this would count as an iproperties change and would fire the event.

0 Likes
Message 11 of 11

jmfowler1996
Advocate
Advocate

Okay, that's a good idea, but I don't have a macro for changing the revision. What I meant when I said that I don't do it manually is that I don't go into iProperties. I double click on the revision table and edit from within the table itself. If I add a new revision row, the automatic revision will pick up on that and change the drawing's revision to that of the most recent revision row.

 

Thanks again.

0 Likes