To follow on from yesterday’s post, today we’re going to look at a reliable way to determine the language of the AutoCAD product hosting your .NET module.
Thanks to Troy Louden for sharing this technique. Here’s the C# code implementing it:
using System.Globalization;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
namespace LanguageInfo
{
public class Commands
{
[CommandMethod("LANG")]
public static void WhichLanguage()
{
var cult =
new CultureInfo(SystemObjects.DynamicLinker.ProductLcid);
Application.DocumentManager.MdiActiveDocument.Editor.
WriteMessage(
"\nLanguage of your AutoCAD product is {0}.",
cult.EnglishName
);
}
}
}
When we run the code, we can see it simply tells us the language associated with the product’s “culture”. We’re printing the English version of the name, but the Culture object provides lots more information besides.
Command: LANG
Language of your AutoCAD product is English (United States).
That’s it – short and sweet.
And that’s also it for the week: all being well my next post will be from San Francisco.