blockswap with extra attribute

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

  1. Laura

    Laura Guest

    Yes, that's the case,

    I have to add some numbers to some existing blocks with one attribute.
    The only thing I have to do is to fill in the second attribute. The position
    and text of the first attribute (and block) stays the same.

    laura
     
    Laura, Nov 9, 2004
    #21
  2. Laura

    Jürg Menzi Guest

    Hi

    In this case you can do something like this:
    Code:
    (defun C:Test ( / AcaDoc AttObj CurEnt OldObj)
    (vl-load-com)
    (if (setq CurEnt (car (entsel "\nSelect block to modify: ")))
    (progn
    (setq OldObj (vlax-ename->vla-object CurEnt)
    AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    AttObj (vla-AddAttribute
    (vla-Item (vla-get-Blocks AcaDoc) (vla-get-Name OldObj))
    0.25 ;height
    acAttributeModePreset
    "NewPrompt" ;prompt
    (vlax-3d-point '(0.175 -0.225 0.0)) ;(point in blockref)
    "NewTag"
    "NewValue"
    )
    )
    ;;;   (vla-put-Layer AttObj "MyAttLayer") ;if necessary
    ;;;   (vla-put-StyleName AttObj "MyTextStyle") ;if necessary
    (command "_.ATTSYNC" "_SEL" CurEnt "_YES")
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Nov 9, 2004
    #22
  3. Laura

    Laura Guest

    Hi Jürg,

    I've tried the lisp, but "_.ATTSYNC" is an unknown command. We have got
    expresstools, but I think not the right AutoCAD version (2000i). In a few
    days( I hope today....) I'm going to get AutoCAD 2005 on my computer. I'll
    try it again then.

    greetings and thanks

    Laura
     
    Laura, Nov 10, 2004
    #23
  4. Laura

    Jürg Menzi Guest

    Hi Laura

    Sorry, didn't consider that 'ATTSYNC' options have changed between 2k(i)
    and 2k2...
    For 2k(i) you've to change the line:
    (command "_.ATTSYNC" "_SEL" CurEnt "_YES")
    to
    (command "_.ATTSYNC" "" CurEnt)

    Cheers
     
    Jürg Menzi, Nov 10, 2004
    #24
  5. Excellent Piece of code Jürg.

    Thanks Laura if you hadn't made this post i'd be in the dark ages still.

    Daniel.
     
    Daniel Bennett, Nov 10, 2004
    #25
  6. Laura

    Jürg Menzi Guest

    Hi Daniel

    Glad to help...¦-)

    Cheers
     
    Jürg Menzi, Nov 10, 2004
    #26
  7. Laura

    Laura Guest

    The routine still doesn't work properly in AutoCAD 2000i, but tomorrow I
    going to try it on 2005!

    I still don't have AutoCAD 2005 on my own computer. Friday I hope, They keep
    postponing it : (
    But I'm going to use a computer tomorrow who has it already.
    I just going to knock the guy behind it away : )

    Oh joy.......

    Glad to enlighten you dark ages Daniel. Mine are going to be brighter too.

    greetings

    Laura
     
    Laura, Nov 10, 2004
    #27
  8. Laura

    Laura Guest

    Hi Jürg,

    I've got AutoCAD 2005 at last!! So I could try you lisp. It work OK, but it
    changes the possition of the existing attribute.
    Sometimes I've changed the place of the attribute to make the drawing more
    readable. I don't want to do that again. I just want to add the value of the
    seccond attribute.
    Can you help me with that?

    Greetings Laura
     
    Laura, Nov 15, 2004
    #28
  9. Laura

    Jürg Menzi Guest

    Hi Laura

    On the fly:
    Code:
    (defun C:Test ( / AcaDoc AttLst AttObj BlkNme CurEnt InsPnt OldObj TmpEnt
    TmpObj TmpSet)
    (vl-load-com)
    (if (setq CurEnt (car (entsel "\nSelect block to modify: ")))
    (progn
    (setq OldObj (vlax-ename->vla-object CurEnt)
    AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    BlkNme (vla-get-Name OldObj)
    )
    (if (setq TmpSet (ssget "X" (list (cons 0 "INSERT") (cons 2 BlkNme))))
    (while (setq TmpEnt (ssname TmpSet 0))
    (setq TmpObj (vlax-ename->vla-object TmpEnt)
    AttLst (cons
    (cons
    TmpObj
    (mapcar
    '(lambda (Att)
    (cons
    (vla-get-TagString Att)
    (list
    (vlax-get Att 'InsertionPoint)
    (vlax-get Att 'TextAlignmentPoint)
    )
    )
    ) (vlax-invoke TmpObj 'GetAttributes)
    )
    )
    AttLst
    )
    )
    (ssdel TmpEnt TmpSet)
    )
    )
    (setq AttObj (vla-AddAttribute
    (vla-Item (vla-get-Blocks AcaDoc) BlkNme)
    0.25 ;height
    acAttributeModePreset
    "NewPrompt"
    (vlax-3d-point '(0.175 -0.225 0.0)) ;(point in blockref)
    "NewTag"
    "NewValue"
    )
    )
    ;;;   (vla-put-Layer AttObj "MyAttLayer") ;if necessary
    ;;;   (vla-put-StyleName AttObj "MyTextStyle") ;if necessary
    (command "_.ATTSYNC" "_SEL" CurEnt "_YES")
    (foreach memb AttLst
    (mapcar
    '(lambda (Att)
    (if (setq InsPnt (cdr (assoc (vla-get-TagString Att) (cdr memb))))
    (progn
    (vlax-put Att 'InsertionPoint (car InsPnt))
    (vlax-put Att 'TextAlignmentPoint (cadr InsPnt))
    )
    )
    ) (vlax-invoke (car memb) 'GetAttributes)
    )
    (vla-Update (car memb))
    )
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Nov 15, 2004
    #29
  10. Laura

    Laura Guest

    Oh yes! That works.

    You're great ! Thanks!

    Laura
     
    Laura, Nov 18, 2004
    #30
  11. Laura

    Jürg Menzi Guest

    Hi Laura

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Nov 18, 2004
    #31
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.