Lisp for text increment.

Lisp for text increment.

Anonymous
Not applicable
3,704 Views
5 Replies
Message 1 of 6

Lisp for text increment.

Anonymous
Not applicable

I HAVE A SET OF MLEADERS WITH USER BLOCK WITH ATTRIBUTES. I SOMETIMES MISS AN OBJECT THRU TAGGING WHICH I NEED TO ADJUST AGAIN ALL THE NUMBER BY ONE. IS THERE ANY LISP THAT WILL AUTOMATICALLY ADJUST MY NUMBER BY +1 ON ALL THE SAME MLEADER AT THE SAME-TIME. +1(INCREMENT).

0 Likes
Accepted solutions (1)
3,705 Views
5 Replies
Replies (5)
Message 2 of 6

DannyNL
Advisor
Advisor

Should be fairly easily to code.

Can you post an example drawing with the block as we need to know the attribute tag containing the number.

0 Likes
Message 3 of 6

krzysztof.psujek
Advocate
Advocate
Accepted solution

Hi,

easy and dirty but should works for you.

Run it with TRY in cmd - you can change it if you want to.

Lisp was written by LeeMac, I've just modified a little his test part.

 

 

;;---------=={ Set MLeader Block Attribute Value }==----------;;
;;                                                            ;;
;;  Sets the value of the specified tag for the specified     ;;
;;  MLeader                                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  mleader - ename/VLA-Object MLeader with attributed block  ;;
;;  tag     - Tagstring of the attribute to change            ;;
;;  value   - Value to which attribute will be set            ;;
;;------------------------------------------------------------;;
;;  Returns:  T if successful, else nil                       ;;
;;------------------------------------------------------------;;

(defun LM:SetMLeaderBlockAttributeValue ( mleader tag value / def id )
  (vl-load-com)
  ;; © Lee Mac 2010

  (if
    (and
      (eq "AcDbMLeader"
        (vla-get-Objectname
          (setq mleader
            (cond
              ( (eq 'VLA-OBJECT (type mleader)) mleader)
              ( (vlax-ename->vla-object mleader) )
            )
          )
        )
      )
      (= 1 (vla-get-ContentType mleader))
      (setq def
        (LM:Itemp
          (vla-get-Blocks
            (vla-get-ActiveDocument
              (vlax-get-acad-object)
            )
          )
          (vla-get-ContentBlockName mleader)
        )
      )
    )
    (if
      (progn
        (vlax-for obj def
          (if (and (eq "AcDbAttributeDefinition" (vla-get-Objectname obj))
                   (eq (strcase tag) (strcase (vla-get-TagString obj))))
            (setq id (vla-get-ObjectID obj))
          )
        )
        id
      )
      (not (vla-SetBlockAttributeValue mleader id value))
    )
  )
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:Itemp ( coll item )
  ;; © Lee Mac 2010
  (if
    (not
      (vl-catch-all-error-p
        (setq item
          (vl-catch-all-apply
            (function vla-item) (list coll item)
          )
        )
      )
    )
    item
  )
)
;;;

(defun c:Try (/ i e); change command here
  (setq i 0)				; enter start number here instead of 0
  (while (setq e (car (entsel "\nSelect MLeader: ")))
    (LM:SetMLeaderBlockAttributeValue e "TAG" (rtos i 2 0));put TAG name which you want to modify here instead of "TAG"
    (setq i (+ 1 i))			;put increment you want here instead of 1
  )
)

Chris

 

Message 4 of 6

Anonymous
Not applicable

Capture12.PNG

THIS ONE SIR... (sz. should be no.)

0 Likes
Message 5 of 6

Anonymous
Not applicable

This one works perfect, should be reloaded every number where i start.

 

Thanks a lot sir. good for my revision as they are adding more valves in drawings. nearly thousand hehehe.

0 Likes
Message 6 of 6

Anonymous
Not applicable
(setq i 0)				; enter start number here instead of 0

can we set the "0" as a reference value for increment? by selecting/picking

0 Likes