Author Topic: Print results of lisp routine on command line...  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

hammonj7

  • Guest
Print results of lisp routine on command line...
« on: August 11, 2010, 10:49:46 AM »
I am using a lisp routine to toggle some system variables that I change fairly often.  My lisp works just fine...for me.  However, my general users are interested in seeing an acknowledgment of the switch printed to the command line after the command has been executed.  Here is the code I am using:

(defun c:rnm ()
  (if (= (getvar "osmode") 1791)
  (setvar "osmode" 1088) ;Sets object snap mode to insertion point only
  (setvar "osmode" 1791) ;Sets object snap mode to "normal" osmode
    )
  (princ)
    )

Basically, I would like to use (princ "\nOsmode Insertion point set.") or whatever when my little routine runs.  So when it sees 1791 is active it changes it to 1088, then prints a confirmation to the command line, and vice versa.

I have a feeling this is simple, but for some reason the solution elludes me.

Thanks for your help!

 

deegeecees

  • Guest
Re: Print results of lisp routine on command line...
« Reply #1 on: August 11, 2010, 10:59:29 AM »
I believe it would be something like this (not tested):

Code: [Select]
(defun c:rnm ()
  (setq result001 (if (= (getvar "osmode") 1791)
     (setvar "osmode" 1088) ;Sets object snap mode to insertion point only
     (setvar "osmode" 1791) ;Sets object snap mode to "normal" osmode
  ))
(print result001)
(princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Print results of lisp routine on command line...
« Reply #2 on: August 11, 2010, 11:05:59 AM »
To add a princ use this:
Code: [Select]
(defun c:rnm ()
  (if (= (getvar "osmode") 1791)
    (progn
      (setvar "osmode" 1088) ;Sets object snap mode to insertion point only
      (princ "\nOsmode Insertion point only set.")
    )
    (progn
      (setvar "osmode" 1791) ;Sets object snap mode to "normal" osmode
      (princ "\nOsmode set to \"normal\".")
    )
  )
  (princ)
)


AND welcome to The Swamp.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hammonj7

  • Guest
Re: Print results of lisp routine on command line...
« Reply #3 on: August 11, 2010, 12:02:47 PM »
 :-D  Thanks guys!  Both solutions work, I will test each out and see which is preferred by the group.

I appreciate your help!

And thanks for the welcome, I hope one day to be able to contribute answers instead of just questions! :whistle:

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Print results of lisp routine on command line...
« Reply #4 on: August 11, 2010, 12:52:04 PM »
And thanks for the welcome, I hope one day to be able to contribute answers instead of just questions! :whistle:
You already have; by asking the question.

Welcome to TheSwamp!
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Print results of lisp routine on command line...
« Reply #5 on: August 11, 2010, 02:19:15 PM »
Perhaps another solution - maybe more concise, but assumes that OSMODE is either 1791 or 1088 to begin with, else toggles the bits surrounding those in addition to the key values.

Code: [Select]
(defun c:rnm nil
  (princ
    (if
      (= 1791
        (setvar 'OSMODE
          (boole 6 (getvar 'OSMODE) 703)
        )
      )
      "\n<Normal OSnap>"
      "\n<Insertion Set>"
    )
  )
  (princ)
)