明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 177|回复: 2

[讨论] 这个代码,能选中图形了,却不能过滤,在哪出错

[复制链接]
发表于 3 天前 | 显示全部楼层 |阅读模式
请教各位大佬,我的这个代码,能选中图形了,却不能过滤,在哪出错。也就是选到了所有图形,却不过滤。运行语句:(ssget-doc  "x"  '((0 . "CIRCLE,LINE")))

  • (defun ssget-doc ( seltype  filst / filster listtosafearray lst made-filterlst pl pnts sset ssetobj target-doc)
  •   (defun ListToSafearray (symVariableType lstValues / safValues)
  • (setq safValues (vlax-make-safearray symVariableType
  •                   (cons 0 (1- (length lstValues)))))
  • (vlax-safearray-fill safValues lstValues)
  • ; safValues
  • )
  •   ;把形如ssget里的过滤表转换成vla的数组
  •   (defun made-filterlst(filst / filter_code filter_codelist filter_value filter_valuelist)
  •     (setq filter_codelist  (mapcar '(lambda (x) (car x)) filst)
  •         filter_valuelist (mapcar '(lambda (x) (cdr x)) filst)
  •         filter_code  (ListtoSafearray 2 filter_codelist)
  •         filter_value (ListtoSafearray 12 filter_valuelist))
  •     (list filter_code  filter_value)
  •   )
  •   ;;  将 "另一个文档的文件名" 替换为实际文件名
  •   (setq target-doc (vla-get-ActiveDocument (vlax-get-acad-object) ))
  •   ;; 获取目标文档的 SelectionSets 集合
  •   (setq sset (vla-get-selectionsets target-doc))
  • (if (vl-catch-all-error-p
  •        (vl-catch-all-apply '(lambda(x) (setq ssetObj (vlax-invoke-method x 'add "TEST_SSET4")) )(list sset)))
  •        (progn (vla-clear (vla-item sset "TEST_SSET4"))
  •            (setq ssetObj (vla-item sset "TEST_SSET4"))
  •          )
  •   )
  •   ;; 设置过滤条件
  •   (setq filster (made-filterlst  filst))
  •   (vlax-invoke-method ssetobj 'Select
  •     (cond
  •   ((= seltype "p")acSelectionSetPrevious)  
  •   ((= seltype "l")acSelectionSetLast )
  •   ((= seltype "x")acSelectionSetAll )        
  •                      )
  •   (car filster)(cadr filster))
  • (princ (vla-get-Count ssetObj ))
  •   (vla-Delete ssetObj)
  •   )


发表于 3 天前 | 显示全部楼层
本帖最后由 kozmosovia 于 2024-9-20 09:45 编辑

(vlax-safearray-fill safValues lstValues)返回值是safearray或者nil,不是variant,需要再make-variant一下
发表于 3 天前 | 显示全部楼层
(ssget"x"'((0 . "CIRCLE,LINE")))多简单
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-23 04:32 , Processed in 0.680623 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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