OK. Below are two different iLogic rules. The first one is primarily just for research, documentation purposes, because it just writes information to the iLogic Log window when those two events happen. The second example is a very simple working example that listens for a DVR to be activated, then it tries to activate a ModelState with the same name as the DVR (not the other way around right now).
Research example:
Sub Main
If oRepEvents Is Nothing Then oRepEvents = ThisApplication.RepresentationEvents
If oMSEvents Is Nothing Then oMSEvents = ThisApplication.ModelStateEvents
AddHandler oRepEvents.OnActivateDesignView, AddressOf oRepEvents_OnActivateDesignView
AddHandler oMSEvents.OnActivateModelState, AddressOf oMSEvents_OnActivateModelState
End Sub
Dim oRepEvents As RepresentationEvents
Dim oMSEvents As ModelStateEvents
Sub oRepEvents_OnActivateDesignView(Doc As Document, DVR As DesignViewRepresentation, _
BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
'HandlingCodeEnum is ignored for this event
If BeforeOrAfter = EventTimingEnum.kBefore Then
Logger.Info("Before: DesignViewRepresentation named '" & DVR.Name & "' activated in " & Doc.DisplayName)
If Context.Count = 0 Then
Logger.Info("Zero Context")
Else
For i = 1 To Context.Count
Logger.Info(Context.Name(i) & " = " & Context.Item(i).ToString)
Next
End If
ElseIf BeforeOrAfter = EventTimingEnum.kAfter Then
Logger.Info("After: DesignViewRepresentation named " & DVR.Name & "' activated in " & Doc.DisplayName)
If Context.Count = 0 Then
Logger.Info("Zero Context")
Else
For i = 1 To Context.Count
Logger.Info(Context.Name(i) & " = " & Context.Item(i).ToString)
Next
End If
End If
End Sub
Sub oMSEvents_OnActivateModelState(Doc As Document, MS As ModelState, _
BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
'no context for this event, and HandlingCodeEnum is ignored also
If BeforeOrAfter = EventTimingEnum.kBefore Then
Logger.Info("Before: ModelState named '" & MS.Name & "' activated in " & Doc.DisplayName)
ElseIf BeforeOrAfter = EventTimingEnum.kAfter Then
Logger.Info("After: ModelState named '" & MS.Name & "' activated in " & Doc.DisplayName)
End If
End Sub
Working example:
Sub Main
If oRepEvents Is Nothing Then oRepEvents = ThisApplication.RepresentationEvents
AddHandler oRepEvents.OnActivateDesignView, AddressOf oRepEvents_OnActivateDesignView
End Sub
Dim oRepEvents As RepresentationEvents
Sub oRepEvents_OnActivateDesignView(Doc As Document, DVR As DesignViewRepresentation, _
BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
'HandlingCodeEnum is ignored for this event
If BeforeOrAfter = EventTimingEnum.kAfter Then
If Doc.ModelStateName <> DVR.Name Then
Dim oMSs As ModelStates = Doc.ComponentDefinition.ModelStates
If oMSs.Count < 2 Then Return
Dim oMS As ModelState = Nothing
Try : oMS = oMSs.Item(DVR.Name) : Catch : End Try
If oMS Is Nothing Then Return
Try : oMS.Activate : Catch : End Try
End If
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)