autocad app version references

autocad app version references

dan.popescu9NZJ8
Contributor Contributor
1,639 Views
12 Replies
Message 1 of 13

autocad app version references

dan.popescu9NZJ8
Contributor
Contributor

I have installed on my machine both Map 3D and Civil 3D.

I have created a dll that i want to run it in both.

I want to avoid creating 2 separate dlls - one for map one for civil.

The command basically is selecting an entity and reads the property of it.

The type of entity is either a polyline or a civil3d alignment. 

so if i load the dll in map 3D i want to ignore code about the civil 3D alignment. 

in order to do that i have to detect what autocad i am into.

also if is map 3D i need to drop civil 3d references.

 

can someone help me?

 

Autodesk.AutoCAD.EditorInput.PromptEntityResult cl_res;
Autodesk.AutoCAD.EditorInput.PromptEntityOptions cl_prompt;
cl_prompt = new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\nSelect the centerline:");
cl_prompt.SetRejectMessage("\nSelect a polyline!");
cl_prompt.AllowNone = true;
cl_prompt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
cl_prompt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Alignment), false);

 

 

Thanks

0 Likes
Accepted solutions (1)
1,640 Views
12 Replies
Replies (12)
Message 2 of 13

ActivistInvestor
Mentor
Mentor

Doing that is somewhere between very difficult and impossible.  It would require you to eliminate 'hard' references to types in the C3D libraries, and load them dynamically and call methods via reflection.

 

Building two separate DLLs is really your only practical option. You can use a single code base that uses conditional compilation (#ifdef/#endif) to factor out all C3D-dependent code for the build that targets Map3D.

 

For example:

 

cl_prompt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
#ifdef CIVIL3D
cl_prompt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Alignment), false);
#endif
 

 


@dan.popescu9NZJ8 wrote:

I have installed on my machine both Map 3D and Civil 3D.

I have created a dll that i want to run it in both.

I want to avoid creating 2 separate dlls - one for map one for civil.

The command basically is selecting an entity and reads the property of it.

The type of entity is either a polyline or a civil3d alignment. 

so if i load the dll in map 3D i want to ignore code about the civil 3D alignment. 

in order to do that i have to detect what autocad i am into.

also if is map 3D i need to drop civil 3d references.

 

can someone help me?

 

Autodesk.AutoCAD.EditorInput.PromptEntityResult cl_res;
Autodesk.AutoCAD.EditorInput.PromptEntityOptions cl_prompt;
cl_prompt = new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\nSelect the centerline:");
cl_prompt.SetRejectMessage("\nSelect a polyline!");
cl_prompt.AllowNone = true;
cl_prompt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
cl_prompt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Alignment), false);

 

 

Thanks


 

0 Likes
Message 3 of 13

Alexander.Rivilis
Mentor
Mentor

@dan.popescu9NZJ8  написал (-а):

I have installed on my machine both Map 3D and Civil 3D.

I have created a dll that i want to run it in both.

I want to avoid creating 2 separate dlls - one for map one for civil.

The command basically is selecting an entity and reads the property of it.

The type of entity is either a polyline or a civil3d alignment. 

so if i load the dll in map 3D i want to ignore code about the civil 3D alignment. 

in order to do that i have to detect what autocad i am into.

also if is map 3D i need to drop civil 3d references.

 

can someone help me?

 

Autodesk.AutoCAD.EditorInput.PromptEntityResult cl_res;
Autodesk.AutoCAD.EditorInput.PromptEntityOptions cl_prompt;
cl_prompt = new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\nSelect the centerline:");
cl_prompt.SetRejectMessage("\nSelect a polyline!");
cl_prompt.AllowNone = true;
cl_prompt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
cl_prompt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Alignment), false);

 

 

Thanks


IMHO. It is easy split your dll into two - dll1 for AutoCAD, and dll2 for Civil 3D. If dll1 detect that it was loaded in Civil3d it loaded dll2 and call it's methodes. In other case you have to use Civil 3D API with help of reflection - it is not easy.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 4 of 13

dan.popescu9NZJ8
Contributor
Contributor

Thank you for your answer.... how do I detect if is autocad map over autocad civil 3d?

I got over the internet some code:

but when i am running it in autocad map is giving me as being civil

 private static bool is_civil3d()
        {
            dynamic acadApp;
            try
            {
                acadApp = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
            }
            catch
            {
                return false;
            }

            string acVer = acadApp.Version.Substring(0, 4);


            string aeccVer;

            if (acVer == "19.0")
                aeccVer = "10.0";
            else if (acVer == "19.1")
                aeccVer = "10.3";
            else if (acVer == "20.0")
                aeccVer = "10.4";
            else if (acVer == "20.1")
                aeccVer = "10.5";
            else if (acVer == "21.0") // acad 2017
                aeccVer = "11.0";
            else if (acVer == "22.0") //acad 2018
                aeccVer = "12.0";
            else if (acVer == "23.0") // acad 2019
                aeccVer = "13.0";
            else aeccVer = null;

            if (string.IsNullOrEmpty(aeccVer))
            {
                return false;
            }

            // Civil 3D?
            dynamic civilLandApp;
            try
            {
                civilLandApp = acadApp.GetInterfaceObject("AeccXUiLand.AeccApplication." + aeccVer);
                System.Windows.Forms.MessageBox.Show(string.Format("{0}", civilLandApp.Name));
                return true;
            }
            catch
            {

                return false;
            }

        }

and :

        private static string GetAcadCurVerKey()
        {
            StringBuilder sb = new StringBuilder(@"Software\Autodesk\AutoCAD\");
            using (RegistryKey acad = Registry.CurrentUser.OpenSubKey(sb.ToString()))
            {
                sb.Append(acad.GetValue("CurVer")).Append(@"\");
                using (RegistryKey curVer = Registry.CurrentUser.OpenSubKey(sb.ToString()))
                {
                    return sb.Append(curVer.GetValue("CurVer")).ToString();
                }
            }
        }

 

0 Likes
Message 5 of 13

ActivistInvestor
Mentor
Mentor

The PRODUCT system variable should tell you what you're running in, but that isn't really going to help you to avoid having the runtime try to load the Civil3D API (which will fail when running on Map3D), because you can't use simple conditional branching to do it.

 


@dan.popescu9NZJ8 wrote:

Thank you for your answer.... how do I detect if is autocad map over autocad civil 3d?

I got over the internet some code:

but when i am running it in autocad map is giving me as being civil

 private static bool is_civil3d()
        {
            dynamic acadApp;
            try
            {
                acadApp = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
            }
            catch
            {
                return false;
            }

            string acVer = acadApp.Version.Substring(0, 4);


            string aeccVer;

            if (acVer == "19.0")
                aeccVer = "10.0";
            else if (acVer == "19.1")
                aeccVer = "10.3";
            else if (acVer == "20.0")
                aeccVer = "10.4";
            else if (acVer == "20.1")
                aeccVer = "10.5";
            else if (acVer == "21.0") // acad 2017
                aeccVer = "11.0";
            else if (acVer == "22.0") //acad 2018
                aeccVer = "12.0";
            else if (acVer == "23.0") // acad 2019
                aeccVer = "13.0";
            else aeccVer = null;

            if (string.IsNullOrEmpty(aeccVer))
            {
                return false;
            }

            // Civil 3D?
            dynamic civilLandApp;
            try
            {
                civilLandApp = acadApp.GetInterfaceObject("AeccXUiLand.AeccApplication." + aeccVer);
                System.Windows.Forms.MessageBox.Show(string.Format("{0}", civilLandApp.Name));
                return true;
            }
            catch
            {

                return false;
            }

        }

and :

        private static string GetAcadCurVerKey()
        {
            StringBuilder sb = new StringBuilder(@"Software\Autodesk\AutoCAD\");
            using (RegistryKey acad = Registry.CurrentUser.OpenSubKey(sb.ToString()))
            {
                sb.Append(acad.GetValue("CurVer")).Append(@"\");
                using (RegistryKey curVer = Registry.CurrentUser.OpenSubKey(sb.ToString()))
                {
                    return sb.Append(curVer.GetValue("CurVer")).ToString();
                }
            }
        }

 


 

 

 

 

0 Likes
Message 6 of 13

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@dan.popescu9NZJ8

You can check if AppDomain.CurrentDomain.GetAssemblies() has "AeccDbMgd" or try to load "AeccDbMgd.dll" with Assembly.LoadFile (in try/catch block).

 
 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 7 of 13

dan.popescu9NZJ8
Contributor
Contributor

thans ... worked

 



System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); bool is_civil = false; foreach (System.Reflection.Assembly asm in assemblies) { System.Reflection.AssemblyName asmName = asm.GetName(); if (asmName.Name == "AeccDbMgd") { is_civil = true; } //FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); //string name = asmName.Name; //Version asmV = asmName.Version; //string fileV = fvi.FileVersion; //string prodV = fvi.ProductVersion; }
Message 8 of 13

ActivistInvestor
Mentor
Mentor

It seems that you didn't understand what I was trying to get across to you earlier. Knowing if you're running on Civil3D isn't going to help you because if you're not running on Civil3D your code cannot contain any references to any Civil3D types, regardless of whether the code executes, or not.

 


@dan.popescu9NZJ8 wrote:

thans ... worked

 



System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); bool is_civil = false; foreach (System.Reflection.Assembly asm in assemblies) { System.Reflection.AssemblyName asmName = asm.GetName(); if (asmName.Name == "AeccDbMgd") { is_civil = true; } //FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); //string name = asmName.Name; //Version asmV = asmName.Version; //string fileV = fvi.FileVersion; //string prodV = fvi.ProductVersion; }

 

0 Likes
Message 9 of 13

Alexander.Rivilis
Mentor
Mentor

@ActivistInvestor

I think @dan.popescu9NZJ8 decided to split his application into two, as I suggested above.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 10 of 13

dan.popescu9NZJ8
Contributor
Contributor

i'm not sure what path I will use... anyway the computers i am building this for should have civil installed.... and if i separate in the first phase the code based on the {if is civil = true} it works. Then i will try to use reflections to see if i am able to make it work into a non civil computer. the 2 dlls require me to the same program written twice with a minor tweak on the map3d one. (I require a coordinate transformation). 

0 Likes
Message 11 of 13

ActivistInvestor
Mentor
Mentor

You can use the same code base to build two separate dlls using conditional compliation as I showed above.

0 Likes
Message 12 of 13

dan.popescu9NZJ8
Contributor
Contributor

i will try to do that. Can you point me to an example?

thanks 

0 Likes
Message 13 of 13

ActivistInvestor
Mentor
Mentor

the code that I showed above was supposed to be an example of that, but I mistakenly used "#ifdef" rather than "#if" (#ifdef is for C++, which is what I've been mostly coding with these days). 

 

So the correct example would be:

 

cl_prompt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
#if CIVIL3D
cl_prompt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Alignment), false);
#endif

 

The code appearing between #if CIVIL3D and #endif would only be compiled when the preprocessor symbol CIVIL3D is defined. Hence, you must define that symbol when building for Civil3D, and undefine it when building for Map3d.

 

 

0 Likes