Info about macro language

Hello

 

I will need information about understanding the language of a macro.

 

I will certainly have several points to see but one by one, to start.

 

What means:

 

PathName = SWmoddoc.GetPathName
FilePath = Left(PathName, InStrRev(PathName, "\"))
FileName = Right(PathName, Len(PathName) - InStrRev(PathName, "\"))

 

if my filename is 045-2014-A.sldddrw

1 Like

Hello

 

It's VBA language:

 

The ' (apostrophes) allow you to put comments in code, which I'm going to do below (it allows you to read the code with the comments just below):

 

PathName = SWmoddoc.GetPathName

'Assigns the name of the active solidworks file on the screen in the PathName variable example "c:\FOLDER\test.slddrw"

 

FilePath = Left(PathName, InStrRev(PathName, "\"))

Assigns the file path to the FilePath variable by looking for the \ from the left, e.g . "c:\FOLDER"


FileName = Right(PathName, Len(PathName) - InStrRev(PathName, "\"))

I assign the file name to the File Name variable by looking for the \ from the right (right), e.g . "test.slddrw"

 

 

Is it understandable now?

 

For any query on a VBA statement, the easiest way is to search for the name in Google, example for GetPathName gives this as the second result:

"Gets the full path name for this document, including the file name."

http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2~GetPathName.html

 

Or to instrrev:

"Returns the position of the first occurrence of one string to another, from the right side of the string."

http://msdn.microsoft.com/fr-fr/library/t2ekk41a(v=vs.90).aspx

3 Likes

So for your example:

 

045-2014-A.sldddrw will be in the FileName variable .

 

You will have the folder where it is located in the FilePath variable (example: C:\Folder\)

 

You will have the concatenation of the two in the PathName variable :

C:\Dossier\045-2014-A.sldddrw

2 Likes