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
Решено! Перейти к решению.
Решено: Alexander.Rivilis. Перейти к решению.
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.
Не нашли то, что искали? Задайте вопросы в сообществе или поделитесь своими знаниями.