Author Topic: Updating attributed block within Mleader style  (Read 3826 times)

0 Members and 1 Guest are viewing this topic.

draggindakota

  • Guest
Updating attributed block within Mleader style
« on: March 12, 2015, 01:18:28 PM »
Hi, long time lurker here looking for some help. I have a grading plan with several hundred grade callouts that I need to raise 0.4 feet. The grades are called out using a multileader containing a block with two mtext attributes: one for top of curb and one for edge of pavement elevations.

I've got lisps that will add a constant value to text strings, and one that will do it to attributed blocks but nothing works when the block is inside of an mleader. I've found a few threads that hit on similar topics HERE and HERE but I'm not familiar enough with LISP to modify them to do what I want, if it's even possible to do something like that.

The mleader I'm using is attached for reference.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #1 on: March 12, 2015, 02:10:42 PM »
Using Lee's code as a base give this a try ... welcome to TheSwamp. :)

Code - Auto/Visual Lisp: [Select]
  1. ;;---------=={ Set MLeader Block Attribute Value }==----------;;
  2. ;;                                                            ;;
  3. ;;  Sets the value of the specified tag for the specified     ;;
  4. ;;  MLeader                                                   ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee McDonnell, 2010                               ;;
  7. ;;                                                            ;;
  8. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  9. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  10. ;;------------------------------------------------------------;;
  11. ;;  Arguments:                                                ;;
  12. ;;  mleader - ename/VLA-Object MLeader with attributed block  ;;
  13. ;;  tag     - Tagstring of the attribute to change            ;;
  14. ;;  value   - Value to which attribute will be set            ;;
  15. ;;------------------------------------------------------------;;
  16. ;;  Returns:  nothing                                         ;;
  17. ;;------------------------------------------------------------;;
  18.  
  19.  
  20. (defun lm:_rjp_mod_setmleaderblockattributevalue (mleader value / def id exval)
  21.   ;; © Lee Mac 2010
  22.   (if (and (eq "AcDbMLeader"
  23.                (vla-get-objectname
  24.                  (setq mleader (cond ((eq 'vla-object (type mleader)) mleader)
  25.                                      ((vlax-ename->vla-object mleader))
  26.                                )
  27.                  )
  28.                )
  29.            )
  30.            (= 1 (vla-get-contenttype mleader))
  31.            (setq def (lm:itemp (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
  32.                                (vla-get-contentblockname mleader)
  33.                      )
  34.            )
  35.       )
  36.     (vlax-for obj def
  37.       (if (eq "AcDbAttributeDefinition" (vla-get-objectname obj))
  38.         ;; RJP mod to get existing value and add a new value to it
  39.         (if (and (setq id (vla-get-objectid obj))
  40.                  (setq exval (vla-getblockattributevalue mleader id))
  41.             )
  42.           (vla-setblockattributevalue mleader id (vl-princ-to-string (+ value (atof exval))))
  43.         )
  44.       )
  45.     )
  46.   )
  47. )
  48. ;;-----------------------=={ Itemp }==------------------------;;
  49. ;;                                                            ;;
  50. ;;  Retrieves the item with index 'item' if present in the    ;;
  51. ;;  specified collection, else nil                            ;;
  52. ;;------------------------------------------------------------;;
  53. ;;  Author: Lee McDonnell, 2010                               ;;
  54. ;;                                                            ;;
  55. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  56. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  57. ;;------------------------------------------------------------;;
  58. ;;  Arguments:                                                ;;
  59. ;;  coll - the VLA Collection Object                          ;;
  60. ;;  item - the index of the item to be retrieved              ;;
  61. ;;------------------------------------------------------------;;
  62. ;;  Returns:  the VLA Object at the specified index, else nil ;;
  63. ;;------------------------------------------------------------;;
  64. (defun lm:itemp (coll item)
  65.   ;; © Lee Mac 2010
  66.   (if
  67.     (not (vl-catch-all-error-p (setq item (vl-catch-all-apply (function vla-item) (list coll item))))
  68.     )
  69.      item
  70.   )
  71. )
  72.  
  73.  
  74. (defun c:test (/ e i n ss)
  75.   (if (and (setq n (getdist "\nEnter increment amount: "))
  76.            (setq ss (ssget ":L" '((0 . "multileader"))))
  77.       )
  78.     (repeat (setq i (sslength ss))
  79.       (lm:_rjp_mod_setmleaderblockattributevalue (ssname ss (setq i (1- i))) n)
  80.     )
  81.   )
  82. )
« Last Edit: March 12, 2015, 02:14:38 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

draggindakota

  • Guest
Re: Updating attributed block within Mleader style
« Reply #2 on: March 26, 2015, 09:35:55 AM »
Thanks for the reply ronjonp, sorry it's been a bit. Got really swamped and this change got put on hold but now I'm back to it. I can't get the function to run for some reason. Should the code be saved as a regular lisp or vlx? The call for the code is lm correct? Sorry for the probably stupid questions.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #3 on: March 26, 2015, 09:54:24 AM »
Please refer to Lee's tutorial on running a lisp routine. Once loaded enter TEST on the command line,

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

draggindakota

  • Guest
Re: Updating attributed block within Mleader style
« Reply #4 on: March 26, 2015, 10:30:02 AM »
Thank you again! That is exactly what I need! Is there a way to carry the increment out to 2 decimal places?

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #5 on: March 26, 2015, 11:55:12 AM »
Thank you again! That is exactly what I need! Is there a way to carry the increment out to 2 decimal places?
Code - Auto/Visual Lisp: [Select]
  1. ;; Set this
  2. (vla-setblockattributevalue mleader id (vl-princ-to-string (+ value (atof exval))))
  3. ;; to this
  4. (vla-setblockattributevalue mleader id (rtos (+ value (atof exval)) 2 2))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

draggindakota

  • Guest
Re: Updating attributed block within Mleader style
« Reply #6 on: March 26, 2015, 12:19:36 PM »
Thanks you for the quick reply. I changed the code as you indicated but it still gives me 1 decimal place. It only does it when the number ends with a zero, i.e. 14.50. Running the lisp would then give me 14.9.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #7 on: March 26, 2015, 12:43:35 PM »
Did you reload the code after you made the change?


Works here: (alert (rtos (+ 0.4 (atof "14.5")) 2 2)) = 14.90
« Last Edit: March 26, 2015, 12:47:52 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

draggindakota

  • Guest
Re: Updating attributed block within Mleader style
« Reply #8 on: March 26, 2015, 12:46:24 PM »
Yes, and tried closing the drawing and reopening.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #9 on: March 26, 2015, 12:51:54 PM »
Don't know what to tell you .. it works fine here.  :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

draggindakota

  • Guest
Re: Updating attributed block within Mleader style
« Reply #10 on: March 26, 2015, 12:55:21 PM »
Figured it out just now. It was because DIMZIN was set to 0. Set it to 1 and all is well. From the User Documentation "DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions."

Thank you for all your help! You rock!

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Updating attributed block within Mleader style
« Reply #11 on: March 26, 2015, 01:06:34 PM »
Glad you got it sorted :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC