Expanding the Origin of a Selected Component in Browser

Expanding the Origin of a Selected Component in Browser

Anonymous
Not applicable
1,327 Views
5 Replies
Message 1 of 6

Expanding the Origin of a Selected Component in Browser

Anonymous
Not applicable

Hello everybody.

 

I am trying to write a macro that should do the following:

 

1) The user selects an Component (Part or Assembly) in the Browser

2) The user run the macro and this expandes the Origin of the selected component.

 

I tried to do this using a ComponentOcurrence Definition but I cannot get this to work. The macro shows no errors but it does not change the Expanded Status from False to True.

 

Has anyone any idea why?

 

 

 

Sub ExpandUrsprung()
    On Error Resume Next
    Dim oOcc As ComponentOccurrence 'just necessary to select
    Set oOcc = ThisApplication.ActiveDocument.SelectSet(1)
   
    Dim a As Inventor.BrowserNode
    oOcc.Definition.Document.BrowserPanes.Item("Modell").topNode.BrowserNodes.Item("Ursprung").Expanded = True 'set the Expanded Value of the Origin (Ursprung) to True
   
End Sub

 

 

 

Ursprung-Autodesk Inventor 2016.jpg

 

Thank you very much!

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

MechMachineMan
Advisor
Advisor
Accepted solution

Because at that point you are wanting to access the BROWSER NODE; component definition has almost nothing to do with it. ie; when dealing with the browser nodes, all the component definition is good for is getting the occurrence so you can you the "GetBrowserNodeFromNativeObject" method.

 

Follow the link and read the associated resources and samples and it will get you along a better path.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-A8D2B514-1C99-422F-A58A-EF7B588A25F4

 

 

Also, as your code above shows, you are actually access a browser pane that you can't even see; the one belonging to the document that the occurrence references. The browser pane you want to be dealing with is the one that is visible and at the forefront - the assembly document browser pane.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hello MechMachine!

 

Yes, it works perfect! Thank you very much!

0 Likes
Message 4 of 6

filippo.toniello
Enthusiast
Enthusiast

Hi there

 

Colud you, please, share the working code? I'm interested to the same functionality but i have some problemt to make it works

0 Likes
Message 5 of 6

Anonymous
Not applicable

update 18/10

I figured to make it works but with sheetmetal fail maybe for the "folded model" sub node?

 

here the code i "patchworked":

 

    ' Get the active assembly document
Dim oDoc As AssemblyDocument
   	oDoc = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
	oOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Selezionare il componente per espandere la cartella Origine")

Dim oOccDef As ComponentOccurrence

    ' Get the model browser
Dim oPane As BrowserPane
   	oPane = oDoc.BrowserPanes.Activepane
		
'    ' Get the browser node that corresponds to the occurrence
Dim oCompo As BrowserNode
   	oCompo = oPane.GetBrowserNodeFromObject(oOcc)

Dim oNode As BrowserNode
For Each oNode In oCompo.BrowserNodes	
	If oNode.FullPath.Contains("Origin") Then
	oNode.Expanded = True
	End If
Next
0 Likes
Message 6 of 6

filippo.toniello
Enthusiast
Enthusiast

This works

    ' Get the active assembly document
Dim oDoc As AssemblyDocument
   	oDoc = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
	oOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Selezionare il componente per espandere la cartella Origine")

    ' Get the model browser
Dim oPane As BrowserPane
   	oPane = oDoc.BrowserPanes.Activepane
		
'    ' Get the browser node that corresponds to the occurrence
Dim oCompo As BrowserNode
   	oCompo = oPane.GetBrowserNodeFromObject(oOcc)

Dim oNode As BrowserNode
For Each oNode In oCompo.BrowserNodes	
	If oNode.FullPath.Contains("Origine") Then
	oNode.Expanded = True

	Else If oNode.FullPath.Contains("Modello piegato") Then
	Dim oNodeSheet As BrowserNodeDefinition
	oNodeSheet = oNode.BrowserNodeDefinition

    ' Get the work plane browser node.
    Dim oWorkPlaneNode As BrowserNode
		oWorkPlaneNode = oCompo.AllReferencedNodes(oNodeSheet).Item(1)
    Dim oNode2 As BrowserNode
	For Each oNode2 In oWorkPlaneNode.BrowserNodes	
	If oNode2.FullPath.Contains("Origine") Then
	oNode2.Expanded = True
	End If
	Next
	End If
Next