This is a simple automation technique if you need to switch to your SolidWorks assembly when you have a drawing open. This technique can be used if you need to get to the custom properties or custom info. I use this technique within other macros and not on its own. There are many different ways of doing this, but I thought I would give you an example to play around with. Go ahead and test it on it's own if you like.
You can only use this macro if the name of your assembly and drawing have been saved with same name and in the same folder.
Please click on the panel below to reveal or hide the macro code
Preconditions: Make sure a drawing is open. ' You need to add references for: ' SolidWorks 20xx Type Library ' SolidWorks 20xx Constant Type Library Sub ActivateAssembly() On Error GoTo ErrH: Dim swApp As SldWorks.SldWorks Dim swModeldoc As SldWorks.ModelDoc2 Dim swDrawDoc As String Dim swAssDoc As String Dim nretval As Long ' Connect to SW Set swApp = Application.SldWorks ' Get active document Set swModeldoc = swApp.ActiveDoc ' Get full path of active document swDrawDoc = swModeldoc.GetPathName ' Take off file extension swDrawDoc = VBA.Left(swDrawDoc, Len(swDrawDoc) - 6) ' Add assembly file extension swAssDoc = swDrawDoc + "SLDASM" ' Switch to assembly swApp.ActivateDoc2 swAssDoc, False, nretval ErrH: If Err.Number = 0 Or Err.Number = 20 Then Err.Clear Resume Next Else MsgBox "<<< ActivateAssembly >>> " & Err.Number & " " & Err.Description, vbCritical, "Error" End If End Sub
This site is now a responsive website. Please follow the link to find out more.
I would be grateful for any feedback regarding this site or comments regarding the macros that I have uploaded.