Define a localized command name in the .NET API
问题:
In ARX I can define both globalized and localized command name. Is there a similar way to define localized command name in the .Net API? Or should I simply define two command methods which call the same function?
解答:
There are a few signatures of CommandMethodAttribute that have a parameter of local command name id. For example:
CommandMethodAttribute(
System.String groupName,
System.String globalName,
System.String localizedNameId,
Autodesk.AutoCAD.Runtime.CommandFlags flags)
CommandMethodAttribute(
System.String groupName,
System.String globalName,
System.String localizedNameId,
Autodesk.AutoCAD.Runtime.CommandFlags flags,
System.String helpTopic)
CommandMethodAttribute(
System.String groupName,
System.String globalName,
System.String localizedNameId,
Autodesk.AutoCAD.Runtime.CommandFlags flags,
System.Type contextMenuExtensionType)
CommandMethodAttribute(
System.String groupName,
System.String globalName,
System.String localizedNameId,
Autodesk.AutoCAD.Runtime.CommandFlags flags,
System.Type contextMenuExtensionType,
System.String helpFileName,
System.String helpTopic)
This example uses the first signature to demonstrate how to use the parameter of localizedNameId:
public class BzhCommands
{
static public void testLocalCommandName()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\nTest command.");
}
}
The third parameter is a String ID pointing to a localized command name in a resource file embedded into the assembly dll. Please note that the key point is that the name of the resource file must be named after the command class.(BzhCommands in this example) Therefore the name of the resource file must be BzhCommands.resx. If the name of the resource file is incorrect, AutoCAD will reject to load the assembly dll though it can be compiled without errors.
The attached C# project defines a localized command name. (BzhTestCommand)
附件是完整工程:
页:
[1]