08-03-2023
01:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-03-2023
01:56 PM
This VBA example will open all the assemblies in a folder, and then close them. Add your DXF code where indicated.
Sub FindFilesWithComment()
sName = ThisApplication.ActiveDocument.FullFileName
Dim filesystem As Object
Set filesystem = CreateObject("Scripting.FilesystemObject")
Dim ActiveDoc As Document
Set ActiveDoc = ThisApplication.ActiveDocument
Dim FolderPath As String
FolderPath = BrowseForFolder()
If FolderPath = "" Then Exit Sub
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim oFiles As Object
Dim oFileNames As String
oFileNames = "Files with comments: " & oComment
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderPath)
For Each oFile In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "iam" Then
sFilename = FolderPath & "\" & oFile.Name
Dim oAsmDoc As AssemblyDocument
'set option to false to open invisible and run faster
Set oAsmDoc = ThisApplication.Documents.Open(sFilename, True)
MsgBox (oAsmDoc.FullFileName)
Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
'put your DXF code here
Next oRefDoc
If Not ActiveDoc Is oAsmDoc Then oAsmDoc.Close (True) 'true = skip save
End If
Next oFile
End Sub
Function BrowseForFolder(Optional OpenAt As Variant) As Variant
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0
Set ShellApp = Nothing
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select
Exit Function
Invalid:
BrowseForFolder = ""
End Function