How to Modify VLX routine with Osnap ON-OFF command in Macro command

How to Modify VLX routine with Osnap ON-OFF command in Macro command

franc_as
Enthusiast Enthusiast
391 Views
4 Replies
Message 1 of 5

How to Modify VLX routine with Osnap ON-OFF command in Macro command

franc_as
Enthusiast
Enthusiast

Hi
I have a couple of vlx routines which turns off and cleared Osnap settings during procedure.
I wish to preserve Osnap settings, because I don't want so set it again every time.
I cannot open vlx file, so I am wondering how to customize Macro command of icon shortcut.
Is it possible to add F3 command before and at the end of vlx command?....or at least, maybe my favourite OSMODE number settings at the end?
And one importing things... during vlx procedure I must pick two or more objects...for example, vlx routine for multiple offset.
Any suggestions?
Kind regards

0 Likes
Accepted solutions (1)
392 Views
4 Replies
Replies (4)
Message 2 of 5

Moshe-A
Mentor
Mentor
Accepted solution

@franc_as hi,

 

Here is a nice lisp i made (10 years ago) to trap invocation of any lisp command, save current object snap and restore it on lisp command end (or cancel).

 

wrap\save this to saveOSnap.lsp file and load it first from appload (or acad.lsp, acaddoc.lsp)

 

And one importing things... during vlx procedure I must pick two or more objects...for example, vlx routine for multiple offset.
Any suggestions?

 

what is wrong with that?

 

 

enjoy

Moshe

 

 

 

; saveOsnap.lsp
; by Moshe-A, 11-13-2014

; program to save osnap before lisp command is start
; and restore osnap when lisp command is ended or cancelled

(defun OnLispStart (R args^ / doc)
; (princ "\nOnLispStart")
  
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (setq *saveOsnap* (vla-getVariable doc "osmode"))
 (vlax-release-object doc)
)


(defun OnLispEnded (R args^ / doc)
; (princ "\nOnLispEnded")

 (if *saveOsnap*
  (progn
   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  
   (if (/= (vla-getVariable doc "osmode") *saveOsnap*)
    (vla-setVariable doc "osmode" *saveOsnap*)
   )
  
   (vlax-release-object doc)
  )
 )
)


(defun install_lisp_reactor ()
 (setq *lispReactor* (vlr-lisp-reactor "" (list '(:vlr-lispWillStart   . OnLispStart)
			                        '(:vlr-lispEnded       . OnLispEnded)
			                        '(:vlr-lispCancelled   . OnLispEnded)
				          )
		     )
 )

 (princ) 
)



  
(defun c:DisableSaveOsnap ()
 (if (and *lispReactor* (vlr-added-p *lispReactor*))
  (progn
   (vlr-remove *lispReactor*)
   (setq *lispReactor* nil)
   (setq *saveOsnap* nil)
  )
 )

 (princ)
)

  
(defun c:EnableSaveOsnap ()
 (install_lisp_reactor)
)


(install_lisp_reactor)

 

 

 

 

 

 

 

 

Message 3 of 5

-didier-
Advisor
Advisor

Bonjour @franc_as 

 

It is easy to memorize your favorite osnap.

First, make settings in the dialog box

Second, Type OS (or OSMPDE) on the keyboard, and note the value.

For example, 32 for "end" AND "intersection".

Third, put it in a macro button.

 

Amicalement

 

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 4 of 5

franc_as
Enthusiast
Enthusiast
Great..it works perfectly.
Thank You!
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Like @-didier-, various users had preferences, you can make them what ever name, we just chose numbers.

 

(defun C:15 ()(setvar "osmode" 15359))   ; sets all snaps on
(defun C:47 ()(setvar "osmode" 47)(setvar "AUNITS" 0))
(defun C:99 ()(setvar "osmode" 99))
(defun C:8 ()(setvar "osmode" 8))
(defun C:59 ()(setvar "osmode" 15359))
(defun C:9 ()(setvar "osmode" 9))
(defun C:0 ()(setvar "osmode" 0))

 

in my code 

(setq oldsnap (getvar 'osmode)) ; get current value osnaps
(setvar 'osmode 0) ; set to off
........ lots of code
(setvar 'osmode 1) ; needed in codde
......... lost of code
(setvar 'osmode oldsnap) ; at end of code

 If you have an error trap then include (setvar 'osmode oldsnap) 

0 Likes