Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic, Work with parts only in specific folders in Assembly tree

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
mgasser8SSYT
241 Views, 6 Replies

iLogic, Work with parts only in specific folders in Assembly tree

Hello Everyone

 

I like to change the suppression on specific files in a folder within a assembly tree.
I realized it without folder and it works fine. Now I have two Folders with nearly same content and want to unsuppress a specific part in folder "Mast1" and a different part in folder "Mast2" . We get the specific component name from the Parameter Table in the Parameters "Mast1Nr" and "Mast2Nr". How do I realize that? 
(The early working code I coded [without folders] is attached)

Labels (3)
6 REPLIES 6
Message 2 of 7
A.Acheson
in reply to: mgasser8SSYT

Hi see helpful article here. 

 

Code is from the link. Adjust as needed. 

 

Sub Main()
  Dim oDoc As AssemblyDocument
  oDoc = ThisApplication.ActiveDocument
    
  Dim oPane As BrowserPane
  oPane = oDoc.BrowserPanes("Model")
  
  Dim oTopNode As BrowserNode
  oTopNode = oPane.TopNode
    
  Dim oFolder As BrowserFolder
  oFolder = oTopNode.BrowserFolders.Item("MyFolder")
  
  Call SuppressFolder(oFolder)
End Sub

' Recursive function as there could be subfolders too
Sub SuppressFolder(oFolder As BrowserFolder)
  Dim oItem As BrowserNode
  For Each oItem In oFolder.BrowserNode.BrowserNodes
    Dim oObj As Object
    oObj = oItem.NativeObject
    
    If TypeOf oObj Is BrowserFolder Then
      Call SuppressFolder(oObj)
    ElseIf TypeOf oObj Is ComponentOccurrence Then
      Dim oOcc As ComponentOccurrence
      oOcc = oObj
      
      If Not oOcc.Suppressed Then Call oOcc.Suppress
    ElseIf TypeOf oObj Is OccurrencePattern Then
      Dim oPatt As OccurrencePattern
      oPatt = oObj
      
      Dim oElem As OccurrencePatternElement
      For Each oElem In oPatt.OccurrencePatternElements
        For Each oOcc In oElem.Occurrences
          If Not oOcc.Suppressed Then Call oOcc.Suppress
        Next
      Next
    End If
  Next
End Sub

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7
mgasser8SSYT
in reply to: mgasser8SSYT

Thank you.
First you have to know I'm a newbie on coding in Inventor. I'm programming the code as rule direct in iLogic. 
But I think the problem is exactly what ist described in the article you posted. The thing is, I do not understand how to "set the Embed Interop Type to False".
I opened the VBA-Editor (with alt + F11) but the code window is empty and I can't find any parameter called "autodesk.inventor.interop" parameter.

How do I proceed to solve the Problem?

Message 4 of 7
A.Acheson
in reply to: mgasser8SSYT

The posted code is for the ilogic editor which uses ilogic (iLogic API) and VB.Net language. You have the VBA editor open which will use VBA language. In any case theat article has both VBA and ilogic code so you can choose.  

 

If your new to coding I would suggest you start with ilogic as this will give you the most help on the forum, and will allow you to use ilogic snippets directly so can generate less complicated code for non skilled users. 

 

On the use of VBA it has less presence on the forums and it can be very rigid for new users. although the Inventor help samples are written in VBA they can be switched over to VB.Net relatively easily. 

 

In my case I learned ilogic first and learned VBA indirectly so I could understand the conversions between the two. 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 7
mgasser8SSYT
in reply to: A.Acheson

Thanks.
I tried your posted code. It works but. It manipulates the hole Folder and not only the specific component within the folder. Sadly I can't imagine how to change the code for specific component manipulation within a folder.

I tried with help from Chat-GPT which work surprisingly good but not for this specific Problem.
In a further step i like to use "changerow" for an other specific component in the same folder.

 

Added 14:31
I think I got it. Now I changed your code as in the attached File. 

 

(How do I post the code that it looks the way it looks in your post?)

Message 6 of 7
mgasser8SSYT
in reply to: mgasser8SSYT

Yes. I got the Code that works for me.
In the Folder "Mast1" are 4 different Masts but Only one Mast should be displayed.
Which Mast has to be displayed is defined in the parameter table ("fx" in Inventor)

So here my final code: 

Edit 07-25-2024:

 

'┌────────────────────────────────────────────────────────────────┐
'│    Header Start                                                │
'│    Alle notwendigen Parameter werden hier definiert            │
'└────────────────────────────────────────────────────────────────┘
Sub Main()
    ' Header mit allen Parameter Definitionen
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oPane As BrowserPane
    oPane = oDoc.BrowserPanes("Modell")
    
    Dim oTopNode As BrowserNode
    oTopNode = oPane.TopNode
    
    Dim oFolder As BrowserFolder
    oFolder = oTopNode.BrowserFolders.Item("Mast1")
    
    ' Liste der spezifischen Komponenten, die unterdrückt werden sollen (nur die ersten 9 Ziffern)
    Dim componentsToSuppress() As String
    componentsToSuppress = Split("328.00241,328.00272,328.00274,328.00267", ",")
    
    ' Teil, in dem die Komponenten unterdrückt werden
    Call SuppressComponents(oFolder, componentsToSuppress)
    
    ' Teil, in dem für die spezifische Komponente die Unterdrückung aufgehoben wird
    Call UnsuppressComponent(oFolder, Mast1_ZNummer)
End Sub

'┌────────────────────────────────────────────────────────────────┐
'│    Header End                                                  │
'└────────────────────────────────────────────────────────────────┘

'┌───────────────────────────────────────────────────────────────────┐
'│    Teil 1 Start                                                   │
'│    Komponenten im gewünschten Modellbaum-Ordner werden gesucht    │
'│    und unterdrückt.                                               │
'└───────────────────────────────────────────────────────────────────┘

' Unterdrückt die spezifischen Komponenten
Sub SuppressComponents(oFolder As BrowserFolder, componentsToSuppress() As String)
    Dim i As Integer
    For i = LBound(componentsToSuppress) To UBound(componentsToSuppress)
        Call FindAndSuppressComponent(oFolder, componentsToSuppress(i))
    Next i
End Sub

Sub FindAndSuppressComponent(oFolder As BrowserFolder, componentPrefix As String)
    Dim oItem As BrowserNode
    For Each oItem In oFolder.BrowserNode.BrowserNodes
        Dim oObj As Object
        oObj = oItem.NativeObject
        
        If TypeOf oObj Is BrowserFolder Then
            ' Rekursiver Aufruf, um in Unterordnern zu suchen
            Call FindAndSuppressComponent(oObj, componentPrefix)
        ElseIf TypeOf oObj Is ComponentOccurrence Then
            Dim oOcc As ComponentOccurrence
            oOcc = oObj
            
            ' Überprüfen, ob die ersten neun Ziffern übereinstimmen
            If Left(oOcc.Name, 9) = componentPrefix Then
                ' Unterdrücke die Komponente
                If Not oOcc.Suppressed Then
                    Call oOcc.Suppress
                    ' Debug-Meldung, um zu überprüfen, ob die Komponente unterdrückt wurde
                    'MsgBox ("Komponente '" & oOcc.Name & "' gefunden und wird unterdrückt!")
                End If
            End If
        End If
    Next
End Sub

'┌────────────────────────────────────────────────────────────────┐
'│    Teil 1 End                                                  │
'└────────────────────────────────────────────────────────────────┘

'┌──────────────────────────────────────────────────────────────────────┐
'│    Teil 2 Start                                                      │
'│    Komponenten im gewünschten Modellbaum-Ordner wird das             │
'│    Bauteil gem Parameter gesucht und die Unterdrückung aufgehoben    │
'└──────────────────────────────────────────────────────────────────────┘

' Hebt die Unterdrückung für die spezifische Komponente basierend auf dem Parameterwert auf
Sub UnsuppressComponent(oFolder As BrowserFolder, componentPrefix As String)
    Dim oItem As BrowserNode
    For Each oItem In oFolder.BrowserNode.BrowserNodes
        Dim oObj As Object
        oObj = oItem.NativeObject
        
        If TypeOf oObj Is BrowserFolder Then
            ' Rekursiver Aufruf, um in Unterordnern zu suchen
            Call UnsuppressComponent(oObj, componentPrefix)
        ElseIf TypeOf oObj Is ComponentOccurrence Then
            Dim oOcc As ComponentOccurrence
            oOcc = oObj
            
            ' Überprüfen, ob die ersten neun Ziffern übereinstimmen
            If Left(oOcc.Name, 9) = componentPrefix Then
                ' Hebe die Unterdrückung der Komponente auf
                If oOcc.Suppressed Then
                    Call oOcc.Unsuppress
                    MsgBox ("Unterdrückung der Komponente '" & oOcc.Name & "' wird aufgehoben!")
                End If
            End If
        End If
    Next
End Sub

'┌────────────────────────────────────────────────────────────────┐
'│    Teil 2 End                                                  │
'└────────────────────────────────────────────────────────────────┘

 

Tags (1)
Message 7 of 7
A.Acheson
in reply to: mgasser8SSYT

Hi @mgasser8SSYT 

See below screenshots

AAcheson_0-1721404649480.pngAAcheson_1-1721404666766.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report