Message 1 of 2
Copy idws of main assembly and all regarding subassemblies to one folder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to copy idws of main assembly and all regarding subassemblies into one folder. Idw for assembly are saved in extra folder, which is in project folder. I made rule which copy only file only from Library.
Sub Main() ' Define the target folder where all .idw files will be copied Dim targetFolder As String = "C:\Users\damjan\Desktop\Nova mapa" ' Ensure the target folder exists If Not System.IO.Directory.Exists(targetFolder) Then System.IO.Directory.CreateDirectory(targetFolder) End If ' Start the process with the current assembly CopyIDWFiles(ThisDoc.Document, targetFolder) MsgBox("All .idw files have been copied to: " & vbLf & targetFolder) End Sub ' Function to recursively find and copy .idw files Sub CopyIDWFiles(document As Document, targetFolder As String) ' Check if the document has an associated drawing file Dim drawingPath As String = System.IO.Path.ChangeExtension(document.FullFileName, ".idw") If System.IO.File.Exists(drawingPath) Then ' Copy the .idw file to the target folder Dim fileName As String = System.IO.Path.GetFileName(drawingPath) Dim destinationPath As String = System.IO.Path.Combine(targetFolder, fileName) If Not System.IO.File.Exists(destinationPath) Then System.IO.File.Copy(drawingPath, destinationPath) MsgBox("Copied: " & vbLf & fileName) Else MsgBox("Skipped (already exists): " & vbLf & fileName) End If End If ' If the document is an assembly, process its subcomponents If document.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then Dim assemblyDoc As AssemblyDocument = document Dim occurrences As ComponentOccurrences = assemblyDoc.ComponentDefinition.Occurrences For Each occurrence As ComponentOccurrence In occurrences If occurrence.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Or occurrence.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then ' Recursively process subassemblies and parts CopyIDWFiles(occurrence.Definition.Document, targetFolder) End If Next End If End Sub