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
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
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
@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
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(); } } }
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(); } } }
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
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; }
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; }
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
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).
You can use the same code base to build two separate dlls using conditional compliation as I showed above.
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.