File Locations - How to get Macros Adress from SW VB API

'Hi

'Could any one tell me if there is an API Command, or Is there a Default Variable that holds the PATH of the Macro thats being read .

'When I move my macro from one machine to the next i have to manually change the path.

'Im thinking it would be really nice if the Macro used its own file path as a default location for accessing any attached files.

Dim MyFilePath As String

Dim MyFile As Object

MyFilePath="F:\\SWApiStudy\\SomeData.txt"

Set MyFile = GetObject(MyFilePath)

'For Example Instead of the Above Code

'Is there a command, or does the API Macro know which folder its being read from

'It would be ideal if I could simply write :

Dim MyFile As Object

Set MyFile = GetObject(SomeData.txt)

'Im sure there is some way to reference the Macro.SWP Location from the SWP or SW itself.

'Can anyone help please ?

'Thanks Matt

SolidworksApi macros
Answers 3
SF
SF 2011-03-04 Best Answer

Hi Matthew,

You can use

swApp.GetCurrentMacroPathName () API.

Thanks,

Amol

SF
SF 2011-03-04

Dim Source As String

Dim Source1 As String

Dim strTemp As String
Dim strTemp1 As String

Dim MIni As Integer

Dim MIniRoug As Integer

Public swApp As SldWorks.SldWorks

Source = swApp.GetCurrentMacroPathName             ' Get macro path+filename
Source1 = Left$(Source, Len(Source) - 3) + "txt"

' read INI or ANY text
Open Source1 For Input As #1
Line Input #1, strTemp
Line Input #1, strTemp
MIni = CInt(Left$(strTemp, 1))
Line Input #1, strTemp
MIniRoug = CInt(Left$(strTemp, 1))
Close #1

SF
SF 2011-03-04

Thanks Amol and Oleg

swApp.GetCurrentMacroPathName()

Was Perfect

Thanks

Matt