Wait while user selects browsernodes in drawing

Wait while user selects browsernodes in drawing

Anonymous
Not applicable
937 Views
6 Replies
Message 1 of 7

Wait while user selects browsernodes in drawing

Anonymous
Not applicable

Hi,

 

I'm looking for a way to let user selects browsernodes in a drawing in a vb.net program.

 

I tried:

Dim comps As Inventor.ObjectCollection= m_inventorApplication.TransientObjects.CreateObjectCollection
Dim comp As Object

 

While True
comp = m_inventorApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kCustomBrowserNodeFilter, "Select items in the browser!")

' If nothing gets selected then we're done
If IsNothing(comp) Then Exit While

comps.Add(comp)
End While

' If there are selected components we can do something
For Each comp In comps
MessageBox.Show("OK")
Next

 

regards Geert

0 Likes
Accepted solutions (1)
938 Views
6 Replies
Replies (6)
Message 2 of 7

Owner2229
Advisor
Advisor

Hey, I'm afraid there's no filter for BrowserNodes, so we have to use an workaround:

 

Dim oComps As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
While True
	Dim oComp As Object = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kAllEntitiesFilter, "Select items in the browser!")
	' If nothing gets selected then we're done 
	If IsNothing(oComp) Then Exit While
	oComps.Add(oComp)
End While
If oComps.Count = 0 Then Exit Sub
For Each oComp As Object In oComps
	If oComp.Type <> ObjectTypeEnum.kBrowserFolderObject Then Continue For
	MessageBox.Show(oComp.Name)
Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 7

ekinsb
Alumni
Alumni

Just to be sure we're all on the same page, what do you mean by "browser node"?  Any type of browser node or a node that represents a specific type of entity?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 4 of 7

Anonymous
Not applicable

Hi Mike,

 

this isn't working.

User can't still select browsernodes with filter = kAllEntitiesFilter.

So comp is nothing.

 

regards,

 

Geert

0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi Brian,

 

i'm writing a layer Synchronisation program for our sales department.

The environment is an Inventor Drawing.

 

The program must do the following:

1) expand the browsernodes in the drawing from the first view till the first assembly (this i have working)

2) user selects in browserpane the parts which must be changed by layer (this i'm searching for)

3) select in all other views the same selected parts

4) for all the selected parts -> call Select Edges

5) change layer of all the selected items

 

This is the code i've so far:

 

       Dim oINVDrawingDoc As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument

        'collapse browser of first view en first assembly
        Dim oTopBrowserNode As Inventor.BrowserNode
        oTopBrowserNode = oINVDrawingDoc.BrowserPanes.ActivePane.TopNode
        Dim oBladBrowserNode As Inventor.BrowserNode = oTopBrowserNode.BrowserNodes("Blad:1")
        For Each oViewBrowserNode As Inventor.BrowserNode In oBladBrowserNode.BrowserNodes
            If oViewBrowserNode.FullPath.Contains("VIEW") Then
                For Each oAsmBrowserNode As Inventor.BrowserNode In oViewBrowserNode.BrowserNodes
                    Dim oAsmBrowserNodeDefinition As Inventor.BrowserNodeDefinition = oAsmBrowserNode.BrowserNodeDefinition
                    If oAsmBrowserNodeDefinition.Label = (Replace(oTopBrowserNode.FullPath, "dwg", "iam")) Then
                        oAsmBrowserNode.Expanded = True
                        GoTo SelectItems
                    End If
                Next
            End If
        Next

SelectItems:

        'select  items in browser 
        Dim comps As Inventor.ObjectCollection = m_inventorApplication.TransientObjects.CreateObjectCollection
        Dim comp As Object

        While True
            comp = m_inventorApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kAllEntitiesFilter, "Select items in the browser!")

            ' If nothing gets selected then we're done	
            If IsNothing(comp) Then Exit While

            comps.Add(comp)
        End While

        ' If there are selected components we can do something
        For Each comp In comps
            If comp.Type <> Inventor.ObjectTypeEnum.kBrowserFolderObject Then Continue For
            MessageBox.Show(comp.Name)
        Next


        
        'loop through first view and assembly to get the selected items
        'Dim oTopBrowserNode As Inventor.BrowserNode
        'oTopBrowserNode = oINVDrawingDoc.BrowserPanes.ActivePane.TopNode
        Dim assemblyName As String = (Replace(oTopBrowserNode.FullPath, "dwg", "iam"))

        'Dim oBladBrowserNode As Inventor.BrowserNode = oTopBrowserNode.BrowserNodes("Blad:1")
        Dim oListOfSelectedBrowserNodeNames As New List(Of String)

        For Each oViewBrowserNode As Inventor.BrowserNode In oBladBrowserNode.BrowserNodes
            'select first view
            If oViewBrowserNode.FullPath.Contains("VIEW") Then
                Dim oFirstViewBrowserNode As Inventor.BrowserNode = oViewBrowserNode
                For Each oAsmBrowserNode As Inventor.BrowserNode In oFirstViewBrowserNode.BrowserNodes
                    Dim oAsmBrowserNodeDefinition As Inventor.BrowserNodeDefinition = oAsmBrowserNode.BrowserNodeDefinition
                    If oAsmBrowserNodeDefinition.Label = assemblyName Then
                        oAsmBrowserNode.Expanded = True
                        'get selected browsernodes and set name in list
                        For Each oBrowserNode As Inventor.BrowserNode In oAsmBrowserNode.BrowserNodes
                            If oBrowserNode.Selected = True Then
                                Dim browserNodeName As String = oBrowserNode.BrowserNodeDefinition.Label
                                oListOfSelectedBrowserNodeNames.Add(browserNodeName)
                            End If
                        Next
                        Exit For
                    End If
                Next
            End If
        Next




        'loop through other views and select the same items items
        For Each oViewBrowserNode As Inventor.BrowserNode In oBladBrowserNode.BrowserNodes
            '1e view level
            If oViewBrowserNode.FullPath.Contains("VIEW") Then
                'check of view is shaded -> dan overslaan
                Dim oDrawingView As Inventor.DrawingView = oViewBrowserNode.NativeObject
                If oDrawingView.ViewStyle <> Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle Then

                    For Each oSubViewBrowserNode As Inventor.BrowserNode In oViewBrowserNode.BrowserNodes
                        '2e view level
                        If oSubViewBrowserNode.FullPath.Contains("VIEW") Then
                            For Each oSub2ViewBrowserNode As Inventor.BrowserNode In oSubViewBrowserNode.BrowserNodes
                                '3e view level
                                If oSub2ViewBrowserNode.FullPath.Contains("VIEW") Then
                                    '3e view level assembly
                                    SelectItemsInAssemblyBrowserNode(oSub2ViewBrowserNode, assemblyName, oListOfSelectedBrowserNodeNames)
                                End If
                            Next
                            '2e view level assembly
                            SelectItemsInAssemblyBrowserNode(oSubViewBrowserNode, assemblyName, oListOfSelectedBrowserNodeNames)
                        End If
                    Next
                End If
            End If
        Next

        'change layer of selected items

 

0 Likes
Message 6 of 7

Anonymous
Not applicable

Hi Brian,

 

i've made a screencast where I do this manualy!

But I need this in a program to automate this for our sales department.

 

http://autode.sk/2oDTALU

 

kind regards,

 

Geert

 

 

 

 

0 Likes
Message 7 of 7

Anonymous
Not applicable
Accepted solution

Hi,

 

i've found another approach which now is working.

Still it's a pitty i can't use the selectset to get the selected browsernodes / ComponentOccurences!

Now I loop through the  modelbrowser to find the selected browsernodes.

 

If someone has a solution to that?

 

Here is the complete VB.NETcode which i use now:

 

Cheers,

 

Geert

 

Imports System.Collections.Generic

Public Class frmLayerSynchronisation
    Private selectedLayerName As String = ""

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        Me.Text = "Layers"
        Me.Top = 0
        Me.Left = 0
        Me.Width = 200
        Me.Height = 50

        'define quantity of needed radiobuttons for all specific GREEFA layers and create them
        Dim aPanel As New UserControl
        aPanel.Top = 0
        aPanel.Left = 0
        aPanel.Width = 200
        aPanel.Height = 200
        Me.Controls.Add(aPanel)

        Dim radioButtonCounter As Integer = 0

        Dim oINVdwg As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument
        Dim lastRadioButtonTop As Integer = 0

        For Each oLayer As Inventor.Layer In oINVdwg.StylesManager.Layers
            If oLayer.Name.Contains("GREEFA") Or oLayer.Name = "0" Then
                Dim aRadioButton As New RadioButton
                aRadioButton.Text = oLayer.Name
                Dim aINVColor As Inventor.Color = oLayer.Color
                aRadioButton.ForeColor = Color.Black
                If oLayer.Name.Contains("GREEFA") Then aRadioButton.BackColor = Color.FromArgb(aINVColor.Red, aINVColor.Green, aINVColor.Blue)
                aRadioButton.Left = 5
                aRadioButton.Top = radioButtonCounter * 20
                aRadioButton.Width = 200
                aPanel.Controls.Add(aRadioButton)
                AddHandler aRadioButton.Click, AddressOf RadioButton_Clicked

                radioButtonCounter = radioButtonCounter + 1
                lastRadioButtonTop = aRadioButton.Top
                Me.Height = Me.Height + 20
            End If
        Next

        'add a command button
        Dim aCommandButton As New Button
        With aCommandButton
            .Text = "OK"
            .Left = 100
            .Top = lastRadioButtonTop + 30
            .Width = 75
            aPanel.Controls.Add(aCommandButton)
            AddHandler aCommandButton.Click, AddressOf Button_Clicked
            Me.Height = Me.Height + 20
        End With


        'collapse browser van 1e view en 1e assembly
        Dim oINVDrawingDoc As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument
        Dim oTopBrowserNode As Inventor.BrowserNode
        oTopBrowserNode = oINVDrawingDoc.BrowserPanes.ActivePane.TopNode
        Dim oBladBrowserNode As Inventor.BrowserNode = oTopBrowserNode.BrowserNodes("Blad:1")

        For Each oViewBrowserNode As Inventor.BrowserNode In oBladBrowserNode.BrowserNodes
            If oViewBrowserNode.FullPath.Contains("VIEW") Then
                For Each oAsmBrowserNode As Inventor.BrowserNode In oViewBrowserNode.BrowserNodes
                    Dim oAsmBrowserNodeDefinition As Inventor.BrowserNodeDefinition = oAsmBrowserNode.BrowserNodeDefinition
                    If oAsmBrowserNodeDefinition.Label = (Replace(oTopBrowserNode.FullPath, "dwg", "iam")) Then
                        oAsmBrowserNode.Expanded = True
                        GoTo ENDFOR
                    End If
                Next
            End If
        Next
ENDFOR:
    End Sub

    Private Sub RadioButton_Clicked(sender As Object, e As EventArgs)
        Dim oRadiobutton As RadioButton = sender

        selectedLayerName = oRadiobutton.Text
    End Sub

    Private Sub Button_Clicked(sender As Object, e As EventArgs)
        Dim oObjectCollection As Inventor.ObjectCollection = m_inventorApplication.TransientObjects.CreateObjectCollection
        Dim oINVDrawingDoc As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument

        'voer uit
        Dim oComponentOccurrencesEnumerator As Inventor.ComponentOccurrencesEnumerator = Nothing

        'loop door 1e view en assembly om de geselecteerde items vast te leggen
        Dim oTopBrowserNode As Inventor.BrowserNode
        oTopBrowserNode = oINVDrawingDoc.BrowserPanes.ActivePane.TopNode
        Dim oBladBrowserNode As Inventor.BrowserNode = oTopBrowserNode.BrowserNodes("Blad:1")
        Dim assemblyName As String = (Replace(oTopBrowserNode.FullPath, "dwg", "iam"))

        'Dim oBladBrowserNode As Inventor.BrowserNode = oTopBrowserNode.BrowserNodes("Blad:1")
        Dim oListOfSelectedBrowserNodeNames As New List(Of String)

        For Each oViewBrowserNode As Inventor.BrowserNode In oBladBrowserNode.BrowserNodes
            'select first view
            If oViewBrowserNode.FullPath.Contains("VIEW") Then
                Dim oFirstViewBrowserNode As Inventor.BrowserNode = oViewBrowserNode
                For Each oAsmBrowserNode As Inventor.BrowserNode In oFirstViewBrowserNode.BrowserNodes
                    Dim oAsmBrowserNodeDefinition As Inventor.BrowserNodeDefinition = oAsmBrowserNode.BrowserNodeDefinition
                    If oAsmBrowserNodeDefinition.Label = assemblyName Then
                        'get selected browsernodes
                        oObjectCollection = GetAllDrawingCurvesOfSelectedBrowserNodes(oAsmBrowserNode, oObjectCollection)
                        Exit For
                    End If
                Next
            End If
        Next

        Dim oSheet As Inventor.Sheet = oINVDrawingDoc.ActiveSheet
        Dim oLayer As Inventor.Layer = oINVDrawingDoc.StylesManager.Layers.Item(selectedLayerName)
        'change layer for curves collection
        Call oSheet.ChangeLayer(oObjectCollection, oLayer)
        oSheet.Update()

        Me.Close()

    End Sub

    Private Function GetAllDrawingCurvesOfSelectedBrowserNodes(ByVal oStartBrowserNode As Inventor.BrowserNode, ByVal oObjectCollection As Inventor.ObjectCollection) As Inventor.ObjectCollection
        Dim oINVDrawingDoc As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument
        Dim oSheet As Inventor.Sheet = oINVDrawingDoc.ActiveSheet

        'loop through browsernodes of startBrowserNode
        For Each oBrowserNode As Inventor.BrowserNode In oStartBrowserNode.BrowserNodes
            Try
                Dim oNativeObj As Object = oBrowserNode.NativeObject
                'Check if browsernode is of type ComponentOccurrence
                If TypeName(oNativeObj) = "ComponentOccurrence" Then
                    'check if browsernode is selected
                    If oBrowserNode.Selected = True Then
                        Try
                            'loop through all drawingviews to get all teh drawingcurves to change layer
                            For Each oDrawView As Inventor.DrawingView In oSheet.DrawingViews
                                'check if drawingView is not shaded
                                If oDrawView.ViewStyle <> Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle Then
                                    Dim oCurveEnum As Inventor.DrawingCurvesEnumerator = Nothing
                                    Try
                                        'get all the drawingcurves of selected browsernode in this drawingview
                                        oCurveEnum = oDrawView.DrawingCurves(oNativeObj)
                                    Catch
                                        Try
                                            'nested part occurrence requires another approach
                                            Dim oParentCompOcc As Inventor.ComponentOccurrence = oStartBrowserNode.NativeObject
                                            Dim oCompOccProxy As Object = Nothing
                                            Call oParentCompOcc.CreateGeometryProxy(oNativeObj, oCompOccProxy)
                                            oCurveEnum = oDrawView.DrawingCurves(oCompOccProxy)
                                        Catch

                                        End Try
                                    End Try

                                    'add segments to collection to be moved to required layer
                                    For Each oCurve As Inventor.DrawingCurve In oCurveEnum
                                        For Each oSegment As Inventor.DrawingCurveSegment In oCurve.Segments
                                            Call oObjectCollection.Add(oSegment)
                                        Next
                                    Next
                                End If
                            Next
                        Catch ex As Exception

                        End Try

                    Else    'check SubBrowserNodes
                        Call GetAllDrawingCurvesOfSelectedBrowserNodes(oBrowserNode, oObjectCollection)
                    End If
                End If
            Catch ex As Exception

            End Try
        Next

        Return oObjectCollection
    End Function

End Class
0 Likes