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

Detect Autocad version - three questions

7 REPLIES 7
Reply
Message 1 of 8
alex_b
3451 Views, 7 Replies

Detect Autocad version - three questions

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

7 REPLIES 7
Message 2 of 8
arcticad
in reply to: alex_b

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
in reply to: arcticad

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?

 

Message 4 of 8
Alexander.Rivilis
in reply to: alex_b

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
in reply to: alex_b

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
in reply to: Alexander.Rivilis

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.

Message 7 of 8
Alexander.Rivilis
in reply to: alex_b


@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

Message 8 of 8
alex_b
in reply to: Alexander.Rivilis

Shame on me!

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