Read Browser Folder Name if 'RE' then suppress

Read Browser Folder Name if 'RE' then suppress

andrew_canfield
Collaborator Collaborator
838 Views
4 Replies
Message 1 of 5

Read Browser Folder Name if 'RE' then suppress

andrew_canfield
Collaborator
Collaborator

Can the browser folder name be read?

I found some code to iterate but identifying the folders is challenging.

I guess it's the folder contents to suppress & not the folder.

If folder name string starts 're' then suppress, next

Is the basic idea.

 

Browser Folder.JPG

 

 

Regards

 

Andrew

0 Likes
Accepted solutions (1)
839 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

hi

this code uses the recursive function "SuppressRefFolders" to find all folders that contain the text "ref" and suppress all content with the recursive function "SuppressFolder".

In the screen shot i saw that you also wanted to suppress folders in sub assemblys. that is dificult to do because you then also need to set the "Level of Detail". i wrote also code to suppress foders in subassemblys but i did not write code to set the level of detail. (there for i commented out this part of the code.)

[iLogic]

Sub Main()
	Dim doc As AssemblyDocument = ThisDoc.Document
	SuppressRefFolders(doc.BrowserPanes("Model").TopNode)
End Sub

Sub SuppressRefFolders(topNode As BrowserNode)
    For Each node As BrowserNode In topNode.BrowserNodes
        If (TypeOf node.NativeObject Is BrowserFolder) Then
            If (node.BrowserNodeDefinition.Label.ToUpper().Contains("REF")) Then
                SuppressFolder(node.NativeObject)
            Else
                SuppressRefFolders(node)
            End If
            'ElseIf (TypeOf node.NativeObject Is ComponentOccurrence) Then
            '    Dim oOcc As ComponentOccurrence = node.NativeObject
            '    If (oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
            '        Dim refDoc As AssemblyDocument = ThisApplication.Documents.Open(oOcc.ReferencedFileDescriptor.FullFileName)
            '        SuppressRefFolders(refDoc.BrowserPanes("Model").TopNode)
            '        refDoc.Save()
            '        refDoc.Close(True)
            '        Console.WriteLine(node.BrowserNodeDefinition.Label)
            '    End If
        End If
    Next
End Sub

Sub SuppressFolder(oFolder As BrowserFolder)
    Dim oItem As BrowserNode
    For Each oItem In oFolder.BrowserNode.BrowserNodes
        Dim oObj As Object = oItem.NativeObject

        If TypeOf oObj Is BrowserFolder Then
            Call SuppressFolder(oObj)
        ElseIf TypeOf oObj Is ComponentOccurrence Then
            Dim oOcc As ComponentOccurrence = oObj
            If Not oOcc.Suppressed Then Call oOcc.Suppress()
        ElseIf TypeOf oObj Is OccurrencePattern Then
            Dim oPatt As OccurrencePattern = oObj
            For Each oElem As OccurrencePatternElement In oPatt.OccurrencePatternElements
                For Each oOcc In oElem.Occurrences
                    If Not oOcc.Suppressed Then Call oOcc.Suppress
                Next
            Next
        End If
    Next
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

andrew_canfield
Collaborator
Collaborator

Thankyou for this, I've been searching for a while.

 

It's in the sub assemblies where the majority of the references need to be suppressed - the assembly template holds a LOD called 'Simple without REF'. (this will be available in all assemblies)

 

Unchecking your commented code & setting the LoD to 'Simple without REF' - then unsuppressing part 2 ref to test - I can't re suppress the sub assembly reference (part 2 ref). The test assembly has been uploaded to drive - the link is:

https://autode.sk/327o9Jp

 

Editing the LoD's wasn't straight forward, they had to be done individually & re saved,  i guess if it's hard work manually it's trickier with code.

Thanks again for taking the time , it's more complicated than i thought.

 

Regards

 

Andrew

 

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

hi,

i gave it some more time and updated the code. it now updates also subassblys. (i could not download your test assembly so i did not test it with your example) If the LoD is not there it will create it. Also it will set the LoD in the assembly and sub assembly occurences. Have a look at it.

Sub Main()
	Dim doc As AssemblyDocument = ThisDoc.Document
	SuppressRefFolders(doc.BrowserPanes("Model").TopNode)
End Sub

Sub SuppressRefFolders(topNode As BrowserNode)
    Dim ThisApplication As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
    For Each node As BrowserNode In topNode.BrowserNodes
        If (TypeOf node.NativeObject Is BrowserFolder) Then
            If (node.BrowserNodeDefinition.Label.ToUpper().Contains("REF")) Then
                SuppressFolder(node.NativeObject)
            Else
                SuppressRefFolders(node)
            End If
        ElseIf (TypeOf node.NativeObject Is ComponentOccurrence) Then
            Dim oOcc As ComponentOccurrence = node.NativeObject
            If (oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
                Dim refDoc As AssemblyDocument = ThisApplication.Documents.Open(oOcc.ReferencedFileDescriptor.FullFileName)
                Dim lodReps As LevelOfDetailRepresentations = refDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations
                Dim lodRep As LevelOfDetailRepresentation = getDesignViewRep(lodReps, "REF")
                If (lodRep Is Nothing) Then
                    lodReps.Add("REF")
                Else
                    lodRep.Activate()
                End If

                SuppressRefFolders(refDoc.BrowserPanes("Model").TopNode)

                refDoc.Save()
                refDoc.Close(True)
                oOcc.SetLevelOfDetailRepresentation("REF")
            End If
        End If
    Next
End Sub

Function getDesignViewRep(lodReps As LevelOfDetailRepresentations, name As String) As LevelOfDetailRepresentation
    For Each designViewRep As LevelOfDetailRepresentation In lodReps
        If (designViewRep.Name.Equals(name)) Then
            Return designViewRep
        End If
    Next
    Return Nothing
End Function

Sub SuppressFolder(oFolder As BrowserFolder)
    Dim oItem As BrowserNode
    For Each oItem In oFolder.BrowserNode.BrowserNodes
        Dim oObj As Object = oItem.NativeObject

        If TypeOf oObj Is BrowserFolder Then
            Call SuppressFolder(oObj)
        ElseIf TypeOf oObj Is ComponentOccurrence Then
            Dim oOcc As ComponentOccurrence = oObj
            If Not oOcc.Suppressed Then Call oOcc.Suppress()
        ElseIf TypeOf oObj Is OccurrencePattern Then
            Dim oPatt As OccurrencePattern = oObj
            For Each oElem As OccurrencePatternElement In oPatt.OccurrencePatternElements
                For Each oOcc In oElem.Occurrences
                    If Not oOcc.Suppressed Then Call oOcc.Suppress
                Next
            Next
        End If
    Next
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 5

Charlies_3D_T
Advocate
Advocate

@JelteDeJong 

 

One question. Is there an option to add a command that it unsuppresses the folder also? I want a simple code that supresses all parts inside the folder and sub folders and if i want i can unsupress them also. 

 

If so could you point me in the correct direction? 

 

Thank you!

0 Likes