Block numbering

Discussion in 'AutoCAD' started by Kieren, Jun 2, 2004.

  1. Kieren

    Kieren Guest

    I have a block that is inserted many times.
    All have the common attribute "NUMBER".
    Looking for routine to find all instances of inserted block and change attribute value by an increment of 1 (ie 1,2,3...) based on its X,Y insertion point, as opposed to its order of insertion.
    Many thanks,
    ..::KIEREN::..
     
    Kieren, Jun 2, 2004
    #1
  2. Kieren

    Rudy Tovar Guest

    Keep looking through the newsgroup....

    It's been well milk'd....

    Sorry don't remember the heading
    --

    AUTODESK
    Authorized Developer
    http://www.Cadentity.com
    MASi



    attribute value by an increment of 1 (ie 1,2,3...) based on its X,Y
    insertion point, as opposed to its order of insertion.
     
    Rudy Tovar, Jun 2, 2004
    #2
  3. Kieren

    T.Willey Guest

    Kieren,

    From what I understand is you want to renumber blocks by there location relative to 0,0. I would first make a list of all the x, y, and entity names (and keep those three items in a list) of all the blocks. Then I would sort them first by there "x" factor, then by there "y" factor. Then I have a list I can use. I would then just work thru the list to change the attributes.

    Tim
     
    T.Willey, Jun 2, 2004
    #3
  4. Look here:
    http://discussion.autodesk.com/thread.jspa?messageID=3793943
    John

    attribute value by an increment of 1 (ie 1,2,3...) based on its X,Y
    insertion point, as opposed to its order of insertion.
     
    John Georgiev, Jun 2, 2004
    #4
  5. You'll have to make your own sort_func. Other than that this should
    work.
    I didn't have time to test but see if this gets you going.

    (defun c:att_inc (/ doc ss att block_list sort_list cnt)
    (vl-load-com)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (vla-startundomark doc)
    (setq ss (ssget "x" (list '(0 . "INSERT") '(66 . 1))))
    (if ss
    (progn
    (vlax-for item (vla-get-activeselectionset doc)
    (setq att (variant-value (vla-getattributes item)))
    (foreach x (safearray-value att)

    ;;;Get list of all Inserts with a tag called "NUMBER"
    ;;;Along with their insertion points
    (if (= (vla-get-tagstring x) "NUMBER")
    (setq block_list
    (cons (list
    (safearray-value
    (variant-value
    (vla-get-insertionpoint item)
    )
    )
    item
    )
    block_list
    )))))

    ;;;Get the list sorted
    (setq sort_list (sort_func (mapcar 'car block_list)))

    ;;;Go back through and inc. the tag strings by one.
    (setq cnt 1)
    (foreach x sort_list
    (setq att (variant-value
    (vla-getattributes
    (car (cdr (assoc x block_list))))))
    (foreach y (safearray-value att)
    (if (= (vla-get-tagstring y) "NUMBER")
    (vla-put-textstring y (rtos cnt))
    )
    )
    (setq cnt (1+ cnt))
    )
    )
    )
    (vla-endundomark doc)
    (princ)
    )
    ;;;Need to make your own sort function
    (defun sort_func (list)
    ;;;Arg: list of point lists
    ;;;do what sorting you want
    ;;;Should return the same list sorted.
    )

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

    change attribute value by an increment of 1 (ie 1,2,3...) based on its
    X,Y insertion point, as opposed to its order of insertion.
     
    Ken Alexander, Jun 3, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.