Iterate script for all assemblies using vba

Iterate script for all assemblies using vba

k14348
Advocate Advocate
491 Views
3 Replies
Message 1 of 4

Iterate script for all assemblies using vba

k14348
Advocate
Advocate

Hi all,

       I have 10 No. of iam files in a folder. I want to iterate bom structure enabled in all assemblies. I have written some code which need to be corrected. Can anybody help?

 

Regards,

Karth

 

Sub IterateBomEnable()
    
    Dim oPath As String
    oPath = "C:\Users\KTest\"
    
    Dim oFileName As String
    oFileName = Dir(oPath & "*.iam")
    
    Do While oFileName <> ""
        Debug.Print "Processing " & oPath & oFileName
        oFileName = Dir
    Loop
For Each oFileName In ???
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.Documents.Open("oFileName")
    
    Dim oBom As BOM
    Set oBom = oAsmDoc.ComponentDefinition.BOM
    oBom.StructuredViewEnabled = True
    oBom.PartsOnlyViewEnabled = True
Next
    
End Sub

 

0 Likes
Accepted solutions (2)
492 Views
3 Replies
Replies (3)
Message 2 of 4

fullevent
Advisor
Advisor
Accepted solution

Hello @k14348 

 

maybe should do what you want.

 

Private Sub IterateBomEnable()

    Dim objFileSystem As Object
    Dim objVerzeichnis As Object
    Dim objDateienliste As Object
    Dim objDatei As Object
    
    Set objFileSystem = CreateObject("scripting.FileSystemObject")
    Set objVerzeichnis = objFileSystem.GetFolder("C:\Users\KTest\")
    Set objDateienliste = objVerzeichnis.Files
	
    For Each objDatei In objDateienliste
	
		If Not objDatei Is Nothing and instr(objdatei.Name,".iam") > 1 Then
			Dim oAsmDoc As AssemblyDocument
			Set oAsmDoc = ThisApplication.Documents.Open(objdatei.path)
			Dim oBom As BOM
			Set oBom = oAsmDoc.ComponentDefinition.BOM
			oBom.StructuredViewEnabled = True
			oBom.PartsOnlyViewEnabled = True
		end if
    Next objDatei
    
End Sub

 

regards,

Aleks


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 3 of 4

k14348
Advocate
Advocate

Hi,

Is there any option to check iam files in subfolders also?

 

Thanks,

Karth

0 Likes
Message 4 of 4

fullevent
Advisor
Advisor
Accepted solution

Hello @k14348,

 

sure.. try this:

 

Private Sub IAMs_all_Folders()
    Dim Start_Path As String
    Start_Path = "C:\Users\KTest\"    ' Start Folder
    IAMs_aus_Ordner_laden Start_Path
    
End Sub

Private Sub IAMs_aus_Ordner_laden(sPath As String)

    Dim objFileSystem As Object
    Dim objVerzeichnis As Object
    Dim objDateienliste As Object
    Dim objDatei As Object
    Dim SubFolders As Object
    Dim SubFolder As Object
    
    Set objFileSystem = CreateObject("scripting.FileSystemObject")
    Set objVerzeichnis = objFileSystem.GetFolder(sPath)
    Set objDateienliste = objVerzeichnis.Files
    Set SubFolders = objVerzeichnis.SubFolders
    
    For Each objDatei In objDateienliste
    
        If Not objDatei Is Nothing And InStr(objDatei.Name, ".iam") > 1 Then
            Dim oAsmDoc As AssemblyDocument
            Set oAsmDoc = ThisApplication.Documents.Open(objDatei.FullFileName)
            Dim oBom As BOM
            Set oBom = oAsmDoc.ComponentDefinition.BOM
            oBom.StructuredViewEnabled = True
            oBom.PartsOnlyViewEnabled = True
        End If
    Next objDatei
    For Each SubFolder In SubFolders
        IAMs_aus_Ordner_laden (SubFolder.path)
    Next SubFolder
End Sub

I hope this helps you.

 

Greetings

 


Aleksandar Krstic
Produkt- und Projektmanager