TheSwamp
Code Red => VB(A) => Topic started by: hardwired on May 30, 2008, 09:46:18 AM
-
Hi,
I want to find the root folder of where my drawing files are for are project..
We have prject folders in the following fashion..
Projects >> Client Name >> ProjectName... then in here, we have a Drawings folder and many other various folders including a Schedules folder where other dwgs are found..
Using the ThisDrawing.Path is there a way in VBA to backtrack folders so i can locate the main Project folder? So....
X:\Projects\MyClient\MyProject\Drawings\MyDrawing.dwg << obviously this is the dwg file
...but i want to find using vba the main project folder (X:\Projects\)
I didn't know if there was a fundamental vb function or command to remove the last few folders from a path string. I'm presuming it would involve looking for the '\' character in the string somehow but obviously there's a few in the path itself..
Any ideas?
Typical example. I have a small routine that opens Windows Explorer to the dwg file location, but i want it to open to the main project folder instead:
Sub open_project_window()
Dim RetVal
Dim dwg_path As String
dwg_path = ThisDrawing.Path
RetVal = Shell("C:\Windows\Explorer.exe " & dwg_path, 1)
End Sub
-
Is "projects" going to be the same number of characters every time or does it vary?
-
Something like this:
Dim dwgPath as String
Dim pathTokens as Variant
Dim projectPath as string
dwgPath = ThisDrawing.Path
pathTokens = split(dwgPath, "\")
projectPath = pathTokens(0) & "\" & pathTokens(1)
I coded this in the quick reply box, so watch out for syntax errors.
-
Yeah, like that. Also gave you a fixed width method.
Sub TEST()
Dim StrPath As String
Dim strFixed As String
Dim varSplit As Variant
Dim strSplit As String
StrPath = ThisDrawing.Path
strFixed = Left(StrPath, 12)
varSplit = Split(StrPath, "\")
strSplit = varSplit(0) & "\" & varSplit(1) & "\"
End Sub
-
Hi, thanks both of you. I used Chuck's code and changed it to suit, now it works. Thanks
Sub open_project_window()
Dim RetVal
Dim dwg_path As String
Dim PathTokens As Variant
Dim ProjectPath As String
dwg_path = ThisDrawing.Path
PathTokens = Split(dwg_path, "\")
ProjectPath = PathTokens(0) & "\" & PathTokens(1) & "\" & PathTokens(2) & "\" & PathTokens(3)
RetVal = Shell("C:\Windows\Explorer.exe " & ProjectPath, 1)
End Sub
-
Hi,
I used the last code, it's ok, but if I want to open a dialog window from bricscad, what I have to use?
Now I'm using "ThisDrawing.SendCommand ("open" & vbCr)" - it's working to open the dialog window but not in the current folder. Any ideas?
Thanks.