Author Topic: Sum Mleaders values to Mleader with Field  (Read 2203 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Sum Mleaders values to Mleader with Field
« on: October 01, 2015, 05:19:06 PM »
Hello guys.

The following codes works if I select single Mleader but if I try to select more Mleaders to sum their values ( numbers ), it fails.

Any one can take a look and give a solution please ?

Thanks in advance.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ fmt lst sel str in)
  2.   (setq fmt "%lu6%qf1")
  3.   (if (setq sel (ssget '((0 . "MULTILEADER"))))
  4.     (if (= 1 (sslength sel))
  5.       (progn (setq str
  6.                     (strcat
  7.                       "%<\\AcObjProp Object(%<\\_ObjId "
  8.                       (LM:ObjectID (vlax-ename->vla-object (ssname sel 0)))
  9.                       ">%).TextString>%"
  10.                     )
  11.              )
  12.              (if str
  13.                (command "_.mleader" "\\" "\\" str)
  14.              )
  15.       )
  16.       (progn
  17.         (repeat (setq in (sslength sel))
  18.           (setq lst
  19.                  (vl-list*
  20.                    "%<\\AcObjProp Object(%<\\_ObjId "
  21.                    (LM:ObjectID
  22.                      (vlax-ename->vla-object (ssname sel (setq in (1- in))))
  23.                    )
  24.                    ">%).TextString>%"
  25.                    " + "
  26.                    lst
  27.                  )
  28.           )
  29.         )
  30.         (setq
  31.           str (strcat
  32.                 "%<\\AcExpr "
  33.                 (apply 'strcat (reverse (cdr (reverse lst))))
  34.                 " \\f \""
  35.                 fmt
  36.                 "\">%"
  37.               )
  38.         )
  39.         (command "_.mleader" "\\" "\\" str)
  40.       )
  41.     )
  42.   )
  43.   (princ)
  44. )
  45. ;; ObjectID  -  Lee Mac
  46. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  47. ;; Compatible with 32-bit & 64-bit systems
  48.  
  49. (defun LM:ObjectID ( obj )
  50.     (eval
  51.         (list 'defun 'LM:ObjectID '( obj )
  52.             (if
  53.                 (and
  54.                     (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  55.                     (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  56.                 )
  57.                 (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  58.                '(itoa (vla-get-objectid obj))
  59.             )
  60.         )
  61.     )
  62.     (LM:ObjectID obj)
  63. )
  64. ;; Active Document  -  Lee Mac
  65. ;; Returns the VLA Active Document Object
  66.  
  67. (defun LM:acdoc nil
  68.     (LM:acdoc)
  69. )

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Sum Mleaders values to Mleader with Field
« Reply #1 on: October 01, 2015, 05:41:03 PM »
Quick fix, add the following between lines 39 & 40:
Code - Auto/Visual Lisp: [Select]
  1.             (vla-put-textstring (vlax-ename->vla-object (entlast)) str)
  2.             (command "_.regen")

Coder

  • Swamp Rat
  • Posts: 827
Re: Sum Mleaders values to Mleader with Field
« Reply #2 on: October 01, 2015, 05:49:04 PM »
Quick fix, add the following between lines 39 & 40:
Code - Auto/Visual Lisp: [Select]
  1.             (vla-put-textstring (vlax-ename->vla-object (entlast)) str)
  2.             (command "_.regen")

Perfect  :wink: Thank you Lee.

I am confused why the field codes work with single selection and it doesn't work with multiple selection !
Is there any logic reason behind this failure ?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Sum Mleaders values to Mleader with Field
« Reply #3 on: October 01, 2015, 06:28:36 PM »
I am confused why the field codes work with single selection and it doesn't work with multiple selection !
Is there any logic reason behind this failure ?

The command-line text input may not be able to interpret Expression Fields or nested Fields.

Coder

  • Swamp Rat
  • Posts: 827
Re: Sum Mleaders values to Mleader with Field
« Reply #4 on: October 02, 2015, 03:32:25 AM »
Thank you.