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

VB.NET EQUIVALENT FOR THISDRAWING.PATH

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
TTIII
1230 Views, 5 Replies

VB.NET EQUIVALENT FOR THISDRAWING.PATH

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

 

5 REPLIES 5
Message 2 of 6
StephenPreston
in reply to: TTIII

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
in reply to: StephenPreston

Thanks,

But are there two different properties that returns the Filename seperate from the path?
Message 4 of 6
mcicognani
in reply to: TTIII

You can use the System.Io.Path functions to extract name and path from a fullpathname
Message 5 of 6
TTIII
in reply to: mcicognani

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)
Message 6 of 6
norman.yuan
in reply to: TTIII

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

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