Author Topic: (spark) sans Variables.  (Read 3784 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
(spark) sans Variables.
« on: February 13, 2004, 10:18:14 AM »
I dont have much time but I thought I would toss this at you guys.

I had this idea for a little while now, and last night I couldnt sleep so I kinda workied out a quick little solution while lying in bed. Showed it to Mark this morn and he added a line to make it even cooler so I decided to share it with you all and kinda get reactions, questions, comments or concerns. Does this spark any cool ideas?  
Code: [Select]
;; misc. support procedure for demo.
(defun getpoin7 ()
  (while (not (setq x (getpoint "\nSelect Point: ")))
     (princ "\nYou did not select a point, please try again. ")) x)
;; Construct list
(defun ConsList (lst)
  (mapcar
    '(lambda (x)
       (if (listp x)(vl-list* x)
         (cons (eval x) xlst))) lst))


Run this:
(setq templist (ConsList (list (getvar "clayer") (getvar "dimscale") (getstring T "\nEnter a string: ") (getpoin7))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
(spark) sans Variables.
« Reply #1 on: February 13, 2004, 10:35:51 AM »
I'll let that one sink in a bit.

SMadsen

  • Guest
(spark) sans Variables.
« Reply #2 on: February 13, 2004, 11:06:38 AM »
Not quite sure what the intention is. If it's only to return every item as a list you can 'save' a global by using the one below. If the intention is another, please tell. Does it have to do with the way that nil should be handled, or ...??

Code: [Select]
(defun conslist (lst)
  (mapcar (function (lambda (x) (if (atom x)(list x) x))) lst)
)

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
(spark) sans Variables.
« Reply #3 on: February 13, 2004, 12:18:53 PM »
Well my idea was for end user enviroment variables before and after the main code runs. That way you could eliminate all the "origCmdecho", "origDimscale" variables. they all would be contained in one nice list. ...Is that idea kinda corny?

"How Nil should be handled?" What do you have cooking Stig? (Is this going to give me another headache? :P )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
(spark) sans Variables.
« Reply #4 on: February 13, 2004, 12:42:38 PM »
Don't worry. I think I got the headache this time :?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
(spark) sans Variables.
« Reply #5 on: February 13, 2004, 12:51:20 PM »
Any ideas here?

Code: [Select]
;;; UNDO GORUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vlxx-UndoBegin () (vla-StartUndoMark (vlxx-ActiveDocument)))

(defun vlxx-UndoEnd () (vla-EndUndoMark (vlxx-ActiveDocument)))

;;;===================================================================;
;;; SAVE SYSTEM VARIABLES                                             ;
;;;-------------------------------------------------------------------;
;;; Save sysvars to global list for restoring later.                  ;
;;;                                                                   ;
;;; EXAMPLE: See example for using this function below.               ;
;;;                                                                   ;
;;; HISTORY: Taken from ACADX.COM                                     ;
;;;===================================================================;
(defun vlxx-VarSave (vlist)
  (foreach n vlist
    (setq G$VARS
      (if G$VARS
        (append G$VARS (list (list n (getvar n))))
        (list (list n (getvar n)))
      )
    )
  )
)
;;;===================================================================;
;;; RESTORE SYSTEM VARIABLES                                          ;
;;;-------------------------------------------------------------------;
;;; Restore sysvars from global list for restoring later.             ;
;;;                                                                   ;
;;; EXAMPLE: See example for using this function below.               ;
;;;                                                                   ;
;;; HISTORY: Taken from ACADX.COM                                     ;
;;;===================================================================;
(defun vlxx-VarRestore ( / $orr #err)
  (defun #err (s)
    (princ (strcat "\nError: " s))
    (setq G$VARS nil)
    (setq *error* $orr)
    (princ)
  )
  (setq $orr *error* *error* #err)
  (cond
    ( (and G$VARS (listp G$VARS))
      (foreach n G$VARS
        (cond
          ( (= (strcase (car n)) "CLAYER")
            (command "_.layer" "_s" (cadr n) "")
          )
          ( (= (strcase (car n)) "VIEWRES")
            (command "_.viewres" "_Y" (cadr n) "")
          )
          ( T (setvar (car n) (cadr n)) )
        )
      )
      (setq G$VARS nil)
    )
  )
  (setq *error* $orr $orr nil)
)
;|
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;;;EXAMPLE FOR TWO PREVIOUS FUNCTIONS
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;;; This is an ex. on how to properly use the previous 2 functions
;;;
;;; HISTORY: Taken from ACADX.COM
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
(defun My-Function (/ TrapError olderr fl)
  (vlxx-VarSave
   '("osmode" "autosnap" "polarmode" "blipmode" "mbuttonpan")
   )
;-----------------------------------
  (defun TrapError (s)
    (princ (strcat "\nError: " s))
    (term_dialog)
    (if fl (close fl))
    (vlxx-VarRestore)
    (vlxx-UndoEnd)
    (setq *error* olderr olderr nil)
    (princ)
  )
;-----------------------------------
  (vlxx-UndoBegin)
  (setq olderr *error* *error* TrapError)


;;---> do your wild and crazy stuff here... <---;;


  (vlxx-VarRestore)
  (setq *error* olderr)
  (vlxx-UndoEnd)
  (princ)
)
|;
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.