Anyone have a macro that allows you to open ALL drawings of subassemblies and parts from a main assembly? The drawings have the same no as its reference.
Hello
Try the following:
Option Explicit
Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.ModelDoc2
Dim Assembly As ModelDoc2
Dim myAssy As AssemblyDoc
Dim fileerror As Long
Dim filewarning As Long
Dim i As Long
Dim nRetval As Long
Dim myCmps As Variant
Dim myCmp As Component2
Dim myName As String
Sub main()
Set swApp = Application.SldWorks
Set Assembly = swApp.ActiveDoc
Set myAssy = Assembly
myCmps = myAssy.GetComponents(False)
For i = 0 To UBound(myCmps)
Set myCmp = myCmps(i)
Set swModel = myCmp.GetModelDoc2
myName = swModel.GetPathName
myName = Left(myName, (Len(myName) - 7)) & ".slddrw"
Set swDraw = swApp.OpenDoc6(myName, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_Silent, "", fileerror, filewarning)
myAssy.EditAssembly
Next i
Set Assembly = swApp.ActivateDoc2(myAssy.GetPathName, True, nRetval)
MsgBox "Traitement terminé", vbExclamation
End Sub
Kind regards
3 Likes
Hello;
I have a little question for Our Doctor S Macro d.roger nationnal.
Why did you choose to populate your "myName" variable with "=swmodel.getplathName"
rather than with "= myCmps(i). GetPathName"?
I don't understand this choice.
On the other hand, the rest is as usual, simple, precise, effective.... Well done.
Kind regards.
1 Like