VBA 64bit support

<< Click to Display Table of Contents >>

Navigation:  CAD/Application Integrations > SolidWorks addin >

VBA 64bit support

Solidworks VBA x64 macro

images_icons_SW16Solidworks users only

Introduction

DBWorks supports the VBA 64 bit introduced in Solidworks 2013 through the usage of the native API available for 32/64 bit platform.
To access the native API, an instance of the Initialize object must be created and connected to the running DBWorks:

Set mwApi = CreateObject("MwPDMApi.Initialize")

Set mwDBWAppl = mwApi.StartConnection(DBWorksApplicationName) 'DBWorks

and, after computation, it must be disconnected as follow:

Set mwDBWAppl = Nothing

mwApi.EndConnection

Below there are some examples to show the migration from SW 2012 to SW 2013 VBA code.

Connection parameters

SW 2012: MWscriptGUI

Set mwscriptguiObj = CreateObject("mwscriptgui.DBWPar")

DBWorksInstallationDirectory = mwscriptguiObj.DBWorksInstallationDirectory

DBWorksConnectionDSN = mwscriptguiObj.getDBWorksDsn()
Set mwscriptguiObj = Nothing
'
Set mwscriptguiObj = CreateObject("mwscriptgui.DBWConnpar")
DBWorksConnectionUID = mwscriptguiObj.GetParameter("DBWORKS_UID")
DBWorksConnectionPWD = mwscriptguiObj.GetParameter("DBWORKS_PWD")
Set mwscriptguiObj = Nothing

SW 2013: Native API

DBWorksInstallationDirectory = mwDBWAppl.PDMSystem.GetInstallationPath

DBWorksConnectionDSN = mwDBWAppl.PDMSystem.GetEnvironment("DBWorksConnectionDSN")

DBWorksConnectionUID = mwDBWAppl.PDMSystem.GetEnvironment("DBWorksConnectionUID")
DBWorksConnectionPWD = mwDBWAppl.PDMSystem.GetEnvironment("DBWorksConnectionPWD")

File selection

SW 2012: MWscriptGUI

Set parameters = CreateObject("MWScriptGUI.DBWPar")

DBWorks_par_dir = parameters.parameter("PAR_DIR")

DBWBOM_PAR.Caption = DBWSelectFile(DBWorks_par_dir, "Text (*.txt)|*.txt")

SW 2013: Native API

DBWorks_par_dir = mwDBWAppl.Options.GetOptionByName("PAR_DIR")

DBWBOM_PAR.Caption = mwDBWAppl.UserInterface.SelectFile(DBWorks_par_dir,"Text (*.txt)|*.txt")

BOM generation

SW 2012: MWscriptGUI

bomFile = ExcelBOM2(BomP_uid, DBWBOM_PAR.Caption, "")

SW 2013: Native API

bomFile = mwDBWAppl.BOM.ExcelBOM(BomP_uid, DBWBOM_PAR.Caption, "")

Please refer to .NET API for more information about the provided DBWorks API native Object Model.