Sorry, I did apparently forget that step. I simply added a line of code to capture the originally active DVR to a variable, before activating the 'other' one. Then near the end, after locking that 'other' DVR, I simply use that previously created variable, to activate that originally active DVR again. To use this code in an external iLogic rule, instead of within an internal iLogic rule, you can simply right click on the internal iLogic rule in your 'Rules' tab, and choose 'Copy', then activate your 'External Rules' tab, then paste that rule where ever you want it within that tab's area. It should still work just as good that way.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting rule.", vbCritical, "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oSS As Inventor.SelectSet = oADoc.SelectSet
If oSS.Count = 0 Then
MsgBox("No assembly components were pre-selected. Exiting rule.", vbCritical, "iLogic")
Exit Sub
End If
Dim oOccsCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oObj In oSS
If TypeOf oObj Is ComponentOccurrence Then
oOccsCol.Add(oObj)
End If
Next
Dim sViewName As String
If oOccsCol.Count = 0 Then
MsgBox("No assembly components were pre-selected. Exiting rule.", vbCritical, "iLogic")
Exit Sub
ElseIf oOccsCol.Count = 1 Then
Dim oOcc As ComponentOccurrence = oOccsCol.Item(1)
sViewName = oOcc.Name
Else 'more than one
sViewName = InputBox("Enter View Rep Name.", "View Rep Name", "")
If sViewName = "" Then Exit Sub 'no name was specified, so exit rule
End If
Dim oRepsMgr As RepresentationsManager = oADoc.ComponentDefinition.RepresentationsManager
'record originally active DVR here, so we can re-activate it later
Dim oActiveDVR As DesignViewRepresentation = oRepsMgr.ActiveDesignViewRepresentation
Dim oDVRs As DesignViewRepresentations = oRepsMgr.DesignViewRepresentations
Dim oDVR As DesignViewRepresentation = Nothing
Try
oDVR = oDVRs.Item(sViewName)
Catch
oDVR = oDVRs.Add(sViewName)
End Try
oDVR.Activate
oDVR.HideAll
oDVR.SetVisibilityOfOccurrences(oOccsCol, True)
oDVR.Locked = True
oActiveDVR.Activate 're-activate originally active DVR
oADoc.Update
'oADoc.Save
By the way, if you have not used external iLogic rules before, you may want to set up a few things first. To do so, go to your Tools tab, and there should be a tool named 'iLogic Configuration' on the Options panel. If you do not see it, you may have to expand the panel down to see it. In the upper area of that dialog is where you can specify where you want your external iLogic rules to be stored. I have one main folder for external iLogic rules, which has a bunch of sub folders. Each sub folder is for a different category of external iLogic rules, for our internal organization, because we have tons of them. And I specify each of those sub folders in that dialog. Once that is done, that is where iLogic will first look for any external iLogic rules you attempt to run, so you only need to specify the external rules file name (without extension), and no path.
Wesley Crihfield

(Not an Autodesk Employee)