<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic iLogic rule to change view rep members seems to make interface unstable. in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785383#M167541</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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 " &amp;amp; oStartingRepName &amp;amp; ": " &amp;amp; oAction &amp;amp; selectedStuff.Count.ToString &amp;amp; " item(s)."
	Catch
		ThisApplication.StatusBarText = "Failed to change view rep " &amp;amp; oStartingRepName
	End Try

	oTrans.End

End Sub &lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 20 May 2024 16:51:27 GMT</pubDate>
    <dc:creator>nbonnett-murphy</dc:creator>
    <dc:date>2024-05-20T16:51:27Z</dc:date>
    <item>
      <title>iLogic rule to change view rep members seems to make interface unstable.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785383#M167541</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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 " &amp;amp; oStartingRepName &amp;amp; ": " &amp;amp; oAction &amp;amp; selectedStuff.Count.ToString &amp;amp; " item(s)."
	Catch
		ThisApplication.StatusBarText = "Failed to change view rep " &amp;amp; oStartingRepName
	End Try

	oTrans.End

End Sub &lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 May 2024 16:51:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785383#M167541</guid>
      <dc:creator>nbonnett-murphy</dc:creator>
      <dc:date>2024-05-20T16:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic rule to change view rep members seems to make interface unstable.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785401#M167542</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 16:56:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785401#M167542</guid>
      <dc:creator>nbonnett-murphy</dc:creator>
      <dc:date>2024-05-20T16:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic rule to change view rep members seems to make interface unstable.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785597#M167549</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12898829"&gt;@nbonnett-murphy&lt;/a&gt;, 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to use abort before the Exit Subs and in the Catch of your Try/Catch&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;oTrans.abort &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 18:59:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785597#M167549</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2024-05-20T18:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic rule to change view rep members seems to make interface unstable.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785891#M167564</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 21:37:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-rule-to-change-view-rep-members-seems-to-make-interface/m-p/12785891#M167564</guid>
      <dc:creator>nbonnett-murphy</dc:creator>
      <dc:date>2024-05-20T21:37:15Z</dc:date>
    </item>
  </channel>
</rss>

