BlockReplace vs Attribute Position

Dear All,

How to replace and synchronize a block whose attribute position has been moved. The Lock Position property is set to Yes.

The goal is to replace an original block (Block_OLD) with a new block (Block_NEW) so that the attribute is moved to the position shown on Block_NEW.

Attached is a drawing with an example of two blocks (Block_OLD and Block_NEW).

When using the BlockReplace command to replace Block_OLD with Block_NEW, the ATT1 attribute is not repositioned as it is on Block_NEW.

How can this problem be resolved? Thank you for your help

Comments

  • This may help

    ; https://forum.bricsys.com/discussion/40581/blockreplace-vs-attribute-position#latest

    ; Replace block by AlanH OCT 2026

    (defun c:roldnewb ( / ss x attreqold blk blkn newb connold objnew)
    (setq atreqold (getvar "attreq"))
    (setvar "attreq" 0)
    (setq cannold (getvar "cannoscale"))
    (setvar 'cannoscale "1:1")

    (setq blkn (vlax-get (vlax-ename->vla-object (car (entsel "\nPick old block "))) 'name))
    (setq newb (getstring "\nEnter new block name " T))

    (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 blkn))))
    (repeat (setq x (sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
    (setq scx (vlax-get blk 'XScaleFactor))
    (setq scy (vlax-get blk 'YScaleFactor))
    (setq rot (vlax-get blk 'Rotation))
    (setq xy (vlax-get blk 'insertionpoint))
    (if (vlax-property-available-p blk "hasattributes")
    (setq atts (vlax-invoke blk 'Getattributes))
    )
    (command "-insert" newb xy scx scy rot)
    (setq objnew (vlax-ename->vla-object (entlast)))
    (if (vlax-property-available-p objnew "hasattributes")
    (progn
    (setq atts2 (vlax-invoke objnew 'Getattributes))
    (setq K 0)
    (foreach att atts2
    (vlax-put att 'textstring (vlax-get (nth k atts) 'textstring))
    (setq k (1+ k))
    )
    )
    )
    (vla-delete blk)
    )
    (alert "No block objects found")
    )

    (setvar 'cannoscale cannold)
    (setvar 'attreq attreqold)
    (princ)
    )
    (c:roldnewb)

  • attsync command?