Change "Representation" automatically when changing "Model State" of an assembly

Change "Representation" automatically when changing "Model State" of an assembly

LiamB281200
Observer Observer
204 Views
2 Replies
Message 1 of 3

Change "Representation" automatically when changing "Model State" of an assembly

LiamB281200
Observer
Observer

Does anyone know how to have a "Representation" change automatically with a change of "Model State"? I have 7 custom Representations which match 7 custom Model States and whenever I change a Model State, I have to manually change the Representation to match it. Is there a way of making it change automatically when I change the Model State?

0 Likes
205 Views
2 Replies
Replies (2)
Message 2 of 3

harvey3ELEA
Advocate
Advocate

I have similar setups on my tanks and I would love if you could link reps to model states, but I don't think it's possible short of one of the board's talented iLogic coders devising a routine to make that happen, if even possible.

0 Likes
Message 3 of 3

harvey3ELEA
Advocate
Advocate

This code makes it happen (works on my end), but carefully read the risks mentioned in thread 12391641 .

WCrihfield compiled and posted this on 11/21/2023 at this link:

Click 12391641 (won't accept an http link here)

 

 

Sub Main
	If oMSEvents Is Nothing Then oMSEvents = ThisApplication.ModelStateEvents
	AddHandler oMSEvents.OnActivateModelState, AddressOf oMSEvents_OnActivateModelState
End Sub

Dim oMSEvents As ModelStateEvents

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.kAfter Then
		Dim RepMgr As RepresentationsManager = Doc.ComponentDefinition.RepresentationsManager
		If RepMgr.ActiveDesignViewRepresentation.Name <> MS.Name Then
			Dim DVRs As DesignViewRepresentations = RepMgr.DesignViewRepresentations
			Dim DVR As DesignViewRepresentation = Nothing
			Try : DVR = DVRs.Item(MS.Name) : Catch : End Try
			If DVR Is Nothing Then Return
			Try : DVR.Activate : Catch : End Try
		End If
	End If
End Sub

  

0 Likes