明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1038|回复: 2

按块名过滤

[复制链接]
发表于 2023-4-16 00:01:34 | 显示全部楼层 |阅读模式
本帖最后由 KO你 于 2023-4-16 00:22 编辑

原帖  http://bbs.mjtd.com/forum.php?mo ... hlight=%B9%FD%C2%CB
原帖 http://bbs.mjtd.com/forum.php?mo ... hlight=%B9%FD%C2%CB

请路过的高手修改成支持(动态块、无名块、普通块)通用点,造福大家使用


原码以下
快捷键  fg  按块名过滤
(defun c:fg(/ block_name filtn ssf ent name_lst)
(princ "\n可多选取过滤---支持动态块、无名块、普通块")
(if (and
(setq ss (ssget '((0 . "INSERT"))))               
(setq ss_lst
(vl-remove-if-not
'(lambda(x)
(if(and
(setq obj (vlax-ename->vla-object x))
(= (vla-get-objectname obj) "AcDbBlockReference")
(= (vla-get-isdynamicblock obj) :vlax-true))T nil))
(ss-enlst ss))))
(progn
(foreach x ss_lst (redraw x 3))
(setq name_lst
(mapcar
'(lambda(ename)
(princ"\n请框选对象范围<按空格或右键全选>:")
(if (vlax-property-available-p (setq obj(vlax-ename->vla-object ename)) 'effectivename)
(setq block_name (vla-get-effectivename obj))
(setq block_name (vla-get-name obj))))ss_lst))
(setq name_lst (LM:lst->str (LST-ONLY name_lst) ","))
(if name_lst
(progn
(Princ name_lst)
(setq filtn (list '(0 . "INSERT") (cons 2 (getublkname name_lst))))                        
(if (setq ssf (ssget filtn))
(princ)
(setq ssf (ssget "x" filtn)))
(if ssf
(progn
(foreach x ss_lst (redraw x 4))
(princ (sslength ssf))
(sssetfirst ssf ssf))))))
(princ "\n错误提示----请按提示选择块"))
(princ))
;; List to String  -  Lee Mac
;; Concatenates each string in a supplied list, separated by a given delimiter
;; lst - [lst] List of strings to concatenate
;; del - [str] Delimiter string to separate each item
;(LM:lst->str '("1" "2" "3" "4" "5") ",")
;"1,2,3,4,5"
(defun LM:lst->str ( lst del / str )
(setq str (car lst))
(foreach itm (cdr lst) (setq str (strcat str del itm)))str)
;;表元素唯一
(defun LST-ONLY(Lst / temp)        
(setq temp '())
(foreach x Lst
(if (not(member x temp))                        
(setq temp(cons x temp))))
(setq temp (reverse temp)))
;选择集与对象名表互转
(defun ss-enlst(ss / enlst)
(cond
((= (type ss) 'PICKSET)
(vl-remove-if-not '(lambda (x) (= (type x) 'ENAME)) (mapcar 'cadr (ssnamex SS))))
((= (type ss) 'LIST)
(setq enlst (ssadd))
(last (mapcar '(lambda (x) (ssadd x enlst)) ss)))))
(defun Getublksset (/ acadobj doc ass ssetobj gpcode datavalue)
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(vl-Catch-All-Apply
'(lambda ()
(vla-delete (vla-item (vla-get-SelectionSets doc) "*UBSET*"))))
(setq ssetObj (vla-Add (vla-get-SelectionSets doc) "*UBSET*"))
(setq gpCode (vlax-make-safearray vlax-vbInteger '(0 . 0)))
(vlax-safearray-put-element gpCode 0 2)
(setq dataValue (vlax-make-safearray vlax-vbVariant '(0 . 0)))
(vlax-safearray-put-element dataValue 0 "`*U*")
(vla-Select ssetObj acSelectionSetAll nil nil gpCode dataValue)ssetObj)
(defun Getublkname (name / namejoin)
(setq namejoin "")
(vlax-for obj(getublksset)
(if (and
(wcmatch (strcase (vla-get-effectivename obj))
(strcase name)))
(setq namejoin (strcat ",`" (vla-get-name obj) namejoin))))
(strcat name namejoin))
(defun SSgetdynblk (name mode / names filtn)
(setq filtn (getublkname name))
(if (wcmatch (strcase mode t) "x,a,:e,:s,:e:s,:s:e,l,p")
(ssget mode (list '(0 . "insert") (cons 2 filtn)))               
(ssget (list '(0 . "insert") (cons 2 filtn)))))
(prin1)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2023-4-16 11:55:46 | 显示全部楼层
谢谢楼主分享
发表于 2023-4-17 09:10:48 | 显示全部楼层
謝謝樓主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 07:17 , Processed in 0.148201 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表