Author Topic: CommandMethodAttribute & localizedNameId  (Read 4914 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
CommandMethodAttribute & localizedNameId
« on: June 14, 2011, 10:47:31 AM »
Hi.
  From ObjectARX 2009:
Code: [Select]
public CommandMethodAttribute(
    string groupName,
    string globalName,
    string localizedNameId,
    CommandFlags flags,
    Type contextMenuExtensionType,
    string helpFileName,
    string helpTopic
);
 How can I use localizedNameId? I don't want use null. Give me code sample please...

  From ObjectARX 2009: string localizedNameId -  Input command localized name Id.
quote here:
Quote from: *Tony Tanzillo
The LocalizedNameId is the string resource identifier
of the localized name of the command. If provided,
the localized name of the command is obtained from
the resource, which can be stored in a locale-specific
satellite resource assembly.
"resource" - is it resx-file in MS VS 2010?

if I set string value (for example "cmd1") for localizedNameId directly then:
Quote from:  acad command string
Command: netload
Cannot load assembly. Error details:
System.Resources.MissingManifestResourceException: Could not find any resources
appropriate for the specified culture or the neutral culture.  Make sure
"LocalizationExample.Class1.resources" was correctly embedded or linked into
assembly "LocalizationExample" at compile time, or that all the satellite
assemblies required are loadable and fully signed.
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo
culture)
   at System.Resources.ResourceManager.GetString(String name)
   at Autodesk.AutoCAD.Runtime.CommandClass.AddCommand(ICommandLineCallable ca,
MethodInfo mi)
   at
Autodesk.AutoCAD.ApplicationServices.AutoCADApplicationHolder.Initialize(Assembl
y assembly)
   at
Autodesk.AutoCAD.ApplicationServices.ExtensionLoader.ProcessAssembly(Assembly
assembly)

thank you.
« Last Edit: June 14, 2011, 10:57:08 AM by Andrey »


Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CommandMethodAttribute & localizedNameId
« Reply #2 on: June 14, 2011, 12:31:33 PM »



Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CommandMethodAttribute & localizedNameId
« Reply #5 on: June 14, 2011, 03:14:23 PM »
Do I understand that no one has experience in the localization team by setting localizedNameId?  :cry:

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CommandMethodAttribute & localizedNameId
« Reply #6 on: June 15, 2011, 04:12:09 AM »
There can be it will help with understanding of an essence of my problems (they are specified in code comments):
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using acad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;

/*
 * Windows XP SP3 x86
 * AutoCAD 2009 SP3 Enu
 * .Net Framework 3.5 SP1
 * Microsoft Visual Studio 2010
 */

namespace LocalizationExample {

    public sealed class Class1 {        
        const string grName = "bush";
        //It works successfully
        const string helpFileName = @"Debug\help\ru-RU\MyHelp_ru-RU.chm";
        //It works successfully
        const string helpTopic = "t2";
        //With it couldn't understand (if to use this variable - I receive an error at NetLoad)
        public const string locname = "cmd1";

        [CommandMethod(grName, "cmd", /*locname - it was not possible to use, ObjectARX 2009
                                       * doesn't contain an example of usage of this parameter (localizedNameId).*/
            null, CommandFlags.Modal,
            typeof(ExampleContextMenu), helpFileName, helpTopic)]        
        public void MyCommand() {
            Editor ed = acad.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("Hello World \n");
            ed.GetString("Print message");
        }
    }

    /// <summary>
    /// http://through-the-interface.typepad.com/through_the_interface/2008/11/displaying-a-co.html
    /// </summary>
    public sealed class ExampleContextMenu : ContextMenuExtension {
        public ExampleContextMenu() {
            this.Title = "Command context menu";//This text isn't displayed anywhere. Where it should appear?
            MenuItem mi = new MenuItem("Item One");
            //The specified file (Config.ico) exists! Why this icon isn't displayed?
            Icon icon = new System.Drawing.Icon(@"D:\123\LocalizationExample\images\Config.ico");
            mi.Icon = icon;
            MenuItem smi = new MenuItem("Sub Item One");
            smi.Enabled = false;
            mi.MenuItems.Add(smi);
            smi = new MenuItem("Sub Item 2 One");
            smi.Checked = true;
            mi.MenuItems.Add(smi);
            this.MenuItems.Add(mi);
            mi = new MenuItem("Item Two");
            mi.Visible = false;
            this.MenuItems.Add(mi);
        }
    }
}

Context menu screen: https://docs.google.com/leaf?id=0B7H_2Cq9tBXdZmEyNzQ2ODQtMzNlMi00OTA5LWIyZjgtZThlNzg5MmQ1YTc2&hl=ru
« Last Edit: June 15, 2011, 04:18:56 AM by Andrey »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: CommandMethodAttribute & localizedNameId
« Reply #7 on: June 15, 2011, 06:15:13 AM »
It works for me.

The pic is supposed to be your Avatar but is hard to see the cat.

The icon must be 16x16.

The code is straight from the link in your code from Through the interface http://through-the-interface.typepad.com/through_the_interface/2008/11/displaying-a-co.html
Just added the icon part
Code: [Select]
  public class MyCommands
    {
        public class MyContextMenu : ContextMenuExtension
        {

            public MyContextMenu()
            {

                this.Title = "Command context menu";
                Icon icon = new Icon(@"C:\Users\Jeff\Pictures\ICO\avatar_6108.ico");

                MenuItem mi = new MenuItem("Item One");
                mi.Icon = icon;
                mi.Click += new EventHandler(MyCommands.OnClick);
                this.MenuItems.Add(mi);

                mi = new MenuItem("Item Two");

                mi.Click += new EventHandler(MyCommands.OnClick);

                this.MenuItems.Add(mi);


                MenuItem smi = new MenuItem("Sub Item One");

                smi.Click += new EventHandler(MyCommands.OnClick);

                this.MenuItems.Add(smi);

            }

        };
        [CommandMethod("mygroup", "mycmd", null, CommandFlags.Modal, typeof(MyContextMenu))]

        public static void MyCommand()
        {

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.GetPoint("\nRight-click before selecting a point:");

        }
        static void OnClick(object sender, EventArgs e)
        {

            Editor ed =

              Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\nA context menu item was selected.");

        }
}


Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CommandMethodAttribute & localizedNameId
« Reply #8 on: June 15, 2011, 06:58:36 AM »
The pic is supposed to be your Avatar but is hard to see the cat.
The icon must be 16x16.
Yes, I know.
It works for me.
What version at you AutoCAD? I have AutoCAD 2009 SP1 x86.

p.s. With parameter localizedNameId I have understood (me Alexander Rivilis has helped).

Jeff H

  • Needs a day job
  • Posts: 6150
Re: CommandMethodAttribute & localizedNameId
« Reply #9 on: June 15, 2011, 07:11:54 AM »
2012