PDA

View Full Version : How to modify lisp to convert blocks with different prefix to anonymous



Arterius
2015-10-01, 10:01 AM
Hi all,

I am using this routine below to convert my two specific blocks to anonymous block and purge, but the problem apears when I attach drawing as xref (drawing with blocks) to another drawing and bind it, than my blocks got name like: "x-plan$0$block1" and ""x-plan$0$block2".
How to modify this routine to make it find blocks with specific word in name?
Thanks in advance.


(defun c:tntblock (/ _data data fdata ss i e from info)(vl-load-com)
(setq blks (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
(defun _data (en func l1 l2 rv)
(if l2
(mapcar '(lambda (j k)
(func en j (if (and rv (/= 0 rv)
(eq j "Rotation")) (- k rv) k))) l1 l2)
(mapcar '(lambda (j)
(func en j)) l1)
)
)


(setq data '( "InsertionPoint" "Height" "TextAlignmentPoint")
Fdata '("Textstring" "color" "Rotation" "StyleName" "Alignment" "Layer"
"ScaleFactor" "UpsideDown" "Backward"
)
)
(if
(setq ss (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "BLOCK1,BLOCK2,`*U*"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq r (vla-get-rotation e))
(if (member (strcase (vla-get-effectivename e)) '("BLOCK1" "BLOCK2"))
(progn
(vlax-invoke e 'ConvertToAnonymousBlock)
(setq from (mapcar '(lambda (k)
(setq info (_data k vlax-get fdata nil nil))
(vla-delete k) info)
(vlax-invoke e 'GetAttributes)))

(vlax-for itm (setq blk (vla-item
blks
(vla-get-name e)
))
(if (eq "AcDbAttributeDefinition" (vla-get-objectname itm))
(progn
(setq fd (car from))
(setq old (_data itm vlax-get data nil nil))
(setq new (vlax-invoke blk 'AddText (car fd) (car old) (cadr old)))
(_data new vlax-put fdata fd r)
(vlax-invoke new 'Move '(0.0 0.0 0.0) (last old))
(vla-delete itm)

(setq from (cdr from))
)
)
)
)
)
)
)
(command "-Purge" "B" "BLOCK1" "N" )
(command "-Purge" "B" "BLOCK2" "N" )
(princ)
)

tedg
2015-10-01, 11:45 AM
Why don't you bind your xrefs using the "insert" option (instead of "bind")?

That way you don't get the "....$0$....." in the name, then maybe it won't be an issue?

Just a thought

Arterius
2015-10-01, 01:11 PM
Thanks tedg for replay. You are right, this is a solution, but our client require binded xrefs.... that's annoying, i know, but client is your master :)
I tested it using your way, I changed BINDTYPE variable to insert xrefs and found another problem: my two specific blocks are inside another block (inserted xref) and routine does not work.... any ideas? :)

tedg
2015-10-01, 01:40 PM
Thanks tedg for replay. You are right, this is a solution, but our client require binded xrefs.... that's annoying, i know, but client is your master :)
I tested it using your way, I changed BINDTYPE variable to insert xrefs and found another problem: my two specific blocks are inside another block (inserted xref) and routine does not work.... any ideas? :)
I tried testing your routine, I couldn't get it to work even without a bound xref with blocks "BLOCK1" and "BLOCK2", I'm not sure what it actually does, a bit over my head.
But maybe someone else who's more lisp savvy than I am can help you.

Going back to your original question, you could use wild cards to find the bound xref block names like *$0$BLOCK1" and *$0$BLOCK2
But I'm not sure how that would apply to your routine, maybe another setq?

Arterius
2015-10-01, 02:10 PM
Please test it on blocks with attributes.

tedg
2015-10-01, 03:57 PM
Please test it on blocks with attributes.

Ok got it to work, but I haven't found a way to answer your question changing the bound xref blocks "...$0$BLOCK1" (etc).

I did find that if you use "bind" "insert" on the xref, and explode the bound xref block, it will change the blocks as you want.

Arterius
2015-10-02, 07:07 AM
Hi Tedg,
yes, exploding is a solution, but it is a detour and I cannot make lisp to explode xref, because usually my xrefs got different name for different building, level or even project...
The best way is to force this routine to rename blocks in binded xref, I am sure this is possible, but it is beyond my skills :)