TheSwamp
Code Red => .NET => Topic started by: xys1995 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");
}
}
}
-
PS: AutoCAD2007 + VS2005
-
I haven't played with toolbars yet ...
Did you get these build errors ?
-
Try this modification ..
//
// 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();
}
-
and this ..
//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++;
}
}
-
So ..
I changed this to suit an available BMP .. and success !!
//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
-
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?
-
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.
-
Do you use AutoCAD2007 and VS2005?
Yes
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.
-
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");
}
-
the source file