.NET

.NET

Reply
Contributor
murrdpirate
Posts: 12
Registered: ‎07-21-2009
Message 1 of 4 (2,612 Views)
Accepted Solution

Reading/writing to .dwg files without AutoCAD?

2612 Views, 3 Replies
06-06-2010 06:50 PM

Is this possible?  I was trying to make a simple windows program that prompted the user to select a .dwg file and the program would list all the layers in a listbox.  But the Database.ReadDWGFile procedure doesn't appear to work outside of AutoCAD (FileNotFound Exception).  Can I have my windows program open AutoCAD in the background to achieve this?

 

Here's my code:

 

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput

Public Class Form1
    Dim myLayers As ArrayList

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myDB As New Database(False, True)
        myDB.ReadDwgFile("C:\test.dwg", FileOpenMode.OpenForReadAndAllShare, True, "")

        Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
            Dim myLayerTable As LayerTable = myDB.LayerTableId.GetObject(OpenMode.ForRead)
            Dim layerName As String = ""
            For Each myObjectID As ObjectId In myLayerTable
                Dim myLayer As LayerTableRecord = myObjectID.GetObject(OpenMode.ForRead)
                myLayers.Add(myLayer.Name)
            Next
            myTrans.Abort()
        End Using

        myDB.Dispose()
        For Each layerxx In myLayers
            ListBox1.Items.Add(layerxx)
        Next
    End Sub

End Class

 

 

Is this possible?

No.

But the Database.ReadDWGFile procedure doesn't appear to work outside of AutoCAD

Yes.

You can only use ActiveX interface of AutoCAD from external application, e.g.

Autodesk.Autocad.Interop and

Autodesk.Autocad.Interop.Common

Valued Contributor
AlexanderRivilis
Posts: 71
Registered: ‎08-31-2007
Message 2 of 4 (2,600 Views)

Re: Reading/writing to .dwg files without AutoCAD?

06-07-2010 02:25 AM in reply to: murrdpirate
Is this possible?

No.

But the Database.ReadDWGFile procedure doesn't appear to work outside of AutoCAD

Yes.

You can only use ActiveX interface of AutoCAD from external application, e.g.

Autodesk.Autocad.Interop and

Autodesk.Autocad.Interop.Common

 
*Expert Elite*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 3 of 4 (2,549 Views)

Re: Reading/writing to .dwg files without AutoCAD?

06-07-2010 10:36 PM in reply to: AlexanderRivilis

You can use either AutoDesk  RealDWG

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=770257

 

or Teigha™.NET for .dwg files

http://www.opendesign.com/

 

To modify files without Autocad.

 

These are both pay options.

 

The only free options is to have Autocad Installed and use ActiveX.

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Contributor
murrdpirate
Posts: 12
Registered: ‎07-21-2009
Message 4 of 4 (2,505 Views)

Re: Reading/writing to .dwg files without AutoCAD?

06-10-2010 05:54 PM in reply to: murrdpirate

Sweet.  Many thanks to both of you.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.