Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic rule to change view rep members seems to make interface unstable.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
nbonnett-murphy
207 Views, 3 Replies

iLogic rule to change view rep members seems to make interface unstable.

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 
3 REPLIES 3
Message 2 of 4

After a little bit more testing, I believe that the undo problem was related to the transaction getting stuck open if the script errors out. I added oTrans.End before every "exit sub" and that seems to have helped. Not yet clear if it also fixes the interface problems.

Message 3 of 4

@nbonnett-murphy, I don't know that I have a solution for you, but as soon as I saw the Transaction, I was going to reply that it was going to be the source of this issue ( based on my own experience with transactions). So you're on the right track.

 

You might want to use abort before the Exit Subs and in the Catch of your Try/Catch

 

oTrans.abort 

 

 

 

Message 4 of 4

Yep, looks like that pretty much did it thanks. I'll need to go through my other scripts where I use the transaction manager to make sure there aren't any cases where it gets left open like this one.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report