- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have this script which takes a selection set, asks the user to add or remove, then unlocks the current view rep, adds/removes the selected items, then relocks the view rep.
For some reason it seems to destabilize the interface. Specifically, the locked/unlocked icons on the view reps don't update properly until you deselect and reselect the active view rep. Also, I went to another part context and dragging the pointer around in the tree didn't update it's apparent position, but would still suppress/unsuppress features as if it was being moved. It also causes a problem where the undo buffer isn't accessible. Even if I make changes, it stays greyed out, and ctrl-Z doesn't reverse changes. I'm guessing that one might be caused by having "exit sub"s happen without closing the transaction so it get's stuck open if I happen to error out during testing.
Can someone help me figure out why this would cause interface problems and what I can do to prevent it? I know there are interface update commands, but I'm not sure where to start with that.
Sub Main
Dim oTransMgr As TransactionManager = ThisApplication.TransactionManager
Dim oTrans As Transaction = oTransMgr.StartTransaction(ThisApplication.ActiveDocument, "View Rep Script")
Dim oDoc As Inventor.Document = ThisApplication.ActiveEditDocument
Dim sSet = oDoc.SelectSet
Dim selectedStuff As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
Dim allViewReps = oDoc.ComponentDefinition.representationsManager.designviewrepresentations
Dim oStartingRep As DesignViewRepresentation = oDoc.ComponentDefinition.representationsManager.ActiveDesignViewRepresentation
Dim oStartingRepName As String = oStartingRep.Name.ToString
If sSet.Count = 0 Then
ThisApplication.StatusBarText = "Empty selection set. Exiting script."
Exit Sub
End If
For Each thing In sSet
selectedStuff.Add(thing)
Next
Logger.Info("Set active rep: {0}", oStartingRep.Name)
Logger.Info("{0} items selected", selectedStuff.Count)
userResponse = MsgBox("Do you want these IN the view rep?", vbYesNoCancel,"Add or remove?")
If userResponse = vbYes
addOrRemove = True
oAction = "Including "
ElseIf userResponse = vbNo
addOrRemove = False
oAction = "Excluding "
Else
ThisApplication.StatusBarText = "View rep change cancelled."
Exit Sub
End If
Try
allViewReps.item(oStartingRepName).locked = False
allViewReps.item(oStartingRepName).SetVisibilityOfOccurrences(selectedStuff, addOrRemove)
allViewReps.item(oStartingRepName).locked = True
ThisApplication.StatusBarText = "View rep " & oStartingRepName & ": " & oAction & selectedStuff.Count.ToString & " item(s)."
Catch
ThisApplication.StatusBarText = "Failed to change view rep " & oStartingRepName
End Try
oTrans.End
End Sub
Solved! Go to Solution.