AnsweredAssumed Answered

Activate configuration that appears in drawing view, prior to saving drawing and model with custom name.

Question asked by Brian Eastman on Nov 22, 2016
Latest reply on May 9, 2017 by Quentin Torgerson

Hi,

 

I currently have a Macro that successfully opens a part from a view on a drawing, takes information from that parts data card, and uses it to save both the part and the drawing with a custom name. Unfortunately, if that part has multiple configurations it doesn't necessarily open the correct configuration before extracting the data and outputting the file. I need a way to ensure the model configuration that's active is the configuration that appears in the drawing's view.

 

The code that I currently have to get my swModel set is:

 

Sub main()

 

Dim swApp           As SldWorks.SldWorks

Dim swModel         As SldWorks.ModelDoc2

Dim swDrawModel     As SldWorks.ModelDoc2

Dim swDraw          As SldWorks.DrawingDoc

Dim swView          As SldWorks.View

Dim swConfig        As SldWorks.Configuration

Dim swConfName      As Variant

Dim BioNexPN        As String

Dim swRev           As String

Dim FilePath        As String

Dim FileName        As String

Dim PDF             As String

Dim AdobePath       As String

Dim Response        As Integer

Dim bool            As Boolean

 

'Set activive document as referenes

    Set swApp = Application.SldWorks

    Set swDrawModel = swApp.ActiveDoc

   

' Check to see if a drawing is loaded.

    If swDrawModel Is Nothing Then

        MsgBox "A released solidworks drawing must be open."

        Exit Sub

    End If

    If swDrawModel.GetType <> swDocDRAWING Then

        MsgBox "A solidworks drawing must be open and active to run this Macro."

        Exit Sub

    End If

   

'Define the OUTPUT file path

    FilePath = Left(swDrawModel.GetPathName, InStrRev((swDrawModel.GetPathName), "\")) + "OUTPUT FILES\"

 

'Check if "OUTPUT FILES" folder exists

    If FileOrDirExists(FilePath) = False Then

        MsgBox "Please create 'OUTPUT FILES' sub folder"

        Exit Sub

    End If

 

'Get referenced 3D model

    Set swDraw = swDrawModel

    Set swView = swDraw.GetFirstView

    Set swView = swView.GetNextView

    Set swModel = swView.ReferencedDocument

 

......

Outcomes