How to get BrowserPane Display Name from iLogic VB.NET

How to get BrowserPane Display Name from iLogic VB.NET

shiftctrl.io
Enthusiast Enthusiast
1,627 Views
8 Replies
Message 1 of 9

How to get BrowserPane Display Name from iLogic VB.NET

shiftctrl.io
Enthusiast
Enthusiast

Hi everyone,

 

I'm new to iLogic API / .NET and trying to write a function which will create an ArrayList of the all parts that match a User Parameter Name/Value. I'm trying to get the component name as shown in the browser pane, however what I get is the file name. Secondly, the list only contains components which are not suppressed... I actually need to build a list containing all components irrespective of their suppression state, so long as they meet the requirement of containing a specified User Parameter Name and Value

 

Any help is greatly appreciated. 

 

I'm running Inventor Pro 2021.

 

Thank you.

 

 

Public Function ListByUserParam(ParameterName,ParameterValue)
    Dim AssyDoc As AssemblyDocument
    AssyDoc = ThisApplication.ActiveDocument

    Dim ArrayListObject As New ArrayList
    Dim Doc As Document    

    For Each Doc In AssyDoc.AllReferencedDocuments
        
        Dim CompDef As ComponentDefinition 
        CompDef = Doc.ComponentDefinition

        Dim UserParams As UserParameters 
        UserParams = CompDef.Parameters.UserParameters
        
        Try 
            UserParamItem = UserParams.Item(ParameterName)
            UserParamValue = UserParamItem.Value
            If CStr(UserParamValue) = ParameterValue
                Dim DisplayName As String
                DisplayName = CStr(Doc.DisplayName)
                DisplayName = Left(DisplayName,Len(DisplayName)-4)
                ArrayListObject.Add(DisplayName)
            End If
        Catch
        End Try
    Next

    Return ArrayListObject

End Function

 

 

0 Likes
Accepted solutions (1)
1,628 Views
8 Replies
Replies (8)
Message 2 of 9

_dscholtes_
Advocate
Advocate

A suppressed component is (treated as) not loaded, so Inventor will not put it in the AllReferencedDocument list.
Since your macro processes documents (defining a component) and not the model browser tree, you will end up with the names of the documents and not the names from the model tree.

A good article about accessing assembly components (by document and by model browser) can be found here

Message 3 of 9

WCrihfield
Mentor
Mentor

Another way to get to all components without iterating through the same ones several times, is accessing them through the BOM's Model Data View.  Each component will be listed one time, then have a quantity.  They will still appear here even if you suppress them, but they won't show up in the Structured View.

 

I usually advise against using Suppress and Level Of Detail Representations, when not necessary, as they often cause more headache than their worth.  I instead advise to use Visibility and Design View Representations.

  • LOD rep's are mainly just used for performance purposes, to conserve system/session memory, since suppressed items don't actually fully load.
  • DV rep's are normally all that is needed, and they will also work directly with drawing view filters.

If you don't want a component to be counted as a normal component within the BOM, you should most likely switch the component's BOM Structure from (Default) Normal to Reference.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 9

WCrihfield
Mentor
Mentor

And to answer the question posed within the title of this post, here is a simple iLogic rule that should show you the names and internal names of the available browser panes.

Dim oDoc As Document = ThisApplication.ActiveDocument
For Each oBPane As BrowserPane In oDoc.BrowserPanes
	MsgBox("Browser Pane's Name = " & oBPane.Name & vbCrLf & _
	"It's Internal Name = " & oBPane.InternalName, vbOKOnly, "BROWSER PANE NAMES")
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 9

shiftctrl.io
Enthusiast
Enthusiast

@WCrihfield Thank you for the ideas and the sample code.

 

I should have elaborated my intent in case you may have other ideas to share. 

 

I'm currently working on a "Product Generator" which assembles components; un- / suppresses parts; changes panel dimensions / material, etc. At first I was under the impression that suppressed parts are not counted in the BOM, however I checked after reading your response and see them there as a normal part. Which is something I will need to address. 

 

My Assembly is comprised of many parts/ iParts/ iAssemblies. Some parts were renamed within the browser though still have their original filenames (member/part names), the renaming was done so that I would be able to use the names as flags for iLogic to loop through parts and build lists.  The problem I'm having right now is with iParts and iAssemblies. I can't rename the actual files as they are part of a larger data structure used within the company, I've tried to fetch names using the LeafOccurance, but i still end up with the file (or member/part) name and not the name which I've renamed the components to. 

 

So my questions:

 

Is there a way to get the names of components directly from the browser (as I've renamed them)?

 

What is the drawback of using Suppression  vs Visibility? If there is a performance boost, wouldn't that be reason to stick with suppressing items?

 

Thank you for your help.

0 Likes
Message 6 of 9

shiftctrl.io
Enthusiast
Enthusiast

Thanks, this article really helped!

0 Likes
Message 7 of 9

shiftctrl.io
Enthusiast
Enthusiast
Accepted solution

After some messing around I finally managed to make a script that works. 

 

I'm posting it here for anyone whom may be in need of it in the future.

 

The code below will populate an ArrayList with all components as labeled in your browser (Including suppressed items) which you can then filter out as needed. 

 

I'm made this script to control a Product Configurator  (AKA Generator) suppression state via an ArrayList. Hope this helps someone. 

 

Sub Main()
    Dim PartsList As New ArrayList
    PartsList = CreatePartsList()
    For Each Part In PartsList
        MessageBox.Show(Part)
    Next
    Break
End Sub

Public Function CreatePartsList() As ArrayList
    Dim AssyDoc As AssemblyDocument
    AssyDoc = ThisApplication.ActiveDocument

    Dim AssyDef As AssemblyComponentDefinition
    AssyDef = AssyDoc.ComponentDefinition

    Dim ActivePane As BrowserPane
    ActivePane = AssyDoc.BrowserPanes.ActivePane

    Dim PartsList As New ArrayList

    Dim CompOcc As ComponentOccurrence
    For Each CompOcc In AssyDef.Occurrences

        Dim CompOccNode As BrowserNode
        CompOccNode = ActivePane.GetBrowserNodeFromObject(CompOcc)

        Dim NodeLabel As String
        NodeLabel = CompOccNode.BrowserNodeDefinition.Label.ToString()

        PartsList.Add(NodeLabel) 
    Next
    Return PartsList
End Function

 

Message 8 of 9

WCrihfield
Mentor
Mentor

Glad to see that you found a solution.

 

I guess saying that I 'advise against' using LODs is too harsh, since I have used them myself, but just in rare occasions, where I'm dealing with either very large assemblies, or models that I know will slow my system down when loaded.  I actually started out using the LOD's somewhat heavily years ago, but have since gotten away from that practice, since I could do so much more with DVR's (Design View Representation), and wasn't seeing a lot of benefit from using the LOD's anymore.

 

It sounds like your assembly may be fairly complex, so it might not be a bad idea for your situation.  When I do use them though, I usually try to also create matching DVR's & LOD's, and try to use both at the same time.  Since there isn't really a good way to truly 'link' a design view rep to a LOD rep, it's just a lot more work to use them both, especially through programming.

Also:

I'm not sure if you ever use the 'filter' functionality of Parts Lists in your assembly drawings, but it can be very useful, and only works with assembly View Representations, and not LOD's.  When you edit your Parts List (within a drawing for an assembly), there is a Filter tool, third from top left in that dialog box.  When you click it, then check the box beside 'Filter', you can choose 'Assembly View Representation' from the list.  Once you've done that, you can choose a View Rep from the new list of available ones that appear for that assembly.  Then you can also check the option to 'Limit QTY to visible components only'.  This isn't the same as choosing the View rep from the View Editor dialog, as that doesn't affect the Parts List.  Also, the 'visible only' option isn't just talking about what items can be seen in a specific drawing view, it is talking about what items are set as Visible or not within the View Rep.  So I take advantage of this useful ability fairly often.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9

maxim.teleguz
Advocate
Advocate

here is a better solution:


c = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select component")

If c Is Nothing Then
	Exit Sub
Else
	'get displayed string since that is what some content center parts show as.
	Dim originalString As String = c.name
	Dim symbol As String = ":"
	' Find the position of the symbol
	Dim indexOfSymbol As Integer = originalString.IndexOf(symbol)
	
	' Check if the symbol is present in the string
	If indexOfSymbol <> -1 Then
	    ' Extract the portion of the string before the symbol
	    Dim resultString As String = originalString.Substring(0, indexOfSymbol)
	    'MsgBox(resultString)
		f = resultString
	Else
	    ' Symbol not found in the string
	    'MsgBox("Symbol not found in the string.")
	End If
End If
0 Likes