Is it possible to make macro wich generate MS Excel file with names of SW drawings (A) and referenced models (B) from directory (and subdirectories)? SW2010
Thanks for advance/
there are a few ways to make such macro. One of the ways is to use:IModelDoc2 : GetDependencies2 or swApp:GetDocumentDependencies2It will allow to get referenced to drawing models without opening them. Hence only in a second or so you will be able recursively collect all data and output it to Excel.
Thanks for your answer, Viktor.
I want to make macro works without manually opening of drawings. How can I choose one certain directory and macro will generate excel file with names of all included drawings and referenced models?
You should be able to accomplish this without even opening a file. Take a look at GetDocumentDependencies2
This would probably be better handled with Document Manager API, if you want it to run as fast as possible.
SolidWorks API Training and Services
Viktor, Matt thanks for your answers.
Now I can get dependences for open or not open drawing.
' Name of unopened document
Const sDefaultName As String = "C:\Dwg 1.SLDDRW"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sDocName As String
Dim vDepend As Variant
Dim bRet As Boolean
Dim i As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
sDocName = swModel.GetPathName
sDocName = sDefaultName
vDepend = swApp.GetDocumentDependencies2(sDocName, True, True, False)
If IsEmpty(vDepend) Then
Debug.Print " No dependencies."
For i = 0 To (UBound(vDepend) - 1) / 2
Debug.Print " " + vDepend(2 * i) + " --> " + vDepend(2 * i + 1)
MsgBox "Ìîäåëü" + ": " + vDepend(2 * i) + " --> " + vDepend(2 * i + 1)
Now I need to get this data for all drawings from one directory and subdirectories and output it to excel file.
How can I do this?
Maybe anyone have an example for similar task?
I have an excel vba macro to make open directory dialog (choose directory) but this code doesnt work in SW
.Title = "Âûáåðèòå ïàïêó èëè äèñê"
On Error Resume Next
V = .SelectedItems(1)
If Err.Number <> 0 Then
MsgBox "Âû íè÷åãî íå âûáðàëè!"
BrowseFolder = CStr(V)
I modify macro and now it get drawing dependencies and output it to excel file.
Const sDefaultName As String = "C:\dwg1.SLDDRW"
Dim sTitle As String
Dim xlApp As Excel.Application
Dim xlBk As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim curCol As Long
Dim curRow As Long
vDepend = swApp.GetDocumentDependencies2(sDocName, False, True, False)
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlBk = xlApp.Workbooks.Add
Set xlSht = xlBk.Worksheets(1)
xlSht.Cells(1, 1).Value = "Drawing"
xlSht.Cells(1, 2).Value = "Referenced part/assembly"
curCol = 2
curRow = 2
'xlSht.Cells(curRow, curCol).Value = vDepend(2 * i)
'curCol = curCol + 1
xlSht.Cells(curRow, curCol).Value = vDepend(2 * i + 1)
'curCol = 2
curRow = curRow + 1
Now I need to make possibility to select folder and get dependencies for all drawings in folder and subfolders and output it to excel.
Tell me please, how can I do this?
please look at the attached example how to browse to folder via VBA
Thanks for you answre and example.
Maybe you have any example how to choose step by step every slddrw in folder and subfolders?
Thanks for your help. I use GetDocumentDependencies2 and made macro runs from Excel (it was easy to me make to choosing folder and work with all drawing files in this folder and subfolder).
Keith, Matt, thanks for your help.
Retrieving data ...