If you load this in your acaddoc.lsp file it will KILL the nearest osmode automatically at the beginning of each command.
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard copyright 2023 All Rights Reserved
;___________________________________________________________________________________________________________|
; Abstract: This routine will (when loaded) will autmatically remove the nearest osnap at the beiginning of
; every command (started from command line)
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
;
; Function List Argument1 Argument2 Arguement3
;* (ActiveDocumentGetObject)
;* Function to get the active document vla-object
;* (BitCodesListAll intExponent)
;* Function to get a list of bits (2^x)
;* (ErrorTrap symFunction)
;* Function to Trap Errors without crashing lisp routine
;* (OSModeListItemRemove intBitCode)
;* Function to remove an osnap bit code from osmode system variable
;* (OSModeReactorNoNearest (Call CallBack)
;* Function to remove an nearest osnap bit code from osmode system variable
;* (OSModeToList intOSMode)
;* Function to convert a bitvalue to a list of bit codes
;$ End Header
;___________________________________________________________________________________________________________|
;
; Initialize CommandWillStart Reactor
;___________________________________________________________________________________________________________|
(or rxnCommandWillStart
(setq rxnCommandWillStart (vlr-editor-reactor nil '((:vlr-commandwillstart . OSModeReactorNoNearest))))
)
;___________________________________________________________________________________________________________|
;
; Function to get the active document vla-object
;___________________________________________________________________________________________________________|
(defun ActiveDocumentGetObject ()
(if (or objACADApplication
(setq objACADApplication (vlax-get-acad-object))
)
(vlax-get objACADApplication "ActiveDocument")
)
)
;___________________________________________________________________________________________________________|
;
; Function to get a list of bits (2^x)
;___________________________________________________________________________________________________________|
(defun BitCodesListAll (intExponent / lstBitCodesAll)
(repeat (1+ intExponent)
(setq intExponent (1- intExponent))
(setq lstBitCodesAll (cons (expt 2 intExponent) lstBitCodesAll))
)
lstBitCodesAll
)
;___________________________________________________________________________________________________________|
;
; Function to Trap Errors without crashing lisp routine
;___________________________________________________________________________________________________________|
(defun ErrorTrap (symFunction / objError result)
(if (vl-catch-all-error-p
(setq objError (vl-catch-all-apply
'(lambda (X)(set X (eval symFunction)))
(list 'result))))
nil
(if result result 'T)
)
)
;___________________________________________________________________________________________________________|
;
; Function to remove an osnap bit code from osmode system variable
;___________________________________________________________________________________________________________|
(defun OSModeListItemRemove (intBitCode / intOSMode lstOSMode objActiveDocument)
(if (and (setq objActiveDocument (ActiveDocumentGetObject))
(setq intOSMode (vlax-invoke objActiveDocument "getvariable" "osmode"))
(setq lstOSMode (OSModeToList intOSMode))
(setq lstOSMode (vl-remove intBitCode lstOSMode))
(setq intOSMode (apply '+ lstOSMode))
)
(errortrap '(vlax-invoke objActiveDocument "setvariable" "osmode" intOSMode))
)
)
;___________________________________________________________________________________________________________|
;
; Function to remove an nearest osnap bit code from osmode system variable
;___________________________________________________________________________________________________________|
(defun OSModeReactorNoNearest (Call CallBack)
(if (not (wcmatch (strcase (car Callback)) "U,UNDO*"))
(OSModeListItemRemove 512)
)
)
;___________________________________________________________________________________________________________|
;
; Function to convert a bitvalue to a list of bit codes
;___________________________________________________________________________________________________________|
(defun OSModeToList (intOSMode / intBitCode lstOSMode)
(if (and (setq lstBitCodes (BitCodesListAll 15))
(/= intOSMode 0)
)
(foreach intBitCode (reverse lstBitCodes)
(if (>= intOSMode intBitCode)
(progn
(setq intOSMode (- intOSMode intBitCode))
(if (/= intBitCode 0)
(setq lstOSMode (cons intBitCode lstOSMode))
)
)
)
)
)
lstOSMode
)
(princ "!")
(vl-load-com)
; Osnap Bit Codes
;0 NONe
;1 ENDpoint
;2 MIDpoint
;4 CENter
;8 NODe
;16 QUAdrant
;32 INTersection
;64 INSertion
;128 PERpendicular
;256 TANgent
;512 NEArest
;1024 Geometric CEnter
;2048 APParent Intersection
;4096 EXTension
;8192 PARallel
;16384 Suppresses the current running object snaps