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

Lisp function called when a given command is used

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
LispEnjoyer
689 Views, 7 Replies

Lisp function called when a given command is used

Good morning/afternoon everyone, 

 

I'm opening this thread today as I'm in quite a bind, here at work we have a monolith of an autolisp program that extends autocad in order to give us specific functionalities, one of them is a function that triggers every time a document is saved, its behavior is to update a special block that hold the last save time and date. 

 

In parallel to this, I have been tasked to develop a program that will insert the last save time and date as a barcode when a save is triggered. Normally it would be easy, simply modify the custom save command to insert a barcode, however I'm not allowed to modify the other program. Everything else is pretty much done, I only need to get over this hurdle before I deploy the thing. 

 

I am aware of 

(vlr-dwg-reactor nil) with :vlr-beginsave

However, it makes the LISP engine crash. I supposed this is because the original custom save command is triggered at the same time, causing unexpected results? 

Is there a way to react to the custom command specifically? 

Or would creating a new custom command that will insert the barcode and then trigger the original one be possible?

 

Where do that crash comes from? 

I use Xrecord to keep the barcode positions and Object Handle for updates, and to detect its presence. When the main function is triggered and no barcode is found, the program waits for the user to select an insert point... Could it be what cause the crash when used with a reactor function? 

That's a lot of questions but it's been puzzling me for a bit. 

Sorry for the approximative english, it is not my first language.  

 

Tags (4)
7 REPLIES 7
Message 2 of 8
MrJSmith
in reply to: LispEnjoyer

For save reactors, I use the following:

(vlr-editor-reactor "SaveReactor" '((:vlr-saveComplete  . DoThisAfterSaves)))

I then filter out what type of save is being done in the "DoThisAfterSaves" function and perform whatever commands I want depending on the type of save.

 

I attempted to see if the after command reactor would catch the commands that are being ran during the save reactor and it does not. However, you could also try using the do-after-command reactor and catch if the command is "QSAVE" and use that to run the barcode insertion.

 

(vlr-command-reactor "DoThisAfterCommandEnded" '((:vlr-commandEnded . DoThisAfterCommandEnded)))

 

Message 3 of 8
Sea-Haven
in reply to: LispEnjoyer

You may also want to trap CLOSE as it will save a dwg as well.

 

Something like this.

 

;Reactor callback function
(defun BeginCloseFunc (reactor lst / blocks blk)
your make barcode bit and update date
)

(cond
((= (vlr-current-reaction-name) ':VLR-beginSave) (Princ "\nThis function has been triggered by a Document Save event."))
((= (vlr-current-reaction-name) ':VLR-beginClose)(princ "\nThis function has been triggered by a Document Close event."))
)
(princ)
)
(if (not _BeginCloseReactor) (setq _BeginCloseReactor (VLR-Dwg-Reactor nil '((:VLR-beginClose . BeginCloseFunc)))))
(if (not _BeginSaveReactor ) (setq _BeginSaveReactor  (VLR-Dwg-Reactor nil '((:VLR-beginSave  . BeginCloseFunc)))))

 

 

Message 4 of 8
LispEnjoyer
in reply to: LispEnjoyer

Thank you very much for your answers, I will do some testing today and report back when I can. 

Message 5 of 8
LispEnjoyer
in reply to: LispEnjoyer

I pinpointed the issue, it's when the user is asked to select an Insertion Point within the reactor function that the Lisp interpreter crashes. 

Otherwise it works, I have to either compromise and ask the user to select a point ahead of time or find another way...

 

According to Autocad's documentation:

Do not use any interactive functions in your reactor callback function (for example, do not use getpoint, entsel).

Attempting to execute interactive functions from within a reactor callback function can cause serious problems, as AutoCAD may still be processing a command at the time the event is triggered. Therefore, avoid the use of input-acquisition methods such as getpoint, entsel, and getkword, as well as selection set operations and the command function."

AutoCAD LT 2025 | About Reactor Guidelines (AutoLISP/ActiveX) | Autodesk

 

Message 6 of 8
Sea-Haven
in reply to: LispEnjoyer

Why do you need a insertion point if your amending a title block you should know the point or know say its attribute name. Even if the title block is not at 0,0 or has been scaled you should still be able to workout the correct point. Your original post was to update a date stamp and add a Barcode. Are they not fixed within the title block ?

Message 7 of 8
LispEnjoyer
in reply to: Sea-Haven

That particular block is merely a visual indicator, the date and hour are spelled and it's part of a wider lisp program I'm not authorized to meddle with. 

The Barcode is for a different purpose altogether and is handled by the program I'm developing, they are to be inserted in varying "types" of drawings and the barcode length is subject to change depending on the filename, thus as to not cover any existing information on the document we need to prompt the user for a suitable insert point. We're adding a new element to the drawing, not updating a preexisting block, once the barcode is added once then the update can be automatized. 

Message 8 of 8
Sea-Haven
in reply to: LispEnjoyer

You can DEFINE your own command like Close and Save as a DEFUN you may have to use that method. The say last line would do the actual saving using the force true save command of the top of my head its _.SAVE & _.CLOSE.

 

I think its my Bricscad not letting me define a new command. Try this

(defun c:CIRCLE ( / )
(alert "circle")
)

 Its been a while since define a command. 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report