MACRO QUESTION -
MACRO QUESTION -
(OP)
I can take characters from the sw file NAME and place them in the sw custom properties of the dwg using a macro. Does anybody have a macro that would allow me to take parts of a file PATH and apply them to a sw property?
ex.
file path: J:1234/abcd/567.slddwg.
custom property would read: 1234567.
ex.
file path: J:1234/abcd/567.slddwg.
custom property would read: 1234567.






RE: MACRO QUESTION -
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: MACRO QUESTION -
Tempval = LTrim(RTrim(Document.GetCustomInfoValue("", PartNoPropName)))
ModelName = Mid(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0), 17, 3)
This is the line in my macro that trims the file name. I'm not sure how to change this into cutting out specific characters from a file path. I know enough about programing to change the 17 and 3 to get what I want, but anything more is a little over my head. If I could apply this part of the macro to the file path and run this part of the macro twice, that would solve my problem. I don't think it would take much effort, but i'm not sure how to do it.
RE: MACRO QUESTION -
Enjoy! Chris
Sub main()
s = "C:\123\i need a beer\456A.sldprt" 'your input
L = Len(s) 'length of the string
For X = L To 1 Step -1 'find the leftmost "\"
If Mid(s, X, 1) = "\" Then a = X
Next X
For X = L To a + 1 Step -1 'find the second leftmost \
If Mid(s, X, 1) = "\" Then b = X
Next X
For X = 1 To L 'find the rightmost \
If Mid(s, X, 1) = "\" Then c = X
Next X
For X = 1 To L 'find the .
If Mid(s, X, 1) = "." Then d = X
Next X
s1 = Mid(s, a + 1, (b - a - 1)) 'cutout the first part number
s2 = Mid(s, c + 1, (d - c - 1)) 'cutout the second part number
partno = s1 + s2 'patch them together
MsgBox (partno) 'done
End Sub
RE: MACRO QUESTION -
Enjoy,
Ken
CODE
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sFileNameAndPath As String
Dim sFileName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
sFileNameAndPath = swModel.GetPathName
sFileName = Right$(swModel.GetPathName, (Len(swModel.GetPathName) - InStrRev(swModel.GetPathName, "\")))
Debug.Print sFileNameAndPath
Debug.Print sFileName
End Sub
RE: MACRO QUESTION -
Looks like I didn't read your original post close enough. The macro above will only parse out the filename.
I have something that can do as you requested but I need a little clarification first...is the filename and path actually "J:1234/abcd/567.slddwg". Usually a path is something like "J:\1234\abcd\567.slddwg".
Ken
RE: MACRO QUESTION -
You should test for both "\" and "/", as both can be delimiters for path strings. You probably want to stage your lops as follows:
For X=L to 1 step -1
For X=a-1 to 1 step -1
For X=b-1 to 1 step -1
etc.
This will parse your path from right to left.
The best thing would be to write this as a function so you can reuse it many times in your code. Perhaps have your input be the path string, and output be your desired result.
RE: MACRO QUESTION -