OSMODE Settings Program & Preserving the "Preferred" OSMODE Setting
The program is intended to allow the user to either choose ALL ON (16383), ALL OFF (16384), or either initially open the SETTINGS>OSMODE and choose the PREFERRED OSMODE options. When the program is invoked again and PREFERRED OSMODE option is chosen (as "P"), the program will ask the user if he wants to change the current PREFERRED OSMODE settings with a Yes/No option.
ISSUE
The PREFERRED OPTION only opens the SETTINGS>OSMODE dialog box after the initial settings have been made. The Yes/No options are not displayed after the initial PREFERRED OPTION is set.
QUESTION
How do I preserve the PREFERRED OPTION and not open the SETTINGS>OSMODE when the user selects No?
Thanks,
Clint
Comments
-
To create a default OSMODE (Entity Snap Mode) value, simply add the value to your on_doc_load.lsp.
i.e.:
(setvar "OSMODE" 4607)
(princ)0 -
Like this in an autoload lisp. You dont have to match the numbers we just did.
(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:9 ()(setvar "osmode" 9))
(defun C:0 ()(setvar "osmode" 0))0 -
Can someone review and suggest revisions to the following code?
The issue is that the Preferred OSMODE setting and the option to change it or not (Yes/No) is not being displayed nor is the Preferred OSMODE setting once set is being preserved.
CODE START
; Filename: SetOSNAPMode
; Release: V1
; Date: August 07, 2025
; By: Clint Hill
;---------------------------------------------------------------------------------------------; Comments:
; Created as tool for production usage with LISP as a coding learning exercise via Microsoft Copilot
;
;---------------------------------------------------------------------------------------------
;
(defun c:SetOSNPAMode (/ mode current preferred response)
(prompt "\nChoose OSNAP mode: [P]referred / [A]ll On / [O]ff: ")
(setq mode (strcase (getstring)))(cond
;; Preferred mode
((= mode "P")
(command "SETTINGS")
(prompt "\nAdjust OSNAP settings in the dialog, then press Enter to continue...")
(getstring "\nPress Enter when done...");; Ask user if they want to update the saved preferred setting
(prompt "\nDo you want to update the saved Preferred OSNAP setting? [Yes/No]: ")
(setq response (strcase (getstring)))
(cond
((= response "YES")
(setq current (getvar "OSMODE"))
(setenv "PreferredOSMODE" (itoa current))
(prompt (strcat "\nPreferred OSNAP setting updated to: " (itoa current)))
)
((= response "NO")
(prompt "\nPreferred OSNAP setting preserved.")
)
(T
(prompt "\nInvalid response. Preferred OSNAP setting preserved.")
)
)
)
;; All On
((= mode "A")
(setvar "OSMODE" 16383)
(prompt "\nOSNAP set to All On.")
)
;; All Off
((= mode "O")
(setvar "OSMODE" 0)
(prompt "\nOSNAP turned Off.")
)
;; Invalid input
(T
(prompt "\nInvalid option. Please enter P, A, or O.")
))
(princ)
)(defun c:RestorePreferredOSNAP ()
(setq preferred (getenv "PreferredOSMODE"))
(if preferred
(progn
(setvar "OSMODE" (atoi preferred))
(prompt (strcat "\nRestored Preferred OSNAP setting: " preferred))
)
(prompt "\nNo Preferred OSNAP setting saved.")
)
(princ)
)CODE END
0 -
The code created via CoPilot doesn't really make sense. It's easier to re-write than try to decipher.
I don't recommend switching all object snaps on, as they will interfere with your ability to make the object snap that you want. It's generally better to just have a few ones on that are complementarity to each other. The user can always override these whilst in a command to select a different snap object option.
The following will allow you to set the 3 OSMODE options you wanted, as well as save the current.
(defun C:SetOSNAPMode ( / pref ans)
(if (not (setq pref (getenv "PreferredOSMODE"))) (setq pref (setenv "PreferredOSMODE" "4135"))) ; Initialise Preferred osmode, set to BricsCAD defaults if not already defined
(initget "All Off Preferred Save")
(setq ans (getkword (strcat "\nChoose a OSNAP mode option [All/Off/Preferred/Save current] <Preferred>: ")))
(cond
((= ans "All") (setvar 'OSMODE 16383 )(princ "\nOSNAP set to All On"))
((= ans "Off") (setvar 'OSMODE 0 )(princ "\nOSNAP set to All Off"))
((= ans "Save") (setenv "PreferredOSMODE" (itoa (getvar 'OSMODE )))(princ "\nOSNAP preferred settings saved"))
((or (null ans)(= ans "Preferred")) (setvar 'OSMODE (atoi pref)) (princ "\nOSNAP set to Preferred settings"))
)
(prin1)
)I recommend that you investigate the INITGET and GETKWORD functions.
Lee Mac provides some nice examples of prompting with a default option
Jason Bourhill
CAD Concepts Ltd
0 -
I stopped using Initget rather use a dcl, then you only have the choices that you can pick. You can set preset values and so on. The getvals will display your preset value only, "BUT" is it must be a string in a dcl so a number 10= "10" but when answer is returned use (atof (nth 2 ans)) etc. There is example code in the top of the three programs. Make sure they are saved in a support path as they are autoloaded.
0 -
I thank you Jason and Alan for your interest and immediately useful and practical learning examples as well as the options in adding a dialog box to the customization.
I will provide updates and questions here as my focus returns to LISP-based customization.
Yours,
Clint
0