Assigning Lisp Routine to a Button

Assigning Lisp Routine to a Button

Anonymous
Not applicable
6,617 Views
5 Replies
Message 1 of 6

Assigning Lisp Routine to a Button

Anonymous
Not applicable

Hi guys

 

I'd like to assign this Lisp routine to a button on the toolbar. I already created the button, but I don't know how to write the macro so that I can load and run this Lisp file.

 

File path: "Y:\ACAD_GLOBAL\2018\Init\init.lsp"

 

My Lisp Routine:

 

;Load Visual Lisp

(vl-load-com)

;Import the "MYPROFILE" Profile from the Y:\ Drive

(vl-catch-all-apply 'vla-importprofile (list
	(vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
	"MYPROFILE"
	"Y:\\ACAD_GLOBAL\\2018\\Profile\\MYPROFILE.arg"
	1)
	)
	

;Set "MYPROFILE" current

(vla-put-ActiveProfile (vla-get-Profiles (vla-get-Preferences (vlax-get-acad-object)))"MYPROFILE")

;Set the "modemacro" sysvar to report the latest profile

(SETVAR "modemacro"(STRCAT "PROFILE: $(getvar, cprofile)"))

 

I've been using acad.lsp to load this Lisp file on startup, which was the wrong approach because it delays the starting process and resets my cuix.

 

P.S.: It has to be a file. The file is located on a shared network and is being accessed to by multiple users but managed by one individual. "MyProfile" is regularly being updated, that's why we need all users to work with the same profile.

 

Thank you for any help.

 

Cheers,

 

Rimi

0 Likes
Accepted solutions (2)
6,618 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

I think [without trying it out] that you should be able to just put this in the macro:

(load "Y:/ACAD_GLOBAL/2018/Init/init")

 

[You can include the .lsp filetype ending if you want, but it's not necessary.]

 

Or, put that filepath into everyone's Support File Search Path list in Options / Files, and just do this in the macro:

 

(load "init")

 

Or, define what's in that as a command name:

 

(defun C:INIT ()

  your

  file

  contents

)

 

anad have acaddoc.lsp load that, and put the command in the macro:

 

(C:INIT)

Kent Cooper, AIA
Message 3 of 6

dbroad
Mentor
Mentor
Accepted solution

First, I believe that forcing everyone to share a profile is wrong on many levels and also counter-productive to some extent.  The company's standards should be on an enterprise CUI that everyone shares and is centrally managed but that shouldn't lock down all individuality and ingenuity.

 

Next, if you want such things on a toolbar, you should restructure the file by wrapping its contents so that it doesn't get executed on-load.

 

(defun foo ( /  ... whatever local vars you want)

 

;;contents of your file

 

 

)

 

where foo is a unique name in your system.  This keeps the code from auto-executing on load.

 

Put your file in the startup suite or rename the lsp file as an mnl file associated with your cui so that it autoloads.  Then edit your enterprise cui and add the command you want and add your lisp function ^c^c(foo) to the macro part of that command. Choose or create an appropriate icon.  Then add the command to the toolbar.  Save your CUI.  The code, previously autoloaded but not executed is then run when the toolbar is pushed. If you don't want to autoload, then the macro would look like  ^c^c(if (null foo)(load "your path name"))(foo). 

Architect, Registered NC, VA, SC, & GA.
Message 4 of 6

Anonymous
Not applicable

@Kent1Cooper wrote:

I think [without trying it out] that you should be able to just put this in the macro:

(load "Y:/ACAD_GLOBAL/2018/Init/init")

 

[You can include the .lsp filetype ending if you want, but it's not necessary.]

 

Or, put that filepath into everyone's Support File Search Path list in Options / Files, and just do this in the macro:

 

(load "init")

 

Or, define what's in that as a command name:

 

(defun C:INIT ()

  your

  file

  contents

)

 

anad have acaddoc.lsp load that, and put the command in the macro:

 

(C:INIT)


Thanks a lot, I'll try these out as soon as I can.

 


@Anonymous wrote:

First, I believe that forcing everyone to share a profile is wrong on many levels and also counter-productive to some extent.  The company's standards should be on an enterprise CUI that everyone shares and is centrally managed but that shouldn't lock down all individuality and ingenuity.

 

Next, if you want such things on a toolbar, you should restructure the file by wrapping its contents so that it doesn't get executed on-load.

 

(defun foo ( /  ... whatever local vars you want)

 

;;contents of your file

 

 

)

 

where foo is a unique name in your system.  This keeps the code from auto-executing on load.

 

Put your file in the startup suite or rename the lsp file as an mnl file associated with your cui so that it autoloads.  Then edit your enterprise cui and add the command you want and add your lisp function ^c^c(foo) to the macro part of that command. Choose or create an appropriate icon.  Then add the command to the toolbar.  Save your CUI.  The code, previously autoloaded but not executed is then run when the toolbar is pushed. If you don't want to autoload, then the macro would look like  ^c^c(if (null foo)(load "your path name"))(foo). 


Thanks a lot, I'll try this out as soon as I can.

 

The reason for using one standard profile is the tool palette that we are using. It is located on a shared drive and regularly updated with new blocks and structures. Unfortunately, the groups of the palettes are saved on the profile.

 

But we are allowing personal user profiles aswell. 🙂 My goal is to customize the UI so that users can switch from the Standard profile to their personal profile with one single button.

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thank you a lot, Sir.

This works perfectly.

 

I added the path of the lsp file to the support file search paths.

 

Y:\ACAD_GLOBAL\2018\Init

 

Then I defined the function

 

(defun C:Test ()

...

...

...

)

 

And added this macro on the button.

 

(if (not c:Test)(load "Test"));Test;

 

It works. 🙂

0 Likes
Message 6 of 6

ahsattarian3
Enthusiast
Enthusiast

Hello

 

Better u use cui to assign lisp function to your toolbar button.

 

Regards

Amir

0 Likes