Author Topic: Using EVAL & READ  (Read 1529 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Using EVAL & READ
« on: June 15, 2009, 01:47:14 PM »
I have been experimenting with a new approach to updating objects with Visual LISP, and was trying to formulate a different way to update various properties at once.

Something like:

Code: [Select]
(defun c:mtxt (/ tEnt tObj ss)
  (vl-load-com)
  (if (and (setq tEnt (car (entsel "\nSelect Source Text: ")))
           (wcmatch (cdadr (entget tEnt)) "ATT*,*TEXT")
           (setq tObj (vlax-ename->vla-object tEnt)))
    (while (setq ss (ssget '((0 . "*TEXT,ATT*"))))
      (foreach Obj (mapcar 'vlax-ename->vla-object
                     (vl-remove-if 'listp
                       (mapcar 'cadr (ssnamex ss))))
        (foreach fun '("Layer" "Color" "Height" "ObliqueAngle" "ScaleFactor" "StyleName")
          (eval ((read (strcat "vla-put-" fun)) Obj
                  ((read (strcat "vla-get-" fun)) tObj))))))
    (princ "\n<< Nothing Selected >>"))
  (princ))

The section I am struggling with is:

Code: [Select]
(foreach fun '("Layer" "Color" "Height" "ObliqueAngle" "ScaleFactor" "StyleName")
          (eval ((read (strcat "vla-put-" fun)) Obj
                  ((read (strcat "vla-get-" fun)) tObj))))

I keep receiving a "bad-function" error.

I am not experienced in using the "eval" and "read" functions, so help in this matter is much appreciated  :-)

Thanks for your time,

Lee

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using EVAL & READ
« Reply #1 on: June 15, 2009, 02:05:43 PM »
No need to do all that.  Here is an example

ob2 = valid AX object

Code: [Select]
Command: (vla-get-layer ob2)
"temp"
Command: (setq lay "0")
"0"
Command: (setq prop "layer")
"layer"
Command: (vlax-put ob2 prop lay)
nil
Command: (vla-get-layer ob2)
"0"
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using EVAL & READ
« Reply #2 on: June 15, 2009, 02:07:44 PM »
Note that you will get an error as there is no 'ObliqueAngle' property in Mtext.
Code: [Select]
(defun c:mtxt (/ tEnt tObj ss)
  (vl-load-com)
  (if (and (setq tEnt (car (entsel "\nSelect Source Text: ")))
           (wcmatch (cdadr (entget tEnt)) "ATT*,*TEXT")
           (setq tObj (vlax-ename->vla-object tEnt)))
    (while (setq ss (ssget '((0 . "*TEXT,ATT*"))))
      (foreach Obj (mapcar 'vlax-ename->vla-object
                     (vl-remove-if 'listp
                       (mapcar 'cadr (ssnamex ss))))
        (foreach fun '("Layer" "Color" "Height" "ObliqueAngle" "ScaleFactor" "StyleName")
          ((eval (read (strcat "vla-put-" fun))) Obj
                  ((eval(read (strcat "vla-get-" fun))) tObj)))))
    (princ "\n<< Nothing Selected >>"))
  (princ))
Also see (vlax-get-property object property) and (vlax-property-available-p obj prop [check-modify])
« Last Edit: June 15, 2009, 02:16:50 PM by CAB »
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using EVAL & READ
« Reply #3 on: June 15, 2009, 08:54:50 PM »
Thanks for the information guys, this is what I went with in the end:

Code: [Select]
(defun c:mtxt (/ tEnt tObj ss)
  (vl-load-com)
  (if (and (setq tEnt (car (entsel "\nSelect Source Text: ")))
           (wcmatch (cdadr (entget tEnt)) "ATT*,*TEXT")
           (setq tObj (vlax-ename->vla-object tEnt)))
    (while (setq ss (ssget '((0 . "*TEXT,ATT*"))))
      (foreach Obj (mapcar 'vlax-ename->vla-object
                     (vl-remove-if 'listp
                       (mapcar 'cadr (ssnamex ss))))
        (foreach fun '(Layer Color Height ObliqueAngle ScaleFactor StyleName)
          (if (and (vlax-property-available-p tObj fun)
                   (vlax-property-available-p Obj fun t))
            (vlax-put-property Obj fun
              (vlax-get-property tObj fun))))))
    (princ "\n<< Nothing Selected >>"))
  (princ))

Let me know if you see any room for further improvement - I'm always looking to improve.   8-)

Thanks,

Lee