Jump to content

LISP to Install Support Path and Custom Menu


Bill Tillman

Recommended Posts

I found this LISP code on AfraLISP website. It looks like it could help solve some problems I'm having around here to automate the user setups. I tried it out and it does seem to work but with my adjustments shown below, here is what I end up with:

 

The support path is updated with the two new paths and they are in the correct positions. The first path is entered like all the rest of the paths in the current Support Path settings with all letters in upper case and the forward slashes I used in the LISP code are converted to back slashes. The second entry ends up in all lower case and none of the slashes converted.

 

I'm still working on getting the My_Menu.cui(x) loaded, but I thought I'd get the first part figured before proceeding.

 

 

 

;inform the user how to run the application
(prompt "\nMy_Menu Menu Installer Loaded...Type My_Menu to run......")

;define the function
(defun C:My_Menu ( / flag1 loaded temp)

 (setq _ACADVERSION (atof (getvar "ACADVER")))
 (if (>= ACADVER 19.0) ; AUTOCAD 2013 or 2014
   (setq _MENUNAME "My_Menu.cuix")
   (setq _MENUNAME "My_Menu.cui")
   ); end if
 
;add the new support paths
 	(addSupportPath "//a_very_long/novell/path/VLISP" 5)
 	(addSupportPath "//a_very_long/novell/path/VLISP/3rdPartyLisp" 6)  	

;set the flag
(setq flag1 T)

;check if the menu is not already loaded
(setq loaded (menugroup "_MENUNAME"))

;if it is not loaded
(if (= loaded nil)

  ;do the following
  (progn

;find the menu file
       (setq temp (findfile _MENUNAME))

   ;if you find the menu
          (if temp

	;do the following
  		(progn

		;switch off dialogues
		(setvar "FILEDIA" 0)

		;load the menu
	    	(command "menuload" _MENUNAME)

		;switch on dialogues
		(setvar "FILEDIA" 1)

		; This is for later use
                       ;install the pulldown
	    	;(menucmd "P11=+VBAMENU.POP1")

		;inform the user
      			(prompt "\nLoading My_Menu....\n")

	);progn

	;menu not find, so do the following
	(progn

		;inform the user
                       (alert "Cannot Locate My_Menu Menu.
		 \nCall System Administrator.")

		;clear the flag	
		(setq flag1 nil)

	);progn

   );if

   );progn

);if

	;if the flag is set
	(if flag1

		;inform the user
      			(prompt "\nVBA Menu Loaded....\n")

	);if

   (princ)

);defun

;subroutine to add support path
(defun addSupportPath (dir pos / tmp c lst)

(setq tmp ""
      c -1
)
(if
	(not
	  (member (strcase dir)
		(setq lst 
		  (mapcar 'strcase 
			(parse (getenv "ACAD") ";")
		  )
		);setq
	  );member
	);not	
(progn
	(if (not pos)
		(setq tmp (strcat (getenv "ACAD") ";" dir))
		(mapcar '(lambda (x)
		(setq tmp (if (= (setq c (1+ c)) pos)
				(strcat tmp ";" dir ";" x)
				(strcat tmp ";" x)
			  )
		)
		)
	lst
	)
)
(setenv "ACAD" tmp)
)
)
(princ)
)

;parsing routine
(defun parse (str delim / lst pos)
(setq pos (vl-string-search delim str))
(while pos
	(setq lst (cons (substr str 1 pos) lst)
		str (substr str (+ pos 2))
		pos (vl-string-search delim str)
	)
)
(if (> (strlen str) 0)
	(setq lst (cons str lst))
)
	(reverse lst)
)

(princ);clean load

Link to comment
Share on other sites

Okay, I'm not sure why the code above is failing...will check it out more later on. In the meantime I found this previous post by Lee-Mac. It looks like that could be an easier target to study for this task.

 

And as usual, Lee-Mac's code is spot on and it worked perfectly. The code from AfraLISP has a module for adding new menu items too and I'm wanting to understand that part. As the IT dept around here rolls out new updated computers this kind of code will make getting them all in synch a snap.

Link to comment
Share on other sites

Okay, once again, many thanks to the one and only Lee-Mac. It looks like I can make this code work. Here is what I need help with. I run the code and install two new entries in the support file path, that goes well. Then I add a menu that's in one of those paths like this:

(command "._MENULOAD" "I:/My_Path/My_Menu.cuix")

This loads the menu and it will appear in the the Load/Unload Customizations dialog window, but the menu item does not appear at the top of the AutoCAD screen like it would had I done this manually. So what do I need to add to the above command to get it to appear at the top?

Link to comment
Share on other sites

A alternative to the set paths you can do printers autosave plot spooling etc also post if you want the rest.

 

; just 1 part of all the Config files stuff
;make new support paths exist + new
; By BIGAL 2014
(setq *files*  (vla-get-files  (vla-get-preferences (vlax-get-Acad-object))))
(setq paths (vla-get-SupportPath *files*))
;make new support paths exist + new
(setq cpaths 
 "P:\\autodesk\\supportfiles;
 P:\\autodesk\\lisp;
 P:\\autodesk\\fonts;
 P:\\autodesk\\hfs fonts;"
 )
(setq newpath (strcat cpaths paths))
(vla-put-SupportPath *files* newpath)
; end use of *files*
(vlax-release-object *files*)

Link to comment
Share on other sites

Okay, I've got the support path figured out. And I can make the code which MENULOAD's a new partial menu. The trick seems to be how to get the new partial menu to show up at the top line of the AutoCAD screen. Anyone .... anyone ..... anyone. Bueller ..... Bueller .... Bueller!

Link to comment
Share on other sites

Are you doing a "command" "menuload" ? maybe use the VL method. There is a lot of info in the Visual Lisp Developers Bible about how to manipulate & load menus. This mentions about making a loaded menu part of the group which sounds like your problem.

 

Manually a menuload then menu appears always works for me, haven't tried a lisp. please post this bit of code.

Link to comment
Share on other sites

I use this code to load menus

(defun C:smc-melb ( / flag1 loaded temp)

;set the flag
(setq flag1 T)
;check if the menu is not already loaded
(setq loaded (menugroup "SMC-Melbourne"))
;if it is not loaded
(if (= loaded nil)
  ;do the following
  (progn

;find the menu file
       (setq temp (findfile "SMC-Melbourne.MNU"))
   ;if you find the menu
          (if temp
 ;do the following
    (progn
  ;switch off dialogues
  (setvar "FILEDIA" 0)
  ;load the menu
      (command "menuload" "SMC-Melbourne")
  ;switch on dialogues
  (setvar "FILEDIA" 1)
  ;install the pulldown
      (menucmd "P15=+SMC-Melbourne.POP25")
  ;inform the user
         (prompt "\nLoading SMC Melbourne Menu....\n")
 );progn
 ;menu not find, so do the following
 (progn
  ;inform the user
                       (alert "SMC Melbourne Not Installed.....")
  ;clear the flag 
  (setq flag1 nil)
 );progn
   );if
   );progn
);if
 ;if the flag is set
 (if flag1
  ;inform the user
         (prompt "\nSMC Melbourne Loaded....\n")
 );if
   (princ)
);defun

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...