So I have a library full of exported blocks (wblock)
Now I wanted to add an attribute to those blocks with the part name so I can use eattext. (since we use 2d blocks and they have multiple views I couldn't use the block names)
And since I am not working in a block but a dwg file of and exported block. I couldn't use any standard attribute lisps. I can't even use attedit since that asks for a block too.
So while I was making this post I figured it out by myself so here is the code:
To add an attribute to the center of a drawing or a block if your in the block editor:
(command "-Attdef" "I" "P" "L" "" "partnr" "enter part number" "partnr" "style" "style1" (getvar "viewctr") "0")
to delete the old attribute ( I modified a block delete routine:
(defun C:delblk3 (blk / SS FILTER SSLEN ENT)
(progn
(setq FILTER (list (cons 0 "ATTDEF")
(cons 2 blk)
)
SS (ssget "_X" FILTER)
)
(if SS
(progn
(vl-load-com)
(repeat (setq SSLEN (sslength SS))
(vlax-invoke-method (vlax-ename->vla-object (ssname ss (setq SSLEN (1- SSLEN)))) 'Delete)
)
)
)
)
)
(c:delblk3 "partnr") ;; call it with this line.
Sharing it because 90% is from here anyway, I hope someone finds it helpfull