blockswap with extra attribute

Discussion in 'AutoCAD' started by Laura, Nov 9, 2004.

  1. Laura

    Laura Guest

    I've got a lisproutine blockswap that replacec one block for another. (see
    below)
    It works great, but it is having trouble with attributes. As long as the
    block already has attributes than you can replace the block for another and
    the blocks keeps the attribute with the value.

    Now I have a existing block with a attribute and I want it to replace it
    with another block, but with 2 attributes (1 attribute extra).
    The problem is that it changes the block, keeps the value of the attribute,
    but doesn't add the seccond attribute.
    I've got 430 blocks to do that way. What is the best method to do this?

    greetings

    Laura

    (defun C:BLKSWAP ()
    (command "zoom" 1xp) ; ingebouwde undo-functie
    (prompt "\nBLKSWAP - Replace one block for another")
    (setq SELECTION_SET (ssget))
    (setq NO_OF_ITEMS (sslength SELECTION_SET))
    (setq BLKNAME (getstring "\nEnter the name of the new block : "))
    (setq INDEX 0)
    (repeat NO_OF_ITEMS
    (setq ENTITY_NAME (ssname SELECTION_SET INDEX))
    (setq ENTITY_LIST (entget ENTITY_NAME))
    (setq ENTITY_TYPE (cdr (assoc 0 ENTITY_LIST)))
    (if (equal ENTITY_TYPE "INSERT")
    (progn
    (setq OLD_BLOCK (assoc 2 ENTITY_LIST))
    (setq NEW_BLOCK (cons 2 BLKNAME))
    (setq NEW_ENTITY_LIST
    (subst NEW_BLOCK OLD_BLOCK ENTITY_LIST)
    )
    (entmod NEW_ENTITY_LIST)
    )
    )
    (setq INDEX (1+ INDEX))
    )
    (prompt "\nProgram complete.")
    (princ)
    )
     
    Laura, Nov 9, 2004
    #1
  2. Laura

    Laura Guest

    Oh, I'm using AutoCAD 2000i
     
    Laura, Nov 9, 2004
    #2
  3. My sentiments exactly...

    I'm working on a drawing for our own office refurb and I keep needing to add
    more and more detail to the blocks, the only way I have been able to do it
    is redfine the block and then reinsert them so I can take advantage of the
    new attributes. I'm using 2004 and I don't know that there is any new tools
    in there to do it.

    Daniel
     
    Daniel Bennett, Nov 9, 2004
    #3
  4. Laura

    LUCAS Guest

    See the command of "attredef" & "_BattMan"
     
    LUCAS, Nov 9, 2004
    #4
  5. Laura

    Alaspher Guest

    Hi, Laura!

    Try this code (put all below written to one lisp-file and load (made for R16, but may be will work in R15)):

    (defun c:rein () (pl:reinsert-newname-attval))
    (vl-load-com)

    (defun pl:reinsert-newname-attval (/ newn doc snam sels sel slst tmp)
    (if (/= (setq newn (getstring "\nEnter new name for blocks <Exit>: " t)) "")
    (progn
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
    snam "pl-temp-selection"
    sels (vla-get-selectionsets doc)
    blocks (vla-get-blocks doc)
    )
    (if (not (vl-catch-all-error-p (vl-catch-all-apply (function vla-item) (list blocks newn))))
    (progn (if (vl-catch-all-error-p (setq sel (vl-catch-all-apply (function vla-item) (list sels snam))))
    (setq sel (vla-add sels snam))
    )
    (vla-clear sel)
    (princ "\nSelect block's inserts.")
    (vla-selectonscreen
    sel
    (vlax-safearray-fill (vlax-make-safearray vlax-vbinteger '(0 . 0)) '(0))
    (vlax-safearray-fill (vlax-make-safearray vlax-vbvariant '(0 . 0)) '("INSERT"))
    )
    (vlax-for x sel (setq slst (cons x slst)))
    (vla-clear sel)
    (vla-delete sel)
    (foreach x slst
    (setq tmp (vla-insertblock
    (vla-objectidtoobject doc (vla-get-ownerid x))
    (vla-get-insertionpoint x)
    newn
    (vla-get-xscalefactor x)
    (vla-get-yscalefactor x)
    (vla-get-zscalefactor x)
    (vla-get-rotation x)
    )
    )
    (pl:attreval x tmp)
    (vla-delete x)
    )
    )
    (princ (strcat "\nBlock with name: '" newn "' not exist in this drawing."))
    )
    )
    )
    (princ)
    )

    (defun pl:attreval (from to / tmp att1 att2)
    (if (and (setq from (pl:get-att-with-tag from)) (setq to (pl:get-att-with-tag to)))
    (foreach x from
    (if (setq tmp (assoc (car x) to))
    (progn (setq att1 (cdr x)
    att2 (cdr tmp)
    )
    (if (= (vla-get-constant att2) :vlax-false)
    (foreach y '("alignment" "backward" "height" "insertionpoint"
    "obliqueangle" "scalefactor" "stylename" "textstring"
    "thickness" "color" "upsidedown"
    )
    (vl-catch-all-apply
    (read (strcat "vla-put-" y))
    (list att2 (vl-catch-all-apply (read (strcat "vla-get-" y)) (list att1)))
    )
    )
    )
    (vl-remove tmp to)
    )
    )
    )
    )
    )

    (defun pl:get-att-with-tag (ins)
    (if (= (vla-get-hasattributes ins) :vlax-true)
    (mapcar (function (lambda (x) (cons (vla-get-tagstring x) x)))
    (vlax-safearray->list (vlax-variant-value (vla-getattributes ins)))
    )
    )
    )

    (progn (princ "\nEnter: 'rein' in the command string for begining.") (princ))
     
    Alaspher, Nov 9, 2004
    #5
  6. Laura

    Laura Guest

    I'm not familiar with the _BattMan command, but the "attredef" works great.
    A real timesaver. Thank you very much.

    Laura
     
    Laura, Nov 9, 2004
    #6
  7. Battman is great I use it all the time, however it doesn't let you add
    another attribute to an excising block... or does it?

    But ATTREDEF is my new best friend!

    Thanks Lucas, I wish I had known about this one earlier!

    Daniel.
     
    Daniel Bennett, Nov 9, 2004
    #7
  8. Laura

    Laura Guest

    This is working great. Just what I was looking for!
    It works in AutoCAD 2000i
    But if all goes wel, we are getting AutoCAD 2005 in a few days! I cannot
    wait.....

    thanks again!

    Laura
     
    Laura, Nov 9, 2004
    #8
  9. Laura

    LUCAS Guest

    Hi! Daniel Bennett
    You are welcome!
    You can also see the command of "attsync".

    No! it doesn't let you add another attribute to an excising block.
    But "Battman" can reorder the attribute.
     
    LUCAS, Nov 9, 2004
    #9
  10. Laura

    Laura Guest

    Ok, i think I found a something. Or I'm doing something wrong (I think it's
    me....).
    When I use the attredef command, my existing attributes are moving to an
    other place.
    They stay near the block, but on a different place, so I have to replace my
    attribute.

    What am I doing wrong?

    laura
     
    Laura, Nov 9, 2004
    #10
  11. Laura

    Laura Guest

    How can I prevent the existing attributetext from changing places?

    laura
     
    Laura, Nov 9, 2004
    #11
  12. <<When I use the attredef command, my existing attributes are moving to an
    other place.
    They stay near the block, but on a different place, so I have to replace my
    attribute.>>

    By ensuring that the Block is redfined with the same insertion point. Also
    note that if you have mirrored any blocks that when you use attredef you do
    it to a block that is rotation is set to zero and that the scales are 1 for
    x,y&z a negative number would indicate a block that has been mirrored.

    I'm going through this right now too, so I feel your pain. But at least if
    you have got one wrong you can use BATTMAN to move the inserts back to where
    you want them, you can the use the sync option and I believe to corrects all
    the other blocks.

    Daniel
     
    Daniel Bennett, Nov 9, 2004
    #12
  13. << But "Battman" can reorder the attribute.>>

    Ahh, one of my favourite tools! Don't know how I made it through my first
    two years without this one.

    Daniel
     
    Daniel Bennett, Nov 9, 2004
    #13
  14. Laura

    Laura Guest

    I don't have BATTMAN in 2000i. But I'll remember it when we are going over
    to 2005 (I hope in a few days)
    But it's still a great sollution.

    laura
     
    Laura, Nov 9, 2004
    #14
  15. Laura

    Alaspher Guest

    If you ask about my code, then the new attributes places acquires from an existing (replaced) insertion. If you want to prevent it, then remove "insertionpoint" from list: '("alignment" "backward" "height" "insertionpoint" "obliqueangle" "scalefactor" "stylename" "textstring" "thickness" "color" "upsidedown") in the function 'pl:attreval'.

    Regards!
     
    Alaspher, Nov 9, 2004
    #15
  16. Wasn't there in 2000i (ahh I remember my upgrade to 2000i how sweet it
    was).... anyway BATTMAN is great give it a shot in two days the ability to
    be able to resort the order of Attributes is worth it's weight in Gold.

    In fact tell your boss that there is a really great feature in 2005 that is
    going to save you so much heartache and time, never know, he might let you
    pilot the installation!

    Daniel
     
    Daniel Bennett, Nov 9, 2004
    #16
  17. Laura

    Laura Guest

    I'm going to pilot the installation!!
    Can't wait....just a few days.....

    Laura
     
    Laura, Nov 9, 2004
    #17
  18. Laura

    Laura Guest

    Thank you. I'll try it.

    laura
     
    Laura, Nov 9, 2004
    #18
  19. Laura

    Jürg Menzi Guest

    Hi Laura

    Is the only difference between old and new block the additional attribute?

    Cheers
     
    Jürg Menzi, Nov 9, 2004
    #19
  20. Hi Juerg,

    In my case it was, although I had to relocate all the attributes slightly to
    keep it all inside the block.

    Daniel
     
    Daniel Bennett, Nov 9, 2004
    #20
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.