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

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

Anonymous
Not applicable
7,064 Views
7 Replies
Message 1 of 8

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

Anonymous
Not applicable

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.

0 Likes
7,065 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
I'm looking for someone help/suggestion.
0 Likes
Message 3 of 8

_gile
Consultant
Consultant

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
Not applicable

Thank you so much.

Its works perfectly.

 

Thanks again!

thenndral

0 Likes
Message 5 of 8

CADbloke
Advocate
Advocate

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
0 Likes
Message 6 of 8

Jedimaster
Collaborator
Collaborator

This cannot be used on the active drawing can it?

0 Likes
Message 7 of 8

_gile
Consultant
Consultant

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

0 Likes
Message 8 of 8

Jedimaster
Collaborator
Collaborator

Thanks, that works!

0 Likes