这个代码,能选中图形了,却不能过滤,在哪出错
请教各位大佬,我的这个代码,能选中图形了,却不能过滤,在哪出错。也就是选到了所有图形,却不过滤。运行语句:(ssget-doc"x"'((0 . "CIRCLE,LINE")))[*](defun ssget-doc ( seltypefilst / 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_codefilter_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-filterlstfilst))
[*](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)
[*])
本帖最后由 kozmosovia 于 2024-9-20 09:45 编辑
(vlax-safearray-fill safValues lstValues)返回值是safearray或者nil,不是variant,需要再make-variant一下 (ssget"x"'((0 . "CIRCLE,LINE")))多简单 你发的这个格式的代码,别人想复制下了运行都不行。
页:
[1]