.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Easy Toolbar

2 REPLIES 2
Reply
Message 1 of 3
lleandro
392 Views, 2 Replies

Easy Toolbar

After looking for a good way of doing a custom Autocad toolbar for our application, the solution I got it was a mix of some solutions I found in the web. In few words, what you need is a Autocad customization file (*.cui) with your personalized toolbar and icon files. Create this file and create a command in your application to upload it and Autocad will take care about the rest for you as its own toolbar. Doing this way, you need to load the toolbar just once and do not wore about taking care of it.

An easy way to create a new *.cui file is typing "cui" in the Autocad command line. In the Cutomize User Interface window, go to the Transfer tab and create you file. TIP: to run your command without the need of typing return put "_" before it. (eg. OPENWINDOW = _OPENWINDOW)

After that, use the code below to upload the *.cui file and find the your icons files and copy them to the right location.
NOTE: You'll need to add AcCui.dll as an assembly reference to your project for this code to build.

[CommandMethod("SHOWTOOLBAR")]
public void cmdShowToolbar()
{
try
{
//Get the default path for the icons files
DirectoryInfo dir = new DirectoryInfo(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("*_TOOLPALETTEPATH").ToString());
dir = new DirectoryInfo(dir.Parent.FullName + "\\Icons");
if (dir.Exists)
{
//GetIcon files path and copy them to the default Autocad icon path
DirectoryInfo dirIcons = new DirectoryInfo("C:\Icons");
FileInfo[] icons = dirIcons.GetFiles("*.bmp");
foreach (FileInfo icon in icons)
icon.CopyTo(dir.ToString() + "\\" + icon.Name, true);

string myCuiFile = "C:\MyFile.cui";
string myCuiFileToSend = "C:/MyFile.cui";
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
string mainCui = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("MENUNAME") + ".cui";
CustomizationSection cs = new CustomizationSection(mainCui);
PartialCuiFileCollection pcfc = cs.PartialCuiFiles;
//Check if the *.cui file is already loaded, if not check if it exists and then load it
if (pcfc.Contains(myCuiFile))
{
ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" already loaded.");
}
else
{
if (System.IO.File.Exists(myCuiFile))
{
ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" exists - loading it.");
LoadMyCui(myCuiFileToSend);
}
}
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error loading toolbar.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void LoadMyCui(string cuiFile)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CMDECHO");
object oldFileDia = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("FILEDIA");

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("CMDECHO", 0);
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", 0);

doc.SendStringToExecute("_.cuiload \"" + cuiFile + "\" ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}

This code based in the "Creating a partial CUI file using .NET and loading it inside AutoCAD" post from 'Through The Interface' blog. (http://through-the-interface.typepad.com/through_the_interface/2007/05/creating_a_part.html) and others information found on the web.
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: lleandro

How do I create a customised toolbar for autocad 2018 using vs 2015 vb.net?

Thank you. 

Message 3 of 3
Alfred.NESWADBA
in reply to: Anonymous

Hi,

 

please do not spam all the threads here about toolbars with your question!

Create a new thread, show what you have, describe the question you have or the point in your code you don't get working .. that's how you get answers without the need for others to read your question appended to other threads.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost