.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ThisDrawing.Path equivalent

12 REPLIES 12
Reply
Message 1 of 13
aielli
2265 Views, 12 Replies

ThisDrawing.Path equivalent

What's the equivalent of ThisDrawing.Path in VB.NET?

Here's what I think it should be... but it's not working:

Dim AcadDoc As Document = Application.DocumentManager.MdiActiveDocument
AcadDoc.Path? or GetPath?

Slowly learning... thanks for the help.
eric
12 REPLIES 12
Message 2 of 13
deanlyon
in reply to: aielli

In C# i did it this way:
AcadApplication oAcadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
String sFilePath = oAcadApp.ActiveDocument.Path + "\\" + oAcadApp.ActiveDocument.Name;

so, In VB.NET I think it would be like this:

Dim oAcadApp as AcadApplication
Dim sFilePath as String
Set oAcadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
sFilePath = oAcadApp.ActiveDocument.Path & "\" & oAcadApp.ActiveDocument.Name;

The path is only the path and the name is only the name.
Message 3 of 13
aielli
in reply to: aielli

Thanks, but I don't believe that ActiveDocument is a property of AcadApplication.

I'm using AutoCAD 2010... not sure if this has changed...
Message 4 of 13
arcticad
in reply to: aielli

This works in 2010
{code}
Dim oAcadApp As Autodesk.AutoCAD.ApplicationServices.Document
oAcadApp = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
MsgBox(oAcadApp.Name)
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 5 of 13
aielli
in reply to: aielli

Thank you!

Didn't realize that the Name property gave the full path.
Message 6 of 13
_gile
in reply to: aielli

AcadDoc.Name was the reply I gave in your duplicated post:
http://discussion.autodesk.com/forums/thread.jspa?threadID=757438&tstart=0

> Thanks, but I don't believe that ActiveDocument is a property of AcadApplication.
Yes it is, but DeanLyon is using COM interop rather than .NET API


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 13
arcticad
in reply to: aielli

As mentioned above, This works with COM in 2010

{code}
Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Try
oAcadApp = GetObject(, "AutoCAD.Application.18")
Dim sFilePath As String
sFilePath = oAcadApp.ActiveDocument.Path & "\" & oAcadApp.ActiveDocument.Name
MsgBox(sFilePath)
Catch ex As Exception
oAcadApp = Nothing
End Try
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 8 of 13
RPeter
in reply to: aielli

Is there an equivalent for the .path for the .NET API? I don't have COM installed 🙂 I'm looking for it a couple days now but can't find a way to do it.

Message 9 of 13
dan.glassman
in reply to: aielli

Whoa -- no need for COM.

 

 

Document doc = Application.DocumentManager.MdiActiveDocument;
string path = Path.GetDirectoryName(doc.Database.Filename);

 

 

Message 10 of 13
hgasty1001
in reply to: aielli

What about the "DWGPREFIX" system variable, it's easy to check in both .NET and COM interop.

 

 

Message 11 of 13
RPeter
in reply to: aielli

dan.glassman => thx man!

Message 12 of 13
johnel48
in reply to: aielli

<CommandMethod("Test1")>
Public Sub Test1()

Dim path As string = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.Filename.ToString

If Right(path,3) <> "dwg" then
MsgBox("This file has not been saved")
Else
MsgBox("ThisDrawing = " & path)
End If

Dim NewPath As String = Left(path, Len(path)-3) & "dat"
MsgBox(NewPath)

End Sub

Message 13 of 13
beeb.pm.Net
in reply to: aielli

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Shared ReadOnly Property ThisDrg() As AcadDocument
        Get
            Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Get
    End Property


   Public Shared Function GetPath(ByVal ThisDrg As AcadDocument) As String
        Dim strPath As String = ThisDrg.FullName
        strPath = IO.Path.GetDirectoryName(strPath)
        Return strPath
    End Function

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost