GetDWGVersion -via VB.NET

GetDWGVersion -via VB.NET

Anonymous
Not applicable
1,625 Views
8 Replies
Message 1 of 9

GetDWGVersion -via VB.NET

Anonymous
Not applicable

Hi, 

 

Quick Question here

 

How do I get the Drawing Version (2000, 2004, 2007, 2010 Cad Version)?

 

myExtractedDB.Version = System.Enum.GetName(GetType(Autodesk.AutoCAD.DatabaseServices.DwgVersion), DatabaseIn.LastSavedAsVersion)..

 

For example the text file show it's 'AC1024' in the prefix. 

I'd rather just pull it from the Drawing Database via VB.NET

 

Any ideas here what's the object or method to access this? 

 

I think I'm the right trail with DwgVersion. 

0 Likes
Accepted solutions (3)
1,626 Views
8 Replies
Replies (8)
Message 2 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

IMHO within the database-object you don't have the info, because it's only an info for "file-format" and not for "working-format".

And as long as you have the database open you have no info about what format will the user choose for the save-command in the future 😉

Opening the file (at least the first bytes) in binary-mode is the way you can go.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 9

arcticad
Advisor
Advisor
Accepted solution
    Function isDWG2010(ByVal filename As String) As Boolean
        'Return False
        'Exit Function
        Dim rtnCheck As Boolean = False

        Dim objReader As IO.StreamReader
        Dim txtContents As String
        ' Check if File Exists
        If IO.File.Exists(filename) Then
            objReader = IO.File.OpenText(filename)
            'Read all the Text in the File
            Do While objReader.Peek <> -1
                txtContents = objReader.ReadLine()
                If txtContents.Substring(0, 6) = "AC1024" Then
                    rtnCheck = True
                End If
                Exit Do
            Loop
            ' Don't forget to close the file
            objReader.Close()
            objReader = Nothing
        End If

        Return rtnCheck

    End Function

 

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



(defun botsbuildbots() (botsbuildbots))
Message 4 of 9

leaveAlone
Enthusiast
Enthusiast
Accepted solution

Use property:

Application.DocumentManager.MdiActiveDocument.Database.OriginalFileVersion


...and from that you have version which is used to save that file (google for what it gives as return and you will find enough resources...)

 

 

0 Likes
Message 5 of 9

Anonymous
Not applicable
Thanks!
0 Likes
Message 6 of 9

kerry_w_brown
Advisor
Advisor
Accepted solution

 

arcticad,

Personally, I'd have the creation of the StreamReader instance in a using statement.

 

_Guy,

The  Application.DocumentManager.MdiActiveDocument.Database.OriginalFileVersion

will return the DwgVersion enumerators I posted for you elsewhere.

 

Regards

 

 

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 7 of 9

Anonymous
Not applicable

Some follow-up here:

 

Can someone point me to what number translates to what verison of Autocad... 

You know what the enumerated items stand for in simple terms....

 


For examples I get 

 

29, 24, 25

 

29 - Autocad 2011

25 - Autocad 2005

 

Any Idea guys?

 

Thanks! 

 

0 Likes
Message 8 of 9

arcticad
Advisor
Advisor

http://autodesk.blogs.com/between_the_lines/autocad-release-history.html

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



(defun botsbuildbots() (botsbuildbots))
Message 9 of 9

Anonymous
Not applicable
Bingo Thanks articad!
0 Likes