Author Topic: trying to eval functions from a list of strings - not working  (Read 1889 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
trying to eval functions from a list of strings - not working
« on: October 11, 2018, 04:48:37 PM »
I am trying to invoke an active-x method based on a string:

Code: [Select]
;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Routine: ApplySet
Purpose: Applies a method and it's arguments to an object
Arguments: obj - vla-object to which the method is applied
Args - a list of arguments as contained in TST:Styles, above
Returns: Nothing of value
-----------------------------------------------------------------------------------------
Example 1: (ApplySet obj '("TitleSuppressed" . :vlax-false)) where obj is a tablestyle object
Results:   Sets the TitleSuppressed property to false

Example 2: (ApplySet obj '("gridlineweight"
    (+ acHorzBottom acHorzInside acHorzTop acVertInside acVertLeft acVertRight)
    acDataRow
    acLnWtByLayer
      )
   )
Results:   Sets all datarow cell border lineweights to ByLayer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;
(defun ApplySet (obj Args / strMethodName)
  (setq
    strMethodName (strcat "vla-set" (car Args))
    MethodArgs   (cdr Args)
  )
  (cond
    ((null (listp MethodArgs))
     (eval (list (read strMethodName) obj MethodArgs)))
    (T
     (eval (append (list (read strMethodName)) (append (list obj) (cdr Args))))
    )
  )     ;end cond
)     ;end defun ApplySet

The second example runs without error (obj is a tablestyle object), though it doesn't seem to do anything.
The first example exits the routine when it tries to EVAL the function.

In both examples obj is a tablestyle object.

Two questions:
1.  Why doesn't the first example complete?
2.  Why doesn't the second example change the tablestyle?

With no errors on #1 I'm kind of stumped.

With the flaky object model for tablestyles I don't know if I'm doing something wrong with #2, or the object model is just broken.

Any suggestions appreciated.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: trying to eval functions from a list of strings - not working
« Reply #1 on: October 11, 2018, 05:03:25 PM »
In the first example the 'ApplySet' subfunction tries to call a method with a name "vla-setTitleSuppressed" that basically doesn't exist.
However a theres a "TitleSuppressed" property, thats accessible via "vla-get-TitleSuppressed" method, but its read only so you won't find "vla-set-TitleSuppressed" method.

Notice the dash "-" between "set" and the "TitleSuppressed" property name, it makes a difference if you are trying to call a method or get/change a property.
Code: [Select]
(vla-<MethodName> obj args) ; method "vla-SetGridLineWeight" exists
(vla-get-<PropertyName> obj prop)
(vla-set-<PropertyName> obj prop val)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: trying to eval functions from a list of strings - not working
« Reply #2 on: October 11, 2018, 05:09:41 PM »
Quick & dirty alternate approach for illuminating purposes tho I wouldn't put into production code as it's overkill:

Code: [Select]
(defun ApplySet ( obj args / prop val )
    (cond
        (   (null (vlax-property-available-p obj (setq prop (car args))))
            (and
                *debug* ;; if this global var is non nil an error message will echoed
                (princ (strcat "\nInvalid property: " (vl-princ-to-string prop)))
            )     
            nil
        )
        (   (vl-catch-all-apply 'vlax-put (list obj prop (setq val (cdr args))))
            (and
                *debug* ;; if this global var is non nil an error message will echoed
                (princ (strcat "\nInvalid value: " (vl-prin1-to-string val)))
            )           
            nil
        )
        (   T   )
    )
)

Example usage (noting the property is not a string but a symbol):

(ApplySet obj '(TitleSuppressed . :vlax-false))

Returns T if no error was encountered.
« Last Edit: October 11, 2018, 05:28:41 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: trying to eval functions from a list of strings - not working
« Reply #3 on: October 11, 2018, 06:23:23 PM »
Heres some old function from my library:
Code - Auto/Visual Lisp: [Select]
  1. ; Usage Example:
  2. ; (InvokeTableMethods (AddOrFindTableStyle "ABC")
  3. ;   '(
  4. ;     (SetAlignment
  5. ;       (acTitleRow acMiddleRight)
  6. ;       (acHeaderRow acMiddleRight)
  7. ;       (acDataRow acMiddleRight)
  8. ;     ); list
  9. ;     (SetAlignment
  10. ;       (acTitleRow acMiddleCenter)
  11. ;       (acHeaderRow acMiddleCenter)
  12. ;       (acDataRow acMiddleCenter)
  13. ;     ); list
  14. ;     (SetTextHeight
  15. ;       (acTitleRow (* (getvar 'textsize) 1.5))
  16. ;       (acHeaderRow (* (getvar 'textsize) 1.2))
  17. ;       (acDataRow (* (getvar 'textsize) 1.0))
  18. ;     ); list
  19. ;     (SetBackgroundColor
  20. ;       (acTitleRow (Value->AcCmColor 255))
  21. ;       (acHeaderRow (Value->AcCmColor '(250 230 250)))
  22. ;       (acDataRow (Value->AcCmColor '(200 180 200)))
  23. ;       (acUnknownRow (Value->AcCmColor 255))
  24. ;     ); list
  25. ;     (SetBackgroundColorNone
  26. ;       (acTitleRow :vlax-true)
  27. ;       (acHeaderRow :vlax-true)
  28. ;       (acDataRow :vlax-true)
  29. ;       (acUnknownRow :vlax-true)
  30. ;     ); list
  31. ;   ); list
  32. ; ); InvokeTableMethods
  33.  
  34. (setq InvokeTableMethods
  35.   (lambda ( o L )
  36.    
  37.     (defun ReleaseColorObjectp ( o )
  38.       (cond
  39.         ( (not (eq 'VLA-OBJECT (type o))) )
  40.         ( (not (vl-every '(lambda (x) (vlax-property-available-p o x)) '(Blue BookName ColorIndex ColorMethod ColorName EntityColor Green Red))) )
  41.         ( (vlax-release-object o) )
  42.       ); cond
  43.     ); defun ReleaseColorObjectp
  44.    
  45.     (mapcar
  46.       (function
  47.         (lambda (subL / mtd argsL)
  48.           (setq mtd (car subL))
  49.           ; (setq argsL (mapcar 'eval (cdr subL)))
  50.           (setq argsL (mapcar (function (lambda (x) (mapcar 'eval x))) (cdr subL)))
  51.           (mapcar (function (lambda (x) (apply 'vlax-invoke (append (list o mtd) x)) )) argsL) ; vl-catch-all-apply / apply
  52.           (mapcar (function (lambda (x) (mapcar (function ReleaseColorObjectp) x))) argsL)
  53.         ); lambda
  54.       ); function
  55.       L
  56.     ); mapcar
  57.   ); lambda o
  58. ); setq InvokeTableMethods
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg