Find the current service pack version of Civil 3D

Find the current service pack version of Civil 3D

stacy.dunn
Collaborator Collaborator
1,967 Views
3 Replies
Message 1 of 4

Find the current service pack version of Civil 3D

stacy.dunn
Collaborator
Collaborator

I am looking for an automated way in .net to obtain the service pack version of Civil 3D 2013 and newer.

I found where I can get the application version but not the service pack information.  Am I limited to searching the registry?

Stacy Dunn
0 Likes
1,968 Views
3 Replies
Replies (3)
Message 2 of 4

Jeff_M
Consultant
Consultant
I believe the registry search is the only way, Stacy. And to make it more interesting, Autodesk changes where the information is saved from time to time...2016 is different than 2012-2015.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 4

Jeff_M
Consultant
Consultant

@stacy.dunn, Here is the result from the code below:

Command: GETSPS
C3D 2012:
AutoCAD Civil 3D 2012 SP1
AutoCAD Civil 3D 2012 SP1.1
AutoCAD Civil 3D 2012 SP1.2
AutoCAD Civil 3D 2012 SP1.3
AutoCAD Civil 3D 2012 SP1.4
AutoCAD Civil 3D 2012 SP2.0
AutoCAD Civil 3D 2012 SP2.1
AutoCAD Civil 3D 2012 SP3.0
AutoCAD Civil 3D 2012 SP4.0
C3D 2013:
AutoCAD Civil 3D 2013 HF1
AutoCAD Civil 3D 2013 HF1.0
AutoCAD Civil 3D 2013 HF2.0
AutoCAD Civil 3D 2013 HF2.1
AutoCAD Civil 3D 2013 HF3.0
AutoCAD Civil 3D 2013 SP1.0
AutoCAD Civil 3D 2013 SP2.0
C3D 2014:
Autodesk AutoCAD Civil 3D 2014 HF1.0
Autodesk AutoCAD Civil 3D 2014 SP1.0
Autodesk AutoCAD Civil 3D 2014 SP2.0
C3D 2015:
Autodesk AutoCAD Civil 3D 2015 SP1.0
Autodesk AutoCAD Civil 3D 2015 SP2.0
Autodesk AutoCAD Civil 3D 2015 SP3.0
C3D 2016:
Autodesk AutoCAD Civil 3D 2016 SP1.0
Autodesk AutoCAD Civil 3D 2016 SP2.0

 

This code is rough, gets only Civil3D information, but does the job. Much of this was derived from my AutoCADMRUCLeaner code.

using Autodesk.AutoCAD.Runtime;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Civil3D_Misc_Commands.VersionTools
{
    public class VersionTools
    {
        [CommandMethod("getsps")]
        public void getsps()
        {            
            var tmp = GetServicePackInfoInstalledAcads();
            var ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            foreach (var itm in tmp)
            {
                ed.WriteMessage("\n" + itm.AcadNum.Keys.First().ToString() + ": ");
                foreach(var key in itm.AcadNum.Values)
                {
                    foreach (string s in key)
                        ed.WriteMessage("\n    " + s);
                }
            }
        }

        List<VerData> GetServicePackInfoInstalledAcads()
        {
            List<VerData> verdata = new List<VerData>();
            List<string> registryKeys = new List<string>();
            registryKeys.Add(@"SOFTWARE\Autodesk\AutoCAD");
            //if need to check for the 32 bit versions, additional keys will be needed

            foreach (string regkey in registryKeys)
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regkey))
                {
                    if (key == null)
                        continue;
                    foreach (string subkey_name in key.GetSubKeyNames())
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                        {
                            var newverdata = new VerData();
                            newverdata.Release = subkey.Name.Split('\\').Last().ToString(); ;
                            var verDbl = Convert.ToDouble(newverdata.Release.Replace("R", ""));
                            List<string> servicePacks = new List<string>();
                            string prodname = "";
                            foreach (string subsubkey_name in subkey.GetSubKeyNames())
                            {
                                if (!(subsubkey_name.StartsWith("ACAD") && subsubkey_name.Contains("000:")))
                                    continue;

                                using (RegistryKey subsubkey = subkey.OpenSubKey(subsubkey_name))
                                {
                                    prodname = (string)subsubkey.GetValue("ProductNameShort");

                                    RegistryKey prodKey = null;
                                    if (verDbl > 20.0)
                                    {
                                        using (var parentsubkey = subkey.OpenSubKey(subsubkey_name.Remove(9)))
                                        prodKey = parentsubkey.OpenSubKey("ProductInfo");
                                    }
                                    else
                                    {
                                        prodKey = subsubkey.OpenSubKey("Service Packs");
                                    }
                                    if (prodKey == null)
                                        continue;
                                    foreach (string prodName in prodKey.GetSubKeyNames())
                                    {
                                        if (prodName.Contains(" SP") || prodName.Contains(" HF"))
                                        {
                                            servicePacks.Add(prodName);
                                        }
                                    }
                                }
                                if (prodname != null && servicePacks.Count > 0)
                                {
                                    newverdata.AcadNum.Add(prodname, servicePacks);
                                }
                            }
                            if (newverdata.AcadNum.Count > 0)
                            {
                                verdata.Add(newverdata);
                            }
                        }
                    }
                }
            }
            return verdata;
        }
    }

    public class VerData
    {
        public string Release;
        public Dictionary<string, List<string>> AcadNum;

        public VerData()
        {
            AcadNum = new Dictionary<string, List<string>>();
        }
    }
}
Jeff_M, also a frequent Swamper
EESignature
Message 4 of 4

stacy.dunn
Collaborator
Collaborator

thank you Jeff!

Stacy Dunn
0 Likes