Automating creation of ribbon or tool bar to run lisps

Automating creation of ribbon or tool bar to run lisps

comcu
Participant Participant
915 Views
15 Replies
Message 1 of 16

Automating creation of ribbon or tool bar to run lisps

comcu
Participant
Participant

Hi, can anyone advise a way to automate the creation of a toolbar/ ribbon panel based on a list of lisp commands in a text file or an excel file?

 

I normally distribute my lisp within my company as fas file with a text file the user can add to pgp file to call lisp commands. Problem is not everyone uses the keyboard to call commands and I am being asked more and more if the can be called from the ribbon. I know how to do this manually but the manual method I would use is time consuming, appreciate it would be easier just maintaining it once the bulk was set up but then it’s the distribution and loading onto each computer. Ultimately I don’t want to save time using lisp that I then lose creating alternative methods of calling lisps. I have done a bit research and I can’t find a method of lisp creating ribbon panels.

 

Most users have never been in the cui so ideally for the user to load, it would be a simple for the users as loading my fas files via appload and adding a few lines to the bottom for the pgp. Any advice?

0 Likes
916 Views
15 Replies
Replies (15)
Message 2 of 16

cadffm
Consultant
Consultant
Accepted solution

Hi,

 

If I am right, Lisp is not designed to create/edit ribbon-stuff

so

create your own Ribbon TAB in your own .cuix file

check if the file is loaded, if not

cuiload with lisp

 

if you don't want an extra Tab, you can set up your custom Tab to merge with (f.e. the Home Tab)

That's a clean way

?

 

 

 

>>"I normally distribute my lisp within my company as fas file with a text file the user can add to pgp file to call lisp commands.

Why do you need a .pgp ? (defun c: should override the .pgp shortcuts, or not?

 

BTW: You could edit the .pgp file by lisp too.

 

Two ways without any user action

 
 

 

 

Sebastian

0 Likes
Message 3 of 16

CodeDing
Advisor
Advisor
Accepted solution

@comcu ,

 

Create your Ribbon/cuix file, and be sure it's in a shared location (like network drive). Also take note of the NAME of your Customization file, it's located here:
image.png

 

Our Ribbon tab tends to disappear sometimes, so I created a command to fix it (all of our "fix" commands are prefixed with "FIX"...). This command will check if the Customization file exists, and force-reload it for the user (if you have a Ribbon in your CUIX, it will populate it):

;; Fixes the problem where "HCL" ribbon does not appear sometimes for users
(defun c:FIXRIBBON ( / menuPath menuGroups)
  (setq menuPath "N:\\folder\\path\\to\\custom.cuix")
  (if (findfile menuPath)
    (progn
      (setq menuGroups (vlax-get (vlax-get (vla-get-preferences (vlax-get-acad-object)) 'Application) 'MenuGroups))
      (vlax-for mg menuGroups
        (if (eq "HCL_CUSTOM" (vlax-get mg 'Name))
          (vlax-invoke mg 'Unload)
        );if
      );vlax-for
      (command "_.MENULOAD" menuPath) (command)
    );progn
  ;else
    (prompt (strcat "\nCould not find custom menu:\n" menuPath))
  );if
  (princ)
);defun

 

...eventually I just added a check inside my acad.lsp file so users don't even have to worry about a 'Fix':

;; Loads custom HCL cuix file, if user doesn't have loaded already.
((lambda ( / mgList)
  (vlax-for m (vla-get-menugroups (vlax-get-acad-object))
    (setq mgList (cons (vlax-get m 'Name) mgList))
  );vlax-for
  (if (not (member "HCL_CUSTOM" mgList))
    (command "_.CUILOAD" "N:\\folder\\path\\to\\custom.cuix")
  );if
  (princ)
))

 

Best,

~DD

0 Likes
Message 4 of 16

paullimapa
Mentor
Mentor
Accepted solution

Here's a video tutorial on how to create a partial menu (cui) file that you can include to accompany your lisp routine. 

Note: Plug-ins tab is now called Add-ins tab

https://www.youtube.com/watch?v=US-OBbIo7XQ

Then include instructions on how to load the partial cui file into AutoCAD as similarly shown here:

https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-55B0E62E-9F40-4A95-BCE6-180EB47C9DDD


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 16

Sea-Haven
Mentor
Mentor
Accepted solution

Unfortunately when Autocad introduced the Ribbon they threw away make from a mnu which is just a text file, so have to use the CUI, a side note a CUIX is a zipped file containing many CUI files which are in XML format. Yes have looked many times at make a CUI ie write a correct XML sounds simple but its not. Anyway for me I have no drama making toolbars or pop menu's. I did write some lisp that makes a pop menu a sort of copy lisp names and make into a mnu file about 80% of what is needed. The Toolbar needs images you can steal them from the CUI as you just need a name. Or else you need to make your own which is not that hard but have to work in like a 32x32 pixel box. 

So this has 130+ lisps.

SeaHaven_0-1741134165059.png

You can call via image selection from the pop menu good for blocks or a visual choice. This is inbuilt in a pop menu including Next where you have more than 20 images.

SeaHaven_1-1741134246226.png

A toolbar is similar.

SeaHaven_2-1741134336817.png

 

Happy to provide more information. Using Excel can help make a mnu as you can copy/paste multiple rows.

 

For any one else make a copy of your CUIX rename to ZIP and have a look.

 

0 Likes
Message 6 of 16

comcu
Participant
Participant

Gents, thank you for your assistance and guidance. There a lot to take on board so bear with me but all real good guidance.

0 Likes
Message 7 of 16

scot-65
Advisor
Advisor
Accepted solution

@comcu 

One last method which will require not only an additional pick, but possibly scrolling as well.

 

Create a dialog with a list box where the list box is populated with the contents of a directory (with wildcard filtering of the file extension names) and allow the user to make a selection.

It's not that hard to strip out the file extension when creating the list, but the trick is to make name recognizable.

Create a toolbar/ribbon/menubar/toolpalette button to call forward the dialog.

 

Here is a similar example:

 

scot65_0-1741215603538.png

 

To expand on the use of this dialog, add a "Browse" button to find the target directory and save this information in the registry in case the directory changes. That way the dialog LSP/FAS program itself will not have to be reissued.

 

I know the feeling "The keyboard is a sacred object and only used to compose emails" syndrome.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 8 of 16

comcu
Participant
Participant

Hi Sebastian, I am not aware of lisp being able to edit the pgp but I have set up a separate lisp file that effectively is a command alias calling a longer lisp name. The problem is when you type the lisp defined alias the full name is not shown in brackets the way it is shown if set up in the pgp file eg AB (ARRAY-BLOCK) is just AB unless set up in lisp. If you know a way of automatically adding text to the bottom of the users pgp file that would be very useful. I have seen lisps that save data to .txt or csv file so wonder if it is a simple as knowing the pgp path and just getting lisp to add text to the bottom and just save as .pgp instead of .txt.

0 Likes
Message 9 of 16

comcu
Participant
Participant

I have got quite familiar with the cui over the year but never got to grips with custom cui. I too have had issue with items disappearing like the QAT  so I find that exporting the QAT and then transferring it back in works well. I do that with any bespoke keyboard shortcuts so assume that I could save time if I could get a grip of how the custom cui work. Is your custom cui effectively a copy of the original cui with items added or does the custom cui just contain items you created and the normal cui is also present? Apologies if my terms are wrong but hope I am make sense.

0 Likes
Message 10 of 16

comcu
Participant
Participant

Hi Paul, thank you for this. As mentioned I have struggled with custom cui (and just added to the main, and export my custom items as back up) so will read the info you referenced. Hoped I will soon be enlightened. Many thanks.

0 Likes
Message 11 of 16

comcu
Participant
Participant

Sea-Haven, this is very interesting. I have set up menu before to be called like the snap menu but always manually created them. Examples you show are much better than I have achieved. I have generally used chat to generate images but it can be quite tedious and very hit and miss. Is the form with 20 images a dialogue box you created, how does excel work, in terms of creating the examples you show? I have yet to use dialogue boxes with my lisp but have read thru how to create and wanted to start building the in to some lisps. I think it was the Afralisp website I saw tutorials.

0 Likes
Message 12 of 16

comcu
Participant
Participant

Scot-65, thank you for the guidance. I will give this a try, I group my lisps into group names autocad uses like draw and modify so potentially I add the buttons to call the dialogue boxes from these sections of the ribbon. I will read up more on dialogue boxes and give it a try. Many thanks 

0 Likes
Message 13 of 16

cadffm
Consultant
Consultant

PGP, 

ahh (Longname) is a good reason for .pgp

thx for explaination.

 

A pgp file is a plain ascii txt file,

doesn't matter the file extension,

so: Yes, it works by Lisp.

 

Search for function to read/write ascii files,

Samples for .txt are similiar.

 

Perhaps you find a ready WELL programmed "Edit pgp" Tool.

 

If not, write your own.

 

 

 

 

 

 

CUIX,

Shojld contain your stuff ONLY

This way you can add/remove your part easily, also to new installations, new releases, different Toolsets and Versions.

 

 

Sebastian

0 Likes
Message 14 of 16

Sea-Haven
Mentor
Mentor

Just me I stay away from all default ways of adding stuff like acaddoc.lsp acad.pgp etc. I grew up when Acad was 1st started so only menu's.

 

The answer for your images is easy, 1st step to make you just use the command "Mslide" with your object/s on the screen and give it a name. I have made like 100 images of blocks by just making  a list of block names and making a slide of each one obviously using a lisp. 

 

Explaining a menu more it has sections POP IMAGE TOOLBAR DIGITISER. A single line in the pop section calls a image section which may have a few or even like 50 images, the preview is automatically generated you do not have to worry about that.

 

Using the "> & <" opens and closes sub menus, yes can have sub sub and so on.

 

***MENUGROUP=XXXSTDS

***POP20
**CADLIB
             [LIBRARY]
             [->Stddwgs]
             [TRENCH]$I=XXXSTDS.TRENCH $I=*
             [PIPES]$I=XXXSTDS.PIPES $I=*
             [PITS]$I=XXXSTDS.PITS $I=*
             [KERBS]$I=XXXSTDS.KERBS $I=*
             [ROADX]$I=XXXSTDS.ROADX $I=*
             [PAVEMENTS]$I=XXXSTDS.PAVEMENT $I=*
             [MISC]$I=XXXSTDS.MISC $I=*
[<-]
             [->IDM dwgs]
             [TRENCH]$I=XXXSTDS.IDMTRENCH $I=*
             [PIPES]$I=XXXSTDS.IDMPIPES $I=*
             [PITS]$I=XXXSTDS.IDMPITS $I=*
             [KERBS]$I=XXXSTDS.IDMKERBS $I=*
             [ROADX]$I=XXXSTDS.IDMROADX $I=*
             [PAVEMENTS]$I=XXXSTDS.IDMPAVEMENT $I=*
[<-]
[->SURVEY dwgs]
             [SHEETS]$I=XXXSTDS.SURVEY $I=*
[<-]
             [->LISP1 A-B]
             [1/4 POINTS]^C^C(LOAD "1-4 POINTS")
             [Add 2 Level]^C^C(LOAD "add-to-levels")
             [Add-pits-drain]^C^C(LOAD"Add-pits-drain")
             [Allbylayer]^C^C(LOAD "Allbylayer")
             [Apndtext]^C^C^p(LOAD "apndtext")

 

So you can see the $I this is call an image menu.

 

 

***image
**PIPES
[PIPES]
[XXXSLD(SD201,SUBSOIL)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG201") 
[XXXSLD(SD202,FLUSHOUT)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG202") 
[XXXSLD(SD203,CATCH)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG203") 
[XXXSLD(SD204,HOUSE)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG204") 

 

You just start with a text file saved as a mnu file and use menuload to load it, then a CUIX will be made.

 

The pop menu above is 697 lines long developed over many years from my staff requests.

 

I would start to use a pop menu rather than a List box choice, if you go that way I would use a list to display in the list box that has an exaggerated description but matches true lisp name. You can change the width of a ListBox so have a bigger description.

 

(("program1" "actuallispfilename1")("program2" "actuallispfilename2")("program3" "actuallispfilename3").....)

 

 

0 Likes
Message 15 of 16

sigmmadesigner
Advocate
Advocate

LOOK AT ME IN THE SOLUTION YOU DEVELOPED, AND IT IS VERY CLOSE TO WHERE I WOULD LIKE TO GET. COULD YOU SHARE THIS SOLUTION?

HERE IS AN IMAGE OF MY GOAL

 

sigmmadesigner_0-1741235790183.png

 

0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

Your images are a custom dcl, the default image in a pop menu is 4x5 when 20+ auto add NEXT.

 

I did not mention it before but the slide images can be stored in a SLB file so you have one file but with 100's of images, so the only difference when you look at the code posted above , 

[XXXSLD(SD201,SUBSOIL)]

xxxsld is a slb file, SD201 is description, the SUBSOIL is image name. So menu line would be hopefully, have not made one for a while.

[SD201,SUBSOIL]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG201") 
or something like
[SD201,SUBSOIL]^C^C^c^c-INSERT "C:/ACADSTDS/CIVIL STANDARDS/CGG201" DRAG \1;;DRAG

Ok need a sample dwg with say some tree blocks and should be able to make you a pop menu. 

0 Likes