Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add a command into a lisp?

2 REPLIES 2
Reply
Message 1 of 3
grantw.gw
422 Views, 2 Replies

How to add a command into a lisp?

Hello, I am trying to add a command to a lisp routine that mirrors our floorplan tags. The Mirroring command (MTG) turns off all of our osnaps somewhere in the process and a couple of us whipped up a command that when you type AQ the osnaps are re-checked and you dont have to hit F11 and check all the boxes again. The command looks like this

 

(defun c:aq ()
(command "-osnap" "end,mid,cen,nod,qua,int,per,app")
)

 

My question is how do I add this command line to the MTG lisp so that right before the MTG lisp routine closes this runs and turns all the osnaps back on. 

 

PS: I am working in ADT2006

 

Thank you,

2 REPLIES 2
Message 2 of 3
mpalan2009
in reply to: grantw.gw

You might do something like this.  This is essentially a command wrapper.

 

 

(defun c:mtgx ()

;get the value of the running object snaps

 (setq osvar (getvar "osmode"))

 

;;; I'm not sure how many pauses you will need to run the commnand

  (command "mtg" pause)

 

;put the running object snaps back

(setvar "osmode" osvar)

(princ))

 

hope this helps.

Matthew

Message 3 of 3
Kent1Cooper
in reply to: grantw.gw

This kind of thing is more easily done using the OSMODE System Variable, rather than a string of mode names in a (command) function.  The combination of modes you show in your (command) can be set without using (command), this way:

(setvar 'osmode 2239)

 

[Type in OSMODE when you have that combination set, and it will show you the 2239 value.]

 

As for getting your Mirroring command to reset them, this is standard save-and-reset-a-variable and error handling procedure.  If you Search for

(defun *error*

in this Forum, you will find countless examples.  It will involve setting a variable that saves the current value of OSMODE when the routine starts, such as:

 

(setq osm (getvar 'osmode))

 

[you can call the variable name whatever you like -- some use something longer such as oldosmode].  At the end of the routine, it will include a reset:

 

(setvar 'osmode osm)

 

Include that reset in an error handler, and it will do it even if the routine doesn't get around to it, such as if the User cancels the routine midway with Escape, or some kind of error occurs.  Some people do the resetting in the main routine by actually calling for the error handler to run with no error message, rather than resetting Osmode overtly [to me it feels somehow "wrong" to force it to behave as if there's been an error when there hasn't been one, but it does work].

 

One advantage of saving the value of OSMODE and resetting it to what it was, rather than always setting to a specific value such as 2239, is that any User can operate with their own preferred combination of modes, and won't find them set to someone else's preferred combination just because they ran a particular routine.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost