Detect Autocad version - three questions

Detect Autocad version - three questions

alex_b
Advocate Advocate
4,516 Views
7 Replies
Message 1 of 8

Detect Autocad version - three questions

alex_b
Advocate
Advocate

Hi

 

The questions refer to an out-of-process program and a system with multiple Autocad versions installed.

 

Q1:  How do we detect the last run Autocad version?

       Somewhere between 2004 and 2008, the system registry doesn't point to the last run version any more, but points

       instead to AcLauncher.exe which, presumably' has the info.

       The question is: How to get the actual path to or the version of, the last-run Acad.exe?

Q2: How does one detect which Autocad version is currently running?

Q3: How does one detect the Autocad version of a .dwg file?

 

Quite a mouthfull, but with your help I hope to find the solutions.

 

Thanks

alex

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

arcticad
Advisor
Advisor

Here is the answers to questions 2 and 3

 

    Public Sub getACAD()
        Dim ProcessList As System.Diagnostics.Process()
        Dim Proc As System.Diagnostics.Process

        ProcessList = System.Diagnostics.Process.GetProcesses()

        For Each Proc In ProcessList
            If UCase(CStr(Proc.ProcessName)) = UCase("acad") Then
                ' FOUND RUNNING COPY
            End If
        Next
    End Sub

 



http://cadpanacea.com/node/359

header     AutoCAD Version
AC1027     AutoCAD 2013
AC1024     AutoCAD 2010,2011,2012
AC1021     AutoCAD 2007, 2008, 2009
AC1018     AutoCAD 2004, 2005, 2006
AC1015     AutoCAD 2000, 2000i, 2002
AC1014     AutoCAD Release 14
AC1013     AutoCAD Release 13
AC1009     AutoCAD Release 11, 12
AC1006     AutoCAD Release 10
AC1004     AutoCAD Release 9
AC1003     AutoCAD 2.6
AC1002     AutoCAD 2.5

 

 Function is2010(ByVal filename As String) As Boolean
        'Return False
        Dim rtnCheck As Boolean = False

        If isFileInUse(filename) Then
            filename = createTempFileName(filename)
        End If

        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()
                '     MsgBox(txtContents.Substring(0, 6))
                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 3 of 8

alex_b
Advocate
Advocate

Thank you Arcticad.

 

is2010() looks just what I need. I'll just translate it to C# and try it.

Re: your sub getAcad(): OK, we found a running acad, now how do we detect which version it is?

 

0 Likes
Message 4 of 8

Alexander.Rivilis
Mentor
Mentor

Look at http://through-the-interface.typepad.com/through_the_interface/installation/ and check function GetAutoCADKey.

Also if you use function getACAD (by articad) you can get full path to acad.exe, i.e. Proc.MainModule.FileName

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 8

alex_b
Advocate
Advocate

arcticad, here is your function translated to C# and beefed-up a little:

public string[] getRunningAcadVersions()
		{
			List<string> result = new List<string>();
			Process[] processList = System.Diagnostics.Process.GetProcesses();
			foreach (Process proc in processList)
			{
				if (proc.ProcessName.ToString().ToUpper() == "ACAD")
				{
					FileVersionInfo versionInfo = proc.MainModule.FileVersionInfo;
					int versionMajor = versionInfo.FileMajorPart;
					int versionMinor = versionInfo.FileMinorPart;
					string version = versionMajor.ToString("X") + "." + versionMinor.ToString("X");
					result.Add(version);
				}
			}
			return result.ToArray();
		}

 May it help others.Smiley Happy

Message 6 of 8

alex_b
Advocate
Advocate

Awesome.

I wasn't aware of the CurVer key.

I kept using Win32API.FindExecutable(".dwg") and it pointed to AcLauncher.exe.

Now it's OK

 

Thank you, Alexander, and Thank you, arcticad.

0 Likes
Message 7 of 8

Alexander.Rivilis
Mentor
Mentor

@alex_b wrote:
...I wasn't aware of the CurVer key...

Alex! It is very old solution as far as I remember since AutoCAD R14.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 8 of 8

alex_b
Advocate
Advocate

Shame on me!

0 Likes