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

autocad app version references

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
dan.popescu9NZJ8
798 Views, 12 Replies

autocad app version references

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

12 REPLIES 12
Message 2 of 13

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


 

Message 3 of 13


@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

Message 4 of 13

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();
                }
            }
        }

 

Message 5 of 13

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();
                }
            }
        }

 


 

 

 

 

Message 6 of 13

@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

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

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; }

 

Message 9 of 13

@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

Message 10 of 13

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). 

Message 11 of 13

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

Message 12 of 13

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

thanks 

Message 13 of 13

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.

 

 

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