Error on Browser Node Expansion

Error on Browser Node Expansion

brianA32ZM
Advocate Advocate
369 Views
5 Replies
Message 1 of 6

Error on Browser Node Expansion

brianA32ZM
Advocate
Advocate

Hello, I am attempting to collapse all Model Browser Nodes with the exception of the Representations that will be expanded. I am looking for help as the code errors on "oNode.Expanded". Thanks in advance. 

Dim oApp As Inventor.Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

Dim oComDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oRepMan As RepresentationsManager
oRepMan = oCompDef.RepresentationsManager

Dim oDVReps As DesignViewRepresentations
oDVReps = oRepMan.DesignViewRepresentations

Dim oPanes As BrowserPanes
oPanes = oDoc.BrowserPanes

Dim oPane As BrowserPane
oPane = oPanes.Item("Model")

Dim oTopNodes As BrowserNode
oTopNode = oPane.TopNode

Dim oNodes As BrowserNodesEnumerator
oNodes = oTopNode.BrowserNodes

For Each oDVRep As DesignViewRepresentation In oDVReps

	oDVRep.Activate

	For Each  oNode In  oNodes
		
		If oNode.FullPath.Contains("Representations")
			Logger.Info(oNode.FullPath)
			Logger.Info(oNode.Expanded )
			oNode.Expanded = True
			oNode.BrowserNodes.Item(1).Expanded = True
		Else
			oNode.Expanded = False
		End If
	Next
Next

Error: 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments)
at ThisRule.Main() in rule: Rule1, in document XX-XXXX-T_Diverter_Template.iam:line 37
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Accepted solutions (1)
370 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @brianA32ZM.  Just a quick thought...  I kind of doubt that this might actually help, but in your line of code for initializing the loop of BrowserNodes, try adding the variable's Type in there, so it is not seen as Object later within the loop.

 

For Each oNode As BrowserNode In oNodes

 

PS.  Another thing that might be a factor is the BrowserNode.Visible status.  I wander if the node is not visible, it may not like you accessing its Expanded property...just another thought that might be worth exploring.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

brianA32ZM
Advocate
Advocate

Thank you. I might be a step closer, but not there yet. 

Adding "As BrowserNode" had no effect, but I think you are no to something with the BrowsersNode Visibility.  I added a Try Catch statement and found out all the non-visible nodes failed. I then tried to make them visible (oNode.Visible = True) before expanding, however that did not change the status.  

0 Likes
Message 4 of 6

bradeneuropeArthur
Mentor
Mentor

try this out:

Dim oApp As Inventor.Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

Dim oComDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oRepMan As RepresentationsManager
oRepMan = oCompDef.RepresentationsManager

Dim oDVReps As DesignViewRepresentations
oDVReps = oRepMan.DesignViewRepresentations

Dim oPanes As BrowserPanes
oPanes = oDoc.BrowserPanes

Dim oPane As BrowserPane
oPane = oPanes.Item("Model")

Dim oTopNodes As BrowserNode
oTopNode = oPane.TopNode

Dim oNodes As BrowserNodesEnumerator
oNodes = oTopNode.BrowserNodes

For Each oDVRep As DesignViewRepresentation In oDVReps
'MsgBox(oDVRep.Name)
If Not oRepMan.ActiveDesignViewRepresentation.Name = oDVRep.Name Then
	oDVRep.Activate

	For Each  oNode As BrowserNode In  oNodes
		'MsgBox (oNode.BrowserNodeDefinition.Label)
		If oNode.FullPath.Contains("Representations")
			Logger.Info(oNode.FullPath)
			Logger.Info(oNode.Expanded )
			oNode.Expanded = True
			oNode.BrowserNodes.Item(1).Expanded = True
		Else
			oNode.Expanded = False
		End If
	Next
	End If
Next

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 6

bradeneuropeArthur
Mentor
Mentor

Or try this:

Dim oApp As Inventor.Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

Dim oComDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oRepMan As RepresentationsManager
oRepMan = oCompDef.RepresentationsManager

Dim oDVReps As DesignViewRepresentations
oDVReps = oRepMan.DesignViewRepresentations

Dim oPanes As BrowserPanes
oPanes = oDoc.BrowserPanes

Dim oPane As BrowserPane
oPane = oPanes.Item("Model")

Dim oTopNodes As BrowserNode
oTopNode = oPane.TopNode

Dim oNodes As BrowserNodesEnumerator
oNodes = oTopNode.BrowserNodes

For Each oDVRep As DesignViewRepresentation In oDVReps
'MsgBox(oDVRep.Name)
If Not oRepMan.ActiveDesignViewRepresentation.Name = oDVRep.Name Then
	oDVRep.Activate
'MsgBox(oDVRep.Name)
	For Each  oNode As BrowserNode In  oNodes
		'MsgBox (oNode.BrowserNodeDefinition.Label)
		If oNode.FullPath.Contains("Representations")
			Logger.Info(oNode.FullPath)
			Logger.Info(oNode.Expanded)
			'MsgBox(oNode.FullPath)
			Try
				oNode.Expanded = True
				Catch
			End Try
			
			Try
			oNode.BrowserNodes.Item(1).Expanded = True
			Catch
		End Try
		Else
			Try 
				oNode.Expanded = False
				Catch
			End Try
			'
		End If
	Next
End If	
Next

 

Regards,

 

Arthur

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 6

brianA32ZM
Advocate
Advocate
Accepted solution

bradeneuropeArthur thank you. 

 

this line was not needed: If Not oRepMan.ActiveDesignViewRepresentation.Name = oDVRep.Name Then

 

The Try Catch statements helped me find the 3 nodes (Positional Representations, iMates, and End of Features) that were causing the error.  I should place the Try Catch statements back in, but the code below works. 

 

Dim oApp As Inventor.Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

Dim oComDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oRepMan As RepresentationsManager
oRepMan = oCompDef.RepresentationsManager

Dim oDVReps As DesignViewRepresentations
oDVReps = oRepMan.DesignViewRepresentations

Dim oPanes As BrowserPanes
oPanes = oDoc.BrowserPanes

Dim oPane As BrowserPane
oPane = oPanes.Item("Model")

Dim oTopNodes As BrowserNode
oTopNode = oPane.TopNode

Dim oNodes As BrowserNodesEnumerator
oNodes = oTopNode.BrowserNodes

For Each oDVRep As DesignViewRepresentation In oDVReps

	oDVRep.Activate

	For Each oNode As BrowserNode In oNodes

		If oNode.FullPath.Contains("Positional Representations") Or oNode.FullPath.Contains("iMates") Or oNode.FullPath.Contains("End of Features")
			'Do nothing
		ElseIf oNode.FullPath.Contains("Representations")
			oNode.Expanded = True
			oNode.BrowserNodes.Item(1).Expanded = True
		Else
			oNode.Expanded = False
		End If

	Next

Next