VB.NET EQUIVALENT FOR THISDRAWING.PATH

VB.NET EQUIVALENT FOR THISDRAWING.PATH

TTIII
Enthusiast Enthusiast
1,513 Views
5 Replies
Message 1 of 6

VB.NET EQUIVALENT FOR THISDRAWING.PATH

TTIII
Enthusiast
Enthusiast

Hello Everyone

 

This is my first post here.

 

I have a bunch of code working just fine in VBA, Im trying to migrate this over to VB.NET.

 

I keep getting FATAL ERRORS on 

MsgBox(ThisDrawing.Path)

 

WHY??????

 

I have looked in the online help in "AutoCAD .NET Developer's Guide 2015".

I saw the line on "VBA to VB.NET and C# Comparison (.NET)" that mentions Thisdrawing but it still doesnt help.


I have also searched the .NET section of this forum (Yes I actually use the Search function)
Below is my code.

 

Please help me.

 

Option Explicit On

'************Imports******************
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
'*************************************
Imports Autodesk.AutoCAD.ApplicationServices
'Imports Autodesk.AutoCAD.Interop
'*************************************
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Namespace myTest
    Public Class myTest
        Public ThisDrawing As AutoCAD.AcadDocument                                                     
        <CommandMethod("myTest")>
        Sub myTest()
            MsgBox(ThisDrawing.ActiveDocument.Path)
        End Sub
   End Class
End Namespace

 

0 Likes
Accepted solutions (1)
1,514 Views
5 Replies
Replies (5)
Message 2 of 6

StephenPreston
Alumni
Alumni
Accepted solution

The .NET equivalent of ThisDrawing is Application.DocumentManager.mdiActiveDocument.Database. The Database class has a Filename property that returns the DWG filepath and name.

 

If you're new to the AutoCAD .NET API, I'd recommend you review the learning resources available on www.autodesk.com/developautocad - My First Plugin and the Training Labs.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 3 of 6

TTIII
Enthusiast
Enthusiast
Thanks,

But are there two different properties that returns the Filename seperate from the path?
0 Likes
Message 4 of 6

Anonymous
Not applicable
You can use the System.Io.Path functions to extract name and path from a fullpathname
0 Likes
Message 5 of 6

TTIII
Enthusiast
Enthusiast
Thanks,

For everyone else that might have this issue, this is what I did;

Public ThisDrawing as Document = Application.DocumentManager.MdiActiveDocument

For the name I used fso (as FileSystemObject) and did this:

Dim MyDrawingName as String
MyDrawingName = fso.GetFileName(ThisDrawing.Name)
0 Likes
Message 6 of 6

norman.yuan
Mentor
Mentor

Using FileSystemObject (from Scripting COM component) is bad choice unless you want to limit your CAD application to run only on your computer or computers that has the exactly the same configuration as yours. Using FileSystemObject Introduces unnecessary external dependency (Scripting COM library, which may not present in other computers, or may have different version of the libarray), not to mention that there is also a .NET interop DLL is to be distributed if other computers need to run your app.

 

,NET framework provided built-in file handling functionaliy as mcicognani suggested (System.IO.Path).

Norman Yuan

Drive CAD With Code

EESignature

0 Likes