Author Topic: How to create a toolbar from scratch (not trough CUI)  (Read 5317 times)

0 Members and 1 Guest are viewing this topic.

Aerdvark

  • Guest
How to create a toolbar from scratch (not trough CUI)
« on: September 07, 2009, 08:08:26 AM »
Is it possible to make a toolbar (with bitmaps, buttons, fly out buttons etc.) but other then through the CUI?

This is what I am thinking of: 1 folder in wich I store the needed bitmaps, and a kind of .mnu file or so, and what else might be needed.

The advantage by doing it this is that I can develope it myself, even at home, and then install it to multiple PC's at the office.

Or am I getting it wrong? That a toolbar must be made through the CUI and when finished export it to a specific file or so?

I'd be glad with some links or so, for I can't find what I need.

Thanks in advance.

Sorry btw for the poor english, I'm just Dutch... :ugly:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #1 on: September 07, 2009, 08:39:01 AM »
You can get quite a lot of information from the toolbars - tbh I haven't tried creating one from scratch, but I wrote this a while back to retrieve the macros associated with a toolbar:

Code: [Select]
;; Get Macros by Lee McDonnell

(defun GetMac (tNme / lst)
  (vl-load-com)
  (vlax-for Men (vla-get-MenuGroups
                  (vlax-get-acad-object))
    (vlax-for tObj (vla-get-Toolbars Men)
      (if (eq tNme (vla-get-Name tObj))
        (vlax-for bObj tObj
          (setq lst (cons (vla-get-Macro bObj) lst))))))
  (vl-remove "" (reverse lst)))

(defun c:test ()
  (princ
    (vl-princ-to-string
      (GetMac "Object Snap")))
  (princ))



Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #2 on: September 07, 2009, 08:41:49 AM »
Oh, and you can use vla-add on the Toolbars Collection  :wink:

And then maybe use: vla-addToolbarButton, or vla-addSeparator

Aerdvark

  • Guest
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #3 on: September 07, 2009, 09:17:52 AM »
Hi Lee,

Thanks for the reply.

I know you mean good, but I do not get it, I mean, to what you are pointing me to.

There must be a way to create a toolbar without the CUI interference.
I remember having downloaded a zip file once, unpacked in a specific folder and then loaded it.
But I have no clue where I got it from...

Cheers (as you allways say),
Marco.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #4 on: September 07, 2009, 09:29:42 AM »
I have shown you how to get at the Toolbars Collection for each Menu Group - from this you can add a new toolbar and add buttons and separators, or maybe load an existing toolbar.

You can delve further when adding buttons and set Bitmaps for these buttons, for example, here is a dump of a toolbar button:

Code: [Select]
; IAcadToolbarItem: A single button item on an AutoCAD toolbar
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 017891b4>
;   CommandDisplayName = "COPYM"
;   Flyout (RO) = AutoCAD: The toolbar item is not a flyout button
;   HelpString = "Copies objects multiple times with options to repeat, divide, measure, and array"
;   Index (RO) = 10
;   Macro = "\003\003copym "
;   Name = "Multiple Copy"
;   Parent (RO) = #<VLA-OBJECT IAcadToolbar 0e872668>
;   TagString = "ID_ACETCOPYM"
;   Type (RO) = 0
; Methods supported:
;   AttachToolbarToFlyout (2)
;   Delete ()
[color=red];   GetBitmaps (2)
;   SetBitmaps (2)[/color]

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #5 on: September 07, 2009, 09:32:28 AM »
this should get you started:
Code: [Select]
(vla-add (vla-get-toolbars (vla-item (vla-get-menugroups (vlax-get-acad-object)) "ACAD")) "Toolbar Name")
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Aerdvark

  • Guest
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #6 on: September 07, 2009, 09:59:05 AM »
@ alanjt: the code works! Before I go further how do I delete it for through the CUI the toolbar "Toolbar Name" can't be removed.
I have to learn, that is obvious! Edit: it is deleted now but  don't have a clue what I have done.

@ Lee: I am sorry but I can't follow it. My lack...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #7 on: September 07, 2009, 10:17:54 AM »
@ Lee: I am sorry but I can't follow it. My lack...

Alan has shown you how to use the vla-add function, as I described in my earlier post. You can then add buttons and separators to this newly created vla-object, by using the methods I describe above.

Perhaps perform a dump of the new object, using vlax-dump-object to see what properties and methods are available to you.  :-)

After adding buttons, you can customise these buttons individually, by using the various methods and properties that apply to them.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #8 on: September 07, 2009, 11:30:19 AM »
@ alanjt: the code works! Before I go further how do I delete it for through the CUI the toolbar "Toolbar Name" can't be removed.
I have to learn, that is obvious! Edit: it is deleted now but  don't have a clue what I have done.

@ Lee: I am sorry but I can't follow it. My lack...

sorry for the delay:
Code: [Select]
(vla-delete (vla-item (vla-get-toolbars (vla-item (vla-get-menugroups (vlax-get-acad-object)) "ACAD")) "Toolbar Name"))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Aerdvark

  • Guest
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #9 on: September 08, 2009, 07:24:51 AM »
Delay? No probs  :-)

This is what I was looking for:

Code: [Select]
***TOOLBARS
**TOOLS1
TAG1 [Toolbar ("tbarname", orient, visible, xval, yval, rows)]
TAG2 [Button ("btnname", id_small, id_large)]macro
TAG3 [Flyout ("flyname", id_small, id_large, icon, alias)]macro
TAG4 [Control (element)]

I am allready working with it, so that means that I got where I wanted to be.

Ofcourse it will go wrong and I will come to ask for help but for now I'm glad to have found this.

I attached a menu tutorial for other interested people.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #10 on: August 31, 2012, 02:06:48 AM »
Hi!

Yes I know it a old thread but I have a simple question...
I didnīt find how can I display screen menu  ?

Quote
Create Screen Menus
The screen menu section of the MNU file controls the screen menu area.
By default, the screen menu is disabled. To enable the screen menu, click
Display Screen Menu on the Display tab in the Options dialog box.
In the MNU file, the ***SCREEN section label represents the beginning of the
AutoCAD screen menus. The submenu section label shown here is identified
by the string **S. A simple, concise name, such as this, is convenient when
many separate items reference this submenu, as shown in the following
example:

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #11 on: August 31, 2012, 02:40:06 AM »
Look at the ScreenMenu system variable: 0=off, 1=on. So you can use setvar to change that.

There's one problem though (at least since 2012, don't know from when this happened) ... the CUI does not show a Screen Menu section. So if you want to edit it, you'll need to modify a CUI in an older ACad. And the ActiveX object only has methods for working with toolbars and pop-up menus.

Another alternative would be to create an old MNU file in Notepad and load it through the menugroups object.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #12 on: August 31, 2012, 03:00:03 AM »
Thanks for intressting link irneb.
Maybe Iīm blind I donīt get it where have Autocad a sysvar screenmenu to can on/off
Is it right?

Or I understand it not correctly, I load mnu-file looks like this
Code: [Select]
//
//      AutoCAD menu file -
//

***SCREEN
**S
[AutoCAD ]^C^C^P(ai_rootmenus) ^P
[* * * * ]$S=ACAD.OSNAP
[FILE    ]$S=ACAD.01_FILE
[EDIT    ]$S=ACAD.02_EDIT
[VIEW 1  ]$S=ACAD.03_VIEW1
[VIEW 2  ]$S=ACAD.04_VIEW2
[INSERT  ]$S=ACAD.05_INSERT
[FORMAT  ]$S=ACAD.06_FORMAT
[TOOLS 1 ]$S=ACAD.07_TOOLS1
[TOOLS 2 ]$S=ACAD.08_TOOLS2
[DRAW 1  ]$S=ACAD.09_DRAW1
[DRAW 2  ]$S=ACAD.10_DRAW2
[DIMNSION]$S=ACAD.11_DIMENSION
[MODIFY1 ]$S=ACAD.12_MODIFY1
[MODIFY2 ]$S=ACAD.13_MODIFY2
[HELP    ]$S=ACAD.14_HELP
[ASSIST ]$S=ACAD.ASSIST
[LAST   ]$S=ACAD.

But nothing happens, whatīs wrong?

Regards Dirk

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #13 on: August 31, 2012, 04:00:21 AM »
You're correct. It seems that it doesn't overwrite the existing one. You could of course extract the files inside the ACAD.CUIX (it's simply a zip file). Then you can modify the extracted ScreenMenuRoot.cui file (it's simply a XML file). Though you're discouraged from editing CUI(x) files manually and they're not nearly as easy to understand as MNU's (especially since there's no documentation about their structure).

Edit: of course if you really "want" to ... you can get into this using DotNet. It does expose the ScreenMenu & ScreenMenuItem classes. But of course then you can't directly work on them from ALisp - you'll need VB.Net or C#, at least as intermediate to add property get/set functions and/or method wrappers for lisp to call.
« Last Edit: August 31, 2012, 04:04:38 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #14 on: August 31, 2012, 04:23:39 AM »
Youīre great - have much ideas  :-o I thoug I could fresh up my popup menus without to do it in cui-interface. So I read pdf file from Aerdvark and than I do something wrong, because I donīt understand what it means in cit "...display screen menu" Do you know it?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #15 on: August 31, 2012, 05:16:47 AM »
The screen menu is something very old. It came from the DOS days in the 80's. Basically a column along the right-side of the screen with text in it. Each line of that column was a menu item. So you had the command-line and the screen menu, and that was it - unless you also used a tablet.

The nice thing about screen menus was that they'd update in context. E.g. while the line command is active, the relevant screen menu would be displayed for options useful in the line command.

Since around R10 (though I cannot remember exactly which version) the pull-down menus were added to the top of the screen. Then later toolbars, palettes, and finally the ribbon. The screen menu has previously been deprecated as a Legacy item (quite a while back), and recently it's been removed from the CUI interface entirely. It's still inside the CUI(x) file, but just never shown for editing.

Other stuff in the Legacy deprecated branch is Tablet areas, Tablet buttons and Image tiles. So taking the example of what's happened to screen menus, it's possible that these might also "disappear" in the future.

My best advise is to start moving your customizations into some of the newer UI elements. E.g. Ribbon panels - they provide the same functionality as you got from the screen menu (e.g. a ribbon specific to the current command opens when that command is active). You could use some of the others as well, e.g. tool palettes / toolbars / pop-up menus / pull-down menus / etc.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #16 on: August 31, 2012, 05:25:04 AM »
And just to be clear. The code you've shown is part of the old MNU files. These have also been replaced by CUI(x) files. You can still load them, but what happens is acad converts them into CUI(x) files then loads those.

You can edit CUI(x) files as you could MNU's (see my previous link about XML files), but ADesk warns that such might break stuff like automatic updates. And of course since they're not documented, it's very easy to break something because you don't know exactly what each thing does.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #17 on: August 31, 2012, 05:28:23 AM »
If you mean you still cannot see the screen menu, then use autolisp to turn it on. Copy the following into your command line
Code: [Select]
(setvar "screenmenu" 1)You should then get a panel on the right side of the ACad screen looking like this.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #18 on: August 31, 2012, 06:21:58 AM »
Ohhhha :-) little history Iīd like the 80īs but no only music... :kewl:
I think sometimes itīs great to have a menu with important internetlinks from different discussions and my firefox favorites explode quit similar. So itīs maby an idea to do this with screen menue. I set var sreenmenu on (1) but get only emty screen menu even I loaded same MNU-file like example views.

I have done it before I use CUI with MNS-files, but there is not opportunities to build in images or not?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #19 on: August 31, 2012, 06:44:27 AM »
I set var sreenmenu on (1) but get only emty screen menu even I loaded same MNU-file like example views.
Strange, then your CUI file may have been edited and its ScreenMenu portion removed. Which version / vertical of ACad are you using?

I have done it before I use CUI with MNS-files, but there is not opportunities to build in images or not?
Nope, screen menus are ONLY text. If you want images as well, then use some of the other stuff - perhaps a tool palette would work better for your scenario.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: How to create a toolbar from scratch (not trough CUI)
« Reply #20 on: August 31, 2012, 07:14:44 AM »
Thanks!

I test it in both civil 2011 and 2012 same happening...

good idea with Toolpalettes I havenīt thougt about it.