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
Solved! Go to Solution.
Solved by StephenPreston. Go to 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.
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