乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 30|回复: 16

[编程交流] Un-dynamic a block - LISP

[复制链接]

7

主题

26

帖子

19

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:02:33 | 显示全部楼层 |阅读模式
Hello all,
 
I should get the following code changed so that you can select the blocks you want to 'undynamic" first.
 
Can somebody help me?
 
  1. (defun c:UnDynamic   (   /       _get_item       _right       _make_key       _dynamic->static_block       _get_locked       _get_dynamic_inserts       _main   )   (defun _get_item ( collection key / item )       (vl-catch-all-apply          '(lambda ( ) (setq item (vla-item collection key)))       )       item   )   (defun _right ( str n / len )       (if (< n (setq len (strlen str)))           (substr str (1+ (- len n)))           str       )   )   (defun _make_key ( collection prefix len / key )       (   (lambda ( i pad )               (while                   (_get_item collection                       (setq key                           (strcat prefix                               (_right                                   (strcat pad (itoa (setq i (1+ i))))                                   len                               )                           )                       )                   )               )               key           )           0           (   (lambda ( pad )                   (while (< (strlen pad) len)                       (setq pad (strcat "0" pad))                   )                   pad               )               ""           )       )   )   (defun _dynamic->static_block ( blocks insert len )       (vla-ConvertToStaticBlock           insert           (_make_key blocks (strcat (vla-get-EffectiveName insert) "_00") len)       )   )   (defun _get_locked ( layers / locked )       (vlax-for layer layers           (if (eq :vlax-true (vla-get-lock layer))               (setq locked (cons layer locked))           )       )       locked   )   (defun _get_dynamic_inserts ( blocks / inserts )       (vlax-for block blocks           (vlax-for object block               (if (eq "AcDbBlockReference" (vla-get-objectname object))                   (if (eq :vlax-true (vla-get-isdynamicblock object))                       (setq inserts (cons object inserts))                   )               )           )       )       inserts   )   (defun _main ( document / blocks inserts locked len )       (if           (setq inserts               (_get_dynamic_inserts                   (setq blocks (vla-get-blocks document))               )           )           (progn               (foreach layer (setq locked (_get_locked (vla-get-layers document)))                   (vla-put-lock layer :vlax-false)               )               (setq len (strlen (itoa (length inserts))))               (foreach insert inserts                   (_dynamic->static_block blocks insert len)               )               (foreach layer locked                   (vla-put-lock layer :vlax-true)               )           )       )       (princ)   )   (_main (vla-get-activedocument (vlax-get-acad-object))))
 
Credits to TP from theswamp.org.
 
Thanks,
Martin.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:08:09 | 显示全部楼层
Not so pretty as his, but gets the job done:
  1. (defun C:test ( / ErrCatcher SS i o )(defun ErrCatcher ( func varLst / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply func varLst)))) rtn))(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)))))))                        (ErrCatcher 'vla-ConvertToStaticBlock (list o (vla-get-EffectiveName o)))                )        ))(princ));| defun |; (or (vlax-get-acad-object) (vl-load-com)) (princ)
回复

使用道具 举报

7

主题

26

帖子

19

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:12:50 | 显示全部楼层
Thanks, it's this kind of thing I want to do.
The only problem is that the name get's changed and you can't edit you static block anymore.
回复

使用道具 举报

7

主题

26

帖子

19

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:13:56 | 显示全部楼层
So what I'm trying to say is that the code in the 1st post should be used.
Only thing that should be added in the code is that you select the items you want to undynamic instead of all the blocks.
 
Thanks,
Martin
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:21:12 | 显示全部楼层
@Grrr:
IMO this:
  1. (or (vlax-get-acad-object) (vl-load-com))
Should be:
  1. (or vlax-get-acad-object (vl-load-com))
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:21:22 | 显示全部楼层
 
Hi Roy,
Yes it seems that it makes more sence:
  1. _$ vlax-get-acad-object#_$ (vlax-get-acad-object)#_$
Thanks!
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:27:05 | 显示全部楼层
It is not about 'more sense'. I expect that (vlax-get-acad-object) will fail if the VL extensions have not been loaded. I am using the word 'expect' because I am using BricsCAD where (vl-load-com) is a dummy function and VL functions are available by default.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:31:27 | 显示全部楼层
Yes, I mean that I haven't noticed that instead of checking for such function, I'm instead running it with the possibility of triggering an error, such as:
  1. _$ (defun C:test () (strcat 1))C:TEST_$ C:test#_$ (C:test)_$ (C:test)Error: bad argument type: stringp 1_1$
You have sharp eye.
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:34:41 | 显示全部楼层
Testing the (vla-ConvertToStaticBlock) function I have noticed something strange (note: as previously mentioned I use BricsCAD).
My test:
1. Insert the same dynamic block twice.
2. Make identical changes to one or more dynamic  properties for each insert.
3. The inserts now look the same but reference different anonymous definitions.
4. Copy one of the inserts.
5. The copy references the same anonymous definition as its original.
6. Only convert the copy to a static block.
7. Result: The original of the copy has also become a static block (probably due to what was mentioned under #5).
 
If AutoCAD has the same behavior, converting only selected inserts to static blocks would require a more complex solution than the code posted in this thread.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:37:52 | 显示全部楼层
 
This differs in AutoCAD: inserting two references of the same dynamic block and modifying their dynamic parameters to use the same values results in the two blocks referencing the same anonymous definition.
 
 
AutoCAD has the same behaviour (as to be expected, based on the above observation).
 
 
This is not the case in AutoCAD: converting one of the dynamic block references has no effect on the others.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 10:07 , Processed in 0.567590 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表