Current Drawing Location Path

Current Drawing Location Path

Anonymous
Not applicable
7,969 Views
4 Replies
Message 1 of 5

Current Drawing Location Path

Anonymous
Not applicable

Hi Guys,

 

I am using vb.net and I need to find the directory path that my current or open drawing is located in.  I'm not sure how to get this from vb.net.  Any help is appreciated.   Thanks.

0 Likes
Accepted solutions (1)
7,970 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Take a look at

Document.Name

Database.OriginalFileName

 

        <CommandMethod("GetFileName")> _
        Sub GetFileName()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            ed.WriteMessage(doc.Name & vbCrLf)
            ed.WriteMessage(db.OriginalFileName)

        End Sub

 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable
Accepted solution

Sorry you want the folder,

 

 

 Application.GetSystemVariable("DWGPREFIX")

 

or another way

make sure you Import System.IO

Change previos Post to

 <CommandMethod("GetFileName")> _
        Sub GetFileName()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            ed.WriteMessage(Path.GetDirectoryName(doc.Name) & vbCrLf)
            ed.WriteMessage(Path.GetDirectoryName(db.OriginalFileName))
        End Sub

 

 

 

 

Message 4 of 5

Anonymous
Not applicable

Thank you for your post.  This is exactly what i was looking for.  I have a another question now that I'm seeing the output of this.  Is there a way to go up one folder level in the directory path?  Or i would have to manually trim the string?

0 Likes
Message 5 of 5

Anonymous
Not applicable
        <CommandMethod("GetFileName")> _
        Sub GetFileName()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            ed.WriteMessage(Path.GetDirectoryName(doc.Name) & vbCrLf)
            ed.WriteMessage(Path.GetDirectoryName(db.OriginalFileName) & vbCrLf)


            Dim fpath As String = Path.GetDirectoryName(doc.Name)


            While fpath <> Nothing
                ed.WriteMessage(fpath & vbCrLf)
                fpath = Path.GetDirectoryName(fpath)
            End While

            fpath = doc.Name
            Dim levels As Integer = ed.GetInteger("Enter number of levels you want" & vbCrLf).Value

            For i As Integer = 0 To levels
                fpath = Path.GetDirectoryName(fpath)
                If fpath = Nothing Then
                    Exit For
                End If
            Next
            ed.WriteMessage(fpath & vbCrLf)

        End Sub

 

0 Likes