Author Topic: Why my program of toolbar shows only a separator?  (Read 5383 times)

0 Members and 1 Guest are viewing this topic.

xys1995

  • Guest
Why my program of toolbar shows only a separator?
« on: August 14, 2006, 10:21:35 PM »
My program create a new toolbar and add a toolbar button in it. But the reuslt is:It only create a toolbar with a separator? Can anyone help me to find the reason.thanks! 
The program is as follow:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Customization;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

namespace toolbarS
{
    public class ToolbarS
    {
        CustomizationSection cs;
        CustomizationSection entCs;
        CustomizationSection[] partials;
       
        int numPartialFiles;

        bool entCsLoaded;
        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

        public ToolbarS()
        {
            string mainCUIFile = (string)Application.GetSystemVariable("MENUNAME");
            mainCUIFile += ".cui";
            cs = new CustomizationSection (mainCUIFile);

            string entCUIFile = (string)Application.GetSystemVariable("ENTERPRISEMENU");
            if (entCUIFile.Equals("."))
                entCsLoaded = false;
            else
            {
                entCsLoaded = true;
                entCs = new CustomizationSection (entCUIFile);
            }

            partials = new CustomizationSection [cs.PartialCuiFiles.Count];
            int i = 0;
            foreach (string filename in cs.PartialCuiFiles)
            {
                if (File.Exists(filename))
                {
                    partials = new CustomizationSection(filename);
                    i++;
                }
            }
            numPartialFiles = i;
        }

        [CommandMethod("savecui")]
        public void saveCui()
        {
            if (cs.IsModified)
                cs.Save();

            for (int i = 0; i < numPartialFiles; i++)
            {
                if (partials.IsModified)
                    partials.Save();
            }

            if (entCsLoaded && entCs.IsModified)
                entCs.Save();
            string flname = cs.CUIFileBaseName;
            Application.SetSystemVariable("FILEDIA", 0);
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiunload " + flname + " ", false, false, false);
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiload " + flname + " filedia 1 ", false, false, false);
        }
           
        [CommandMethod("addtoolbar")]
        public void addToolbar()
        {
           
             MacroGroup mg = new MacroGroup("shenbo", cs.MenuGroup);
             MenuMacro mm= new MenuMacro(mg, "someinfo", "showMessage", "ID_INFO");
             mm.macro.SmallImage = @"f:\comp.bmp";
             mm.macro.LargeImage = @"f:\comp.bmp";
            Toolbar newToolbar = cs.MenuGroup.Toolbars.FindToolbarWithName("MyToolbar");
            if (newToolbar != null)
                ed.WriteMessage("the toolbar has existed!");
            else
            {
                newToolbar = new Toolbar("MyToolbar", cs.MenuGroup);
                newToolbar.ToolbarOrient = ToolbarOrient.floating;
                newToolbar.ToolbarVisible = ToolbarVisible.show;

                ToolbarButton tbb = new ToolbarButton(newToolbar, -1);
                tbb.Name = "testButton";
                tbb.MacroID ="ID_INFO";
             
                foreach (Workspace wk in cs.Workspaces)
                {
                    WorkspaceToolbar wkTb = new WorkspaceToolbar(wk, newToolbar);
                    wk.WorkspaceToolbars.Add(wkTb);
                    wkTb.Display = 1;
                }
                saveCui();
            }
      }

     [CommandMethod("showMessage")]
        public void showMessage()
        {
            ed.WriteMessage("ok");
        }
   }
}

xys1995

  • Guest
Re: Why my program of toolbar shows only a separator?
« Reply #1 on: August 14, 2006, 10:26:32 PM »
PS:   AutoCAD2007 + VS2005

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Why my program of toolbar shows only a separator?
« Reply #2 on: August 15, 2006, 06:29:06 AM »
I haven't played with toolbars yet ...

Did you get these build errors ?

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Why my program of toolbar shows only a separator?
« Reply #3 on: August 15, 2006, 06:48:40 AM »
Try this modification ..
Code: [Select]
            //
            // modified kwb 20060815
            //for (int i = 0; i < numPartialFiles; i++)
            //{
            //    if (partials.IsModified)
            //        partials.Save();
            //}

            for (int i = 0; i < numPartialFiles; i++)
            {
                if (partials[i].IsModified)
                    partials[i].Save();
            }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Why my program of toolbar shows only a separator?
« Reply #4 on: August 15, 2006, 06:50:30 AM »
and this ..
Code: [Select]
            //int i = 0;
            //foreach (string filename in cs.PartialCuiFiles)
            //{
            //    if (File.Exists(filename))
            //    {
            //        partials = new CustomizationSection(filename);
            //        i++;
            //    }
            //}
            int i = 0;
            foreach (string filename in cs.PartialCuiFiles)
            {
                if (File.Exists(filename))
                {
                    partials[i] = new CustomizationSection(filename);
                    i++;
                }
            }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Why my program of toolbar shows only a separator?
« Reply #5 on: August 15, 2006, 07:10:23 AM »
So ..
I changed this to suit an available BMP .. and  success !!
Code: [Select]
            //mm.macro.SmallImage = @"f:\comp.bmp";
            //mm.macro.LargeImage = @"f:\comp.bmp";
            mm.macro.SmallImage = @"K:\ICON_16_AULPIDE.bmp";
            mm.macro.LargeImage = @"K:\ICON_16_AULPIDE.bmp";

edited : and the piccys added
« Last Edit: August 15, 2006, 07:32:49 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

xys1995

  • Guest
still can not work!
« Reply #6 on: August 16, 2006, 01:45:21 AM »
I have modified the code as you say.The toolbar has shown but still a separator.
Do you use AutoCAD2007 and VS2005?
Should I set some envirment of AutoCAD2007,or VS2005?

xys1995

  • Guest
and
« Reply #7 on: August 16, 2006, 01:55:15 AM »
and when I click the item MyToolbar in the Customize User Interface,an error was shown as follow:
It is a JIT debug error.(The application does not support Windows JIT.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Why my program of toolbar shows only a separator?
« Reply #8 on: August 16, 2006, 02:28:24 AM »
Quote
Do you use AutoCAD2007 and VS2005?
Yes

Quote
Should I set some envirment of AutoCAD2007,or VS2005?
I haven't.


Have you removed/deleted the original toolbar definition from your CUI before re-running the routine ?

... and, can you post the error message dump as a txt file ? .. I cant read the full first line of the exception in the piccy you posted.
« Last Edit: August 16, 2006, 02:30:59 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

xys1995

  • Guest
strange
« Reply #9 on: August 16, 2006, 04:53:37 AM »
Have you removed/deleted the original toolbar definition from your CUI before re-running the routine ?

YES!

I reinstall my AutoCAD2007,and run my progarm again,everything is ok!

But when I try to add another toolbar button in the toolbar,the same error occurs.you can try it!
the red color code was newly added!


public void addToolbar()
        {
              MacroGroup mg = new MacroGroup("shenbo", cs.MenuGroup);
             MenuMacro mm= new MenuMacro(mg, "someinfo", "showMessage", "ID_INFO");
             mm.macro.SmallImage = @"f:\comp.bmp";
             mm.macro.LargeImage = @"f:\comp.bmp";

        // add the folowing code: xys 06-08-16
           
             MenuMacro mm1 = new MenuMacro(mg, "anyinfo", "showInfo", "ID_MESS");
             mm1.macro.SmallImage = @"f:\equcopy.bmp";
             mm1.macro.LargeImage = @"f:\equcopy.bmp";


           ..............................
           ...............................
         
             ToolbarButton tbb = new ToolbarButton(newToolbar, -1);
              tbb.Name = "testButton";
              tbb.MacroID ="ID_INFO";

             // add the folowing code: xys 06-08-16
              ToolbarButton mytb = new ToolbarButton(newToolbar, -1);
              mytb.Name = "showButton";
              mytb.MacroID = "ID_MESS";


            ..............................
           ...............................
       }
   

      // and a new function:
      [CommandMethod("showInfo")]
        public void showInfo()
        {
            ed.WriteMessage("\nit is a test");     
        }

     

       

         
           








xys1995

  • Guest
the source file
« Reply #10 on: August 16, 2006, 05:04:52 AM »
the source file