Author Topic: Backtracking to certain folders in dwg path..  (Read 2697 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
Backtracking to certain folders in dwg path..
« 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:

Code: [Select]
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


Bob Wahr

  • Guest
Re: Backtracking to certain folders in dwg path..
« Reply #1 on: May 30, 2008, 09:51:36 AM »
Is "projects" going to be the same number of characters every time or does it vary?

Chuck Gabriel

  • Guest
Re: Backtracking to certain folders in dwg path..
« Reply #2 on: May 30, 2008, 09:56:23 AM »
Something like this:

Code: [Select]
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.

Bob Wahr

  • Guest
Re: Backtracking to certain folders in dwg path..
« Reply #3 on: May 30, 2008, 09:58:46 AM »
Yeah, like that.  Also gave you a fixed width method.

Code: [Select]
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

hardwired

  • Guest
Re: Backtracking to certain folders in dwg path..
« Reply #4 on: May 30, 2008, 10:19:10 AM »
Hi, thanks both of you. I used Chuck's code and changed it to suit, now it works. Thanks


Code: [Select]
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

montzagcg

  • Guest
Re: Backtracking to certain folders in dwg path..
« Reply #5 on: December 10, 2008, 08:00:43 AM »
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.