AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Page I. Page II Page III. Home.

Creating Menu's - Page IV.

Custom Toolbars

The easiest way of creating a custom toolbar is to use the AutoCAD interface.
First, copy and rename Test4.MNU to Test5.MNU. Edit the menu file so that it looks like this : 

***MENUGROUP=TEST5

***POP1
P1_1[&Test Menu 5]
P1_2[&Layer 2 On]^C^CLayer;M;2;;
P1_3[--]
P1_4[&Ortho On/Off]^C^C^O
P1_5[--]
P1_6[->&Change]
P1_7[->C&hange Layer]
P1_8[Change to Layer 1]^C^CChange;\;P;LA;1;;
P1_9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1_10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1_11[<-Change to Layer 4]^C^CChange;\;P;LA;4;;
P1_12[->Ch&ange Colour]
P1_13[Change to Colour 3]^C^CChange;\;P;C;1;;
P1_14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1_15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1_16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;;
P1_17[--]
P1_18[&Kenny](alert "Kenny is Handsome")
P1_19[--]
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=*

***IMAGE
**DOORS
[DOORS Created by Kenny Ramage ]
[DOORS(D1,DOOR1)]INSERT;*D1;\;;
[DOORS(D2,DOOR2)]INSERT;*D2;\;;
[DOORS(D3,DOOR3)]INSERT;*D3;\;;
[DOORS(D4,DOOR4)]INSERT;*D4;\;;
[DOORS(D5,DOOR5)]INSERT;*D5;\;;
[DOORS(D6,DOOR6)]INSERT;*D6;\;;
[DOORS(D7,DOOR7)]INSERT;*D7;\;;
[DOORS(D8,DOOR8)]INSERT;*D8;\;;
[DOORS(DDOOR,DOUBLE DOOR)]INSERT;*DDOOR;\;;
[DOORS(HDDOOR,DOOR & HALF)]INSERT;*HDDOOR;\;;
[ FITTINGS]$I=KENNY.FITTINGS $I=*

Open AutoCAD and load this new menu file.

Now, to create a new toolbar, follow these steps :

Right Click on any toolbar.
The Toolbars Dialogue will open.

M8

Select "New".
The New Toolbar dialogue will open

M8a

In the "Toolbar Name" edit box enter "Testbar" and from the "Menu Group" drop down list select Test5.mnu
Select O.K.
A small empty toolbar will appear on your screen.
Select "Customize" from the "Toolbars" dialogue.
The "Customize Toolbars" dialogue will open.

M8b

In the "Catagories" list box select "Custom".
Select the blank tile then drag and drop it onto your empty toolbar.
Repeat this so that you have 3 blank tiles on your toolbar.
Your toolbar should look like this :

M7

Select "Close"
You now have a toolbar with 3 buttons that do exactly nothing!!

Right Click on the first blank tile.
The "Button Properties" dialogue will open.

M9

In the "Name" edit box type "Test Tool 1".
This will appear as a tooltip.
In the "Help" edit box type "This is Test Button 1".
This will appear in the status bar.
In the "Macro Edit" edit box enter :

^C^C(Alert "Test Tool 1")

This is the action assigned to this button.

Now, from the "Button Icon" list, select the first blank tile, then "Edit".
The "Button Editor" will open.

M10

Select "Grid" to place a grid over your button.
Using the edit tools and the colour palette, draw the image that you would like to appear on your button.
When you are happy select "Save" then "Close".
In the "Buttons Properties" dialogue select "Apply".
You will notice your completed button appear in your toolbar.

Right Click on the second button and repeat the process, naming the button "Test Tool 2".
Then again for the third button naming it "Test Tool 3".

When you have finished and have closed all dialogue boxes, your toolbar should look something like this :

M11

Select any of the buttons on the toolbar and you should get an alert message.
Now Exit AutoCAD.

Open Test5.mnu
Do you notice that nothing has changed and there is no Toolbar section in the MNU file?
The reason for this is because when you Add, Move or Edit any toolbars using the AutoCAD interface, the results are written to the MNS file and not to the MNU file. To update the MNU file and make our changes permanent, we need to copy and paste the toolbars section from the MNS file into the MNU file.
Right, let's do that. Your MNU file should now look like this : 

***MENUGROUP=TEST5

***POP1
P1_1[&Test Menu 5]
P1_2[&Layer 2 On]^C^CLayer;M;2;;
P1_3[--]
P1_4[&Ortho On/Off]^C^C^O
P1_5[--]
P1_6[->&Change]
P1_7[->C&hange Layer]
P1_8[Change to Layer 1]^C^CChange;\;P;LA;1;;
P1_9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1_10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1_11[<-Change to Layer 4]^C^CChange;\;P;LA;4;;
P1_12[->Ch&ange Colour]
P1_13[Change to Colour 3]^C^CChange;\;P;C;1;;
P1_14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1_15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1_16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;;
P1_17[--]
P1_18[&Kenny](alert "Kenny is Handsome")
P1_19[--]
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=*

***IMAGE
**DOORS
[DOORS Created by Kenny Ramage ]
[DOORS(D1,DOOR1)]INSERT;*D1;\;;
[DOORS(D2,DOOR2)]INSERT;*D2;\;;
[DOORS(D3,DOOR3)]INSERT;*D3;\;;
[DOORS(D4,DOOR4)]INSERT;*D4;\;;
[DOORS(D5,DOOR5)]INSERT;*D5;\;;
[DOORS(D6,DOOR6)]INSERT;*D6;\;;
[DOORS(D7,DOOR7)]INSERT;*D7;\;;
[DOORS(D8,DOOR8)]INSERT;*D8;\;;
[DOORS(DDOOR,DOUBLE DOOR)]INSERT;*DDOOR;\;;
[DOORS(HDDOOR,DOOR & HALF)]INSERT;*HDDOOR;\;;
[ FITTINGS]$I=KENNY.FITTINGS $I=*

***TOOLBARS
**TESTBAR
ID_1 [_Toolbar("Testbar", _Floating, _Show, 202, 163, 1)]
ID_2 [_Button("Test Tool 1", "ICON.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 1") 
ID_3 [_Button("Test Tool 2", "ICON0041.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 2") 
ID_4 [_Button("Test Tool 3", "ICON8467.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 3") 

Let's take a closer look at the toolbars section :

***TOOLBARS is, of course, the label for the start of the toolbars section. **TESTBAR is the label for the Toolbar Subsection.
The first Toolbar definition line (ID_1) defines the characteristics of
the toolbar itself. This is made up of 6 parts : 

tbarname	The string that names the toolbar. ("Testbar")
orient		The orientation of the toolbar. (Floating)
		Acceptable values are Floating, Top, Bottom,
		Left and Right.
visible		The visibility of the toolbar. (Show)
		Acceptable values are Show and Hide.
xval		The x co-ordinate of the toolbar (202)
		Measured from the left edge of the screen to the
		right side of the toolbar. (in pixels)
yval		The y co-ordinate of the toolbar. (163)
		Measured from the top edge of the screen to the
		top of the toolbar. (in pixels)
rows		Number of rows in the toolbar (1)

The second and remaining Toolbar definition lines (ID_2 to ID_4) define the characteristics of the buttons. They are each made up of 3 parts : 

btnname		The string that names the button. ("Test Tool 1")
id_small	The name of the small image bitmap (ICON.bmp)
		(16 x 16 bitmap)
id_big		The name of the large image bitmap (ICON_24_BLANK)
		(24 x 24 bitmap)
macro		Action/Command assigned to the button.

Did you notice that a blank tile is in place of the large 24 x 24 bitmap.
The reason for this, of course, is because we never defined a large bitmap.
If I require large bitmaps I use an imaging editing package to increase the size of my existing 16 x 16 bitmap to 24 x 24 and save it as a large bitmap, adding "24" to the end of the name.

Anyway, that's about it. I hope that you managed to muddle your way through this lot and that you will soon be writing your own partial menu's.

I don't know about you, but this is thirsty work, so I'm off for an extremely large, cold beer. (or 10). Cheers for now....... 


To download this complete Tutorial including, all Menu's and Support files,
be brave and Click Here.

 
Page I. Page II. Page III. Home.

 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website