Roy_043 发表于 2022-7-5 17:40:12

@Lee: Thanks for your comments. I'll send a Support Request to the Bricsys team.

Lee Mac 发表于 2022-7-5 17:46:34

You're welcome Roy.

Grrr 发表于 2022-7-5 17:48:51

I've followed the steps Roy mentioned on my Acad 2015, and can comfirm this:
Seems that it adds new block definition, under the provided name:

(vla-ConvertToStaticBlock o "ABC")
But, when I try to convert other block reference under the same / existing block definition name, I get:

_$ (vla-ConvertToStaticBlock o "ABC")Error: Automation Error. Duplicate key_1$
But/And It creates an annonymous block definition anyway:

_$ (vla-get-EffectiveName (vlax-ename->vla-object (car (entsel))))"*U117"_$

Note that the "Name" property row in the quick properties dialog, always references to the block's "effective name / definition name".
 
So thats why my previously posted code forces the creation of N annonymous block definitions:

(ErrCatcher 'vla-ConvertToStaticBlock (list o (vla-get-EffectiveName o)))
Since this always triggers an error

Lee Mac 发表于 2022-7-5 17:51:45

 
Of course: the block name argument for the ActiveX converttostaticblock method cannot correspond to an existing block, otherwise you will receive a duplicate key error - this is why the original code included the '_make_key' function.

DesmetMartin 发表于 2022-7-5 17:57:15

First of all, thanks for all the help so far!
I would like to think together with you guys, but since I can't program, it's though
 
Let me know if you find a solution please!
Thanks!
- Martin

Grrr 发表于 2022-7-5 18:00:42

 
Try this:

(defun C:test ( / ErrCatcher BlksColl SS i o cnt flg nm ); (ErrCatcher 'vla-item (list (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "BlockThatDoesNotExist")) -> nil(defun ErrCatcher ( func varLst / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply func varLst)))) rtn))(setq BlksColl (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))(prompt "\nSelect blocks to convert them into static ones:" )(if (setq SS (ssget "_:L" (list (cons 0 "INSERT"))))        (repeat (setq i (sslength SS))                (if (eq :vlax-true (vla-get-IsDynamicBlock (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i)))))))                        (progn                                (setq cnt 0) (setq flg 'T)                                (while flg                                        (if (not (ErrCatcher 'vla-item (list BlksColl (setq nm (strcat (vla-get-EffectiveName o) "_" (itoa (setq cnt (1+ cnt))))))))                                                (progn (vla-ConvertToStaticBlock o nm) (setq flg nil))                                        ); if                                ); while                        ); progn                ); if        ); repeat); if(princ));| defun |; (or vlax-get-acad-object (vl-load-com)) (princ)
Note that the original dynamic blocks are not purged.

DesmetMartin 发表于 2022-7-5 18:04:40

 
Super! This is what I was looking for!
Thank you so much!
-Martin
页: 1 [2]
查看完整版本: Un-dynamic a block - LISP