Second slide
Generic placeholder image

How to switch to a SolidWorks assembly from a drawing. Read on...

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

Make sure a drawing is open and that you have an assembly saved with the same name and they are in the same folder. It basiccaly takes off the drawing file extension (SLDDRW) and adds the assembly file extension (SLDASM). It then uses the ActivateDoc2 to switch to the assembly
 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
   If Err.Number = 0 Or Err.Number = 20 Then
        Resume Next
        MsgBox "<<< ActivateAssembly >>> " & Err.Number & " " & Err.Description, vbCritical, "Error"
    End If

End Sub

Downloads page

This site is now a responsive website. Please follow the link to find out more.

responsive web design

I would be grateful for any feedback regarding this site or comments regarding the macros that I have uploaded.

HTML Comment Box is loading comments...