find and open file
find and open file
(OP)
Hello,
I am trying to create a program that lets me input my file name and it searches a directory and opens that file.
Our current drawing management system consists of our drawings being put in subdirectories based on their name. For example '3-15344.dwg' would be in the k:\\...\dwg\3\15 directory and '101-12153.dwg' would be in k:\\...\dwg\1\101\12 directory. It is very time consuming to have to navigate the subdirectories to open a drawing I need right now.
My intent is to stop having to go through the subdirectory maze every time I want to open a drawing.
I want to be able to type in the drawing number, click a button, and have the drawing open.
I am new to visual basic and have done a few of the tutorials I have found online but don't know enough to make it do what I need it to do.
Can someone please point me in the right direction? I am using Visual Basic 2008 Express Edition on Windows XP Pro 32bit.
Your help is very much appreciated.
Thanks.
I am trying to create a program that lets me input my file name and it searches a directory and opens that file.
Our current drawing management system consists of our drawings being put in subdirectories based on their name. For example '3-15344.dwg' would be in the k:\\...\dwg\3\15 directory and '101-12153.dwg' would be in k:\\...\dwg\1\101\12 directory. It is very time consuming to have to navigate the subdirectories to open a drawing I need right now.
My intent is to stop having to go through the subdirectory maze every time I want to open a drawing.
I want to be able to type in the drawing number, click a button, and have the drawing open.
I am new to visual basic and have done a few of the tutorials I have found online but don't know enough to make it do what I need it to do.
Can someone please point me in the right direction? I am using Visual Basic 2008 Express Edition on Windows XP Pro 32bit.
Your help is very much appreciated.
Thanks.





RE: find and open file
"E-100845623R1A", "F:\MyProject\Drawings\Electrical\"
That substitutes the simple work of just maintaining a very simple database for all the code and recursion work, not to mention the immense time wasting that would go along with searching the entire system for each and every drawing request.
Enter the drawing number, you get the location in 0.5 ms, then shell out to open the drawing.
**********************
"The problem isn't finding the solution, its trying to get to the real question." BigInch
http://virtualpipeline.spaces.live.com/
RE: find and open file
RE: find and open file
RE: find and open file
I was originally planning to do the whole key file bit similar to what is listed above, which would find stuff a lot faster, but then you have keys files that have to be maintained and sorted.
John
RE: find and open file
I used a little bit of everything and managed to make a little program that does what I needed it to do.
If anyone is interested I can post the code.
Thanks again for your help.
RE: find and open file
I am sure what you did. But a "Shell" command is all you need for your applet.
Best regards,
Alex
RE: find and open file
RE: find and open file
CODE
DwgNo = TextBoxDwgNo.Text
'Selects either Server1 or the Server2 to look in
Dim Server As String
If RadioButton1.Checked = True Then
Server = "\\Server1"
Else
Server = "\\Server2"
End If
'Determines the directory structure of where the drawing is
Dim Parts() As String = TextBoxDwgNo.Text.Split("-") 'splits the drawing number at the hyphen
Dim FirstPart As String = Parts(0).Substring(0, 1) 'calls out the first digit of the file
Dim SecondPart As String
Dim ThirdPart As String
Dim Length1 As Integer = Len(Parts(0)) 'determines the length of the left side of the hyphen
If Length1 = 1 Then 'determines how to split the path
SecondPart = Parts(1).Substring(0, 2)
ThirdPart = Parts(1).Substring(0, 2)
Else
SecondPart = Parts(0).Substring(0, 3)
End If
Dim FilePath As String = Server & FirstPart & "\" & SecondPart & "\" 'Determines the path of the drawing
'searches for the drawing number in the path with a wildcard for the revision
Dim returnValue() As String = System.IO.Directory.GetFiles(FilePath, DwgNo & "*" & ".dwg")
On Error GoTo OpenError
Dim returnLength As Integer = returnValue.Length
Dim revLevel As Integer = returnLength - 1
Dim DwgPath As String = returnValue(revLevel) 'path for drawing with the first revision it finds
'opens autocad
On Error Resume Next
Dim ACADApp As Object, DwgName As Object
ACADApp = GetObject(, "AutoCAD.Application")
If Err.Number <> 0 Then
Err.Clear()
ACADApp = CreateObject("AutoCAD.Application")
End If
DwgName = ACADApp.Documents.Open(DwgPath)
ACADApp.Application.Visible = True
AppActivate("AutoCAD")
'resets the values
ACADApp = Nothing
DwgName = Nothing
OpenError:
If Err.Number <> 0 Then
MessageBox.Show("Drawing not found")
End If