Results 1 to 9 of 9

Thread: Need Help: Auto Numbering Block attributes

  1. #1
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Need Help: Auto Numbering Block attributes

    Hello all,
    I am trying to Autonumber some blocks
    I am trying to use the insertion point to determine the sequence of numbering, with the numbers staring at the top right working down and then next column to the left (see attached jpg)

    The code below is just kind of what my thought process is so far but I get stuck after that.

    Thank you all for your help in advance,
    Andre

    Code:
    (defun c:detcount (/ ss1 attname attval)
      (setq ss1 (ssadd))
      (setq attname "DETNO")
      (setq attval 1)
    
      (setq ss1 (ssadd (ssget) ss1))
    
      ;insertion values for each block selected
      ;modify attribute value of block "1"(see attached JPG)
      (setq attval (+ attval 1))
      ;modify attribute value of block "2"(see attached JPG)
      (setq attval (+ attval 1))
      ;modify attribute value etc...
      
      (princ))
    Thanks again,
    Andre
    Attached Images Attached Images

  2. #2
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    I would sort by X value and place into subgroups within a list, then sort each sublist by Y value and start you incremental count.
    The easiest thing would be to prompt the user to specify a count of how many rows and columns (your picture having 4 columns and 3 rows).

  3. #3
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes


  4. #4
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    Couldn't sleep last night...

    It will work on attributed blocks, MText and Text. You have the options to sort from Top or Bottom, then Left or Right.

    Hope this helps.

    Code:
    (defun c:AutoInc (/ _x _y _gbn _ss2l _0 r ss i lat long)
      ;; Alan J. Thompson, 03.26.10
    
      (vl-load-com)
    
      (setq _x (lambda (e) (car (cdr (assoc 10 (entget e))))))
      (setq _y (lambda (e) (cadr (cdr (assoc 10 (entget e))))))
      (setq _gbn (lambda (L # / n g f)
                   (setq n -1)
                   (while (> (1- (length L)) n)
                     (repeat # (setq g (cons (nth (setq n (1+ n)) L) g)))
                     (setq f (cons (reverse g) f)
                           g nil
                     ) ;_ setq
                   ) ;_ while
                   (reverse f)
                 ) ;_ lambda
      ) ;_ setq
      (setq _ss2l (lambda (x / e i l)
                    (if (eq (type x) 'PICKSET)
                      (progn (setq i -1)
                             (while (setq e (ssname x (setq i (1+ i))))
                               (setq l (cons e l))
                             ) ;_ while
                             l
                      ) ;_ progn
                    ) ;_ if
                  ) ;_ lambda
      ) ;_ setq
      (setq _0 (lambda (l) (vl-position (cdr (assoc 0 (entget x))) l)))
    
      (or *AI:LR* (setq *AI:LR* "Right"))
      (or *AI:TB* (setq *AI:TB* "Top"))
    
      (cond
        ((and (setq r (getint "\nSpecify number of rows: "))
              (not (initget 0 "Left Right"))
              (setq *AI:LR* (cond
                              ((getkword (strcat "\nSort from Left or Right? [Left/Right] <"
                                                 *AI:LR*
                                                 ">: "
                                         ) ;_ strcat
                               ) ;_ getkword
                              )
                              (*AI:LR*)
                            ) ;_ cond
              ) ;_ setq
              (not (initget 0 "Top Bottom"))
              (setq *AI:TB* (cond
                              ((getkword (strcat "\nSort from Top or Bottom? [Top/Bottom] <"
                                                 *AI:TB*
                                                 ">: "
                                         ) ;_ strcat
                               ) ;_ getkword
                              )
                              (*AI:TB*)
                            ) ;_ cond
              ) ;_ setq
              (setq ss (_ss2l (ssget "_:L"
                                     '((-4 . "<OR")
                                       (0 . "MTEXT,TEXT")
                                       (-4 . "<AND")
                                       (0 . "INSERT")
                                       (66 . 1)
                                       (-4 . "AND>")
                                       (-4 . "OR>")
                                      )
                              ) ;_ ssget
                       ) ;_ _ss2l
              ) ;_ setq
    
         ) ;_ and
    
         (setq lat  (if (eq *AI:LR* "Left")
                      <
                      >
                    ) ;_ if
               long (if (eq *AI:TB* "Top")
                      >
                      <
                    ) ;_ if
         ) ;_ setq
    
         (setq i 0)
         (foreach x
                  (apply
                    (function append)
                    (mapcar
                      (function (lambda (l) (vl-sort l (function (lambda (a b) (long (_y a) (_y b)))))))
                      (mapcar (function (lambda (y) (vl-remove nil y)))
                              (_gbn (vl-sort ss (function (lambda (a b) (lat (_x a) (_x b))))) r)
                      ) ;_ mapcar
                    ) ;_ mapcar
                  ) ;_ apply
    
           (cond
             ((_0 '("MTEXT" "TEXT"))
              (vl-catch-all-apply
                (function vla-put-textstring)
                (list (vlax-ename->vla-object x) (itoa (setq i (1+ i))))
              ) ;_ vl-catch-all-apply
             )
             ((_0 '("INSERT"))
              (vl-catch-all-apply
                (function vla-put-textstring)
                (list (car (vlax-invoke (vlax-ename->vla-object x) (function GetAttributes)))
                      (itoa (setq i (1+ i)))
                ) ;_ list
              ) ;_ vl-catch-all-apply
             )
           ) ;_ cond
    
    
         ) ;_ foreach
        ) ;_ cond
      ) ;_ cond
      (princ)
    ) ;_ defun
    Attached Images Attached Images

  5. #5
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    Did you get things sorted?

  6. #6
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Talking Re: Need Help: Auto Numbering Block attributes

    Quote Originally Posted by alanjt View Post
    Couldn't sleep last night...

    It will work on attributed blocks, MText and Text. You have the options to sort from Top or Bottom, then Left or Right.
    Quote Originally Posted by alanjt View Post
    Did you get things sorted?
    I just read your previous post, it worked perfect, thank you all very much.

    Andre

  7. #7
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    Alan,
    How did you make that gif file?

  8. #8
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    Quote Originally Posted by ReachAndre View Post
    I just read your previous post, it worked perfect, thank you all very much.

    Andre
    You're welcome. Glad it helps.

    Quote Originally Posted by ReachAndre View Post
    Alan,
    How did you make that gif file?
    I used Camtasia.

  9. #9
    Member
    Join Date
    2011-12
    Posts
    3
    Login to Give a bone
    0

    Default Re: Need Help: Auto Numbering Block attributes

    Is there any way to do what alanJt has done, but for it to remember the last number you used, and then carry on from the next number when you do it again?

    Or better still, for it to detect which numbers have and have not been used and use the next set of numbers in an ascending sequence?

    Gerry

Similar Threads

  1. Dynamic Block / Attributes Auto Update
    By jesse732900 in forum AutoCAD General
    Replies: 0
    Last Post: 2012-04-03, 09:55 PM
  2. Excel to Auto cad block attributes
    By pksen515343 in forum AutoCAD General
    Replies: 1
    Last Post: 2012-01-23, 12:26 PM
  3. Auto number multiple Block Attributes [Idiot's guide please...]
    By emailsam in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2010-10-25, 11:56 PM
  4. auto numbering block attrib
    By lee.johnson in forum AutoLISP
    Replies: 3
    Last Post: 2010-07-01, 02:38 PM
  5. link mtext auto-numbering to block text
    By dnicho12 in forum AutoCAD Fields
    Replies: 1
    Last Post: 2007-01-29, 07:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •