.NET

Reply
Distinguished Contributor
alex_b
Posts: 393
Registered: ‎08-15-2003
Message 1 of 8 (632 Views)

Detect Autocad version - three questions

632 Views, 7 Replies
02-14-2013 11:38 AM

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

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 2 of 8 (624 Views)

Re: Detect Autocad version - three questions

02-14-2013 12:04 PM 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))
Distinguished Contributor
alex_b
Posts: 393
Registered: ‎08-15-2003
Message 3 of 8 (595 Views)

Re: Detect Autocad version - three questions

02-14-2013 07:06 PM 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?

 

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 4 of 8 (584 Views)

Re: Detect Autocad version - three questions

02-14-2013 10:34 PM 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


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
alex_b
Posts: 393
Registered: ‎08-15-2003
Message 5 of 8 (579 Views)

Re: Detect Autocad version - three questions

02-14-2013 11:00 PM 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.:smileyhappy:

Distinguished Contributor
alex_b
Posts: 393
Registered: ‎08-15-2003
Message 6 of 8 (567 Views)

Re: Detect Autocad version - three questions

02-15-2013 02:42 AM 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.

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 7 of 8 (562 Views)

Re: Detect Autocad version - three questions

02-15-2013 02:53 AM 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.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
alex_b
Posts: 393
Registered: ‎08-15-2003
Message 8 of 8 (555 Views)

Re: Detect Autocad version - three questions

02-15-2013 03:02 AM in reply to: Alexander.Rivilis

Shame on me!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community