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

How to determine the version of AutoCad DWG file using vb.net

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
5901 Views, 7 Replies

How to determine the version of AutoCad DWG file using vb.net

Hello,

 

 

As far as I googled everyone suggest this way.

 

How can the version of an AutoCAD DWG file be determined?
The first 6 bytes of a DWG file will indicate the version used.

 

1. Open the DWG file in Notepad.
2. get the first 6 bytes. its dwg version.

 

AC1027 AutoCAD 2013/2014
AC1024 AutoCAD 2010/2011/2012 
AC1021 AutoCAD 2007/2008/2009 
AC1018 AutoCAD 2004/2005/2006 
AC1015 AutoCAD 2000/2000i/2002 
AC1014 Release 14 
AC1012 Release 13 
AC1009 Release 11/12 
AC1006 Release 10 
AC1004 Release 9 
AC1003 Version 2.60 
AC1002 Version 2.50 
AC1001 Version 2.22 
AC2.22 Version 2.22 
AC2.21 Version 2.21 
AC2.10 Version 2.10 
AC1.50 Version 2.05 
AC1.40 Version 1.40 
AC1.2 Version 1.2 
MC0.0 Version 1.0

 

How can check the dwg version using VB.Net.

Any source code help or suggesion is appreciated.

 

Thanks in advance,
thenndral.

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

I'm looking for someone help/suggestion.
Message 3 of 8
_gile
in reply to: Anonymous

Hi,

 

You may have a look at the System.IO.StreamReader class (and the other classes which inherit from System.IO.Stream abstract class).

 

C#

private static string DwgVersion(string filename)
{
    using (StreamReader reader = new StreamReader(filename))
    {
        switch (reader.ReadLine().Substring(0, 6))
        {
            case "AC1027": return "AutoCAD 2013";
            case "AC1024": return "AutoCAD 2010";
            case "AC1021": return "AutoCAD 2007";
            case "AC1018": return "AutoCAD 2004";
            case "AC1015": return "AutoCAD 2000";
            case "AC1014": return "AutoCAD R14";
            default: return "Prior AutoCAD R14";
        }
    }
}

 

F#

let dwgVersion (filename: string) =
    use reader = new StreamReader(filename)
    match reader.ReadLine().Substring(0, 6) with
    | "AC1027" -> "AutoCAD 2013"
    | "AC1024" -> "AutoCAD 2010"
    | "AC1021" -> "AutoCAD 2007"
    | "AC1018" -> "AutoCAD 2004"
    | "AC1015" -> "AutoCAD 2000"
    | "AC1014" -> "AutoCAD R14"
    | _        -> "Prior AutoCAD R14"

 

VB

Private Function DwgVersion(filenameAs String) As String
    Using reader As New StreamReader(filename)
        Select Case reader.ReadLine().Substring(0, 6)
            Case "AC1027"
                Return "AutoCAD 2013"
            Case "AC1024"
                Return "AutoCAD 2010"
            Case "AC1021"
                Return "AutoCAD 2007"
            Case "AC1018"
                Return "AutoCAD 2004"
            Case "AC1015"
                Return "AutoCAD 2000"
            Case "AC1014"
                Return "AutoCAD R14"
            Case Else
                Return "Prior AutoCAD R14"
        End Select
    End Using
End Function

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 8
Anonymous
in reply to: _gile

Thank you so much.

Its works perfectly.

 

Thanks again!

thenndral

Message 5 of 8
CADbloke
in reply to: _gile

the 2004 version is actually AC1800, not AC1018. Thanks for the code Giles.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 6 of 8
Jedimaster
in reply to: _gile

This cannot be used on the active drawing can it?

Message 7 of 8
_gile
in reply to: Jedimaster

Hi,

 

In the active drawing, you can use the Database.OriginalFileVersion or Database.LastSaveAsVersion property:

 

var version = db.LastSavedAsVersion;
if (version == DwgVersion.MC0To0)
    version = db.OriginalFileVersion;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 8
Jedimaster
in reply to: _gile

Thanks, that works!

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