feargt 发表于 2022-7-5 19:40:03

修改外部参照列表

你好
 
 
我有一个外部参照列表
 
 
Xref\u 1 Xref\u 2 Xref\u 3\u ELC Xref\u 4\u ELC Xref\u。。。。。。。。
 
 
我想修改列表,使其只包含末尾有ELC的项目。
 
 
如果我只能将外部参照添加到列表的末尾带有ELC,那就更好了。
 
 
以下两种尝试均未成功。
 
 
有什么想法吗?
 
 
 
 



(defun c:findxref (/ td xrf)
(setq XrfM nil)
(while (setq td (tblnext "BLOCK" (not td)))
(and (= (logand (cdr (assoc 70 td)) 4) 4)
(setq xrf (cons (strcase (cdr (assoc 2 td))) xrf))
   )
)
(print xrf)


;attempt with Vl-remove
(foreach n xrf
(if (/= (wcmatch n "*_ELC")T) (vlremove n xrf)))




;Create new list
(foreach n xrf
(if (= (wcmatch n "*_ELC")T) (append n xrfm)))


(print Xrf)
(print Xrfm)
(princ)
)

 
 
 
 
谢谢

Tharwat 发表于 2022-7-5 19:46:32

这里只是一个提示。
 

(if (wcmatch n "*_ELC")
(setq lst (append lst (list n)))
)

feargt 发表于 2022-7-5 19:47:39

谢谢你的提示,但是
这对我来说是不可能的,我从你的暗示中错过了什么?
 
 
 
 
Xrfm不断返回零
 
 
 
 
 
 

(defun c:findxref (/ td xrf XrfM)
(setq XrfM '())
(while (setq td (tblnext "BLOCK" (not td)))
(and (= (logand (cdr (assoc 70 td)) 4) 4)
(setq xrf (cons (strcase (cdr (assoc 2 td))) xrf))
   )
)
(print xrf)

(foreach n xrf
(if (wcmatch n "*_ELC")   
      (setq XrfM (appendn Xrfm))
   
      )
)

(print Xrfm)
(princ)
)

Tharwat 发表于 2022-7-5 19:50:44

很抱歉,我忘记为append函数添加list函数来处理列表。
 
因此,只需为n变量添加list函数,就可以将其附加到列表中。
 
如。
 

(foreach n xrf
   (if (wcmatch n "*_ELC")
   (setq XrfM (append Xrfm (list n)))
   )
)

Lee Mac 发表于 2022-7-5 19:54:37

我建议在初始循环中省略它们,而不是从结果列表中删除不需要的项,例如:
(defun c:findxref ( / td xrf xrn )
   (while (setq td (tblnext "block" (not td)))
       (and (= (logand (cdr (assoc 70 td)) 4) 4)
            (wcmatch (setq xrn (strcase (cdr (assoc 2 td)))) "*_ELC") ;; Must pass this criteria before being added to the list
            (setq xrf (cons xrn xrf))
       )
   )
   (print xrf)
   (princ)
)

feargt 发表于 2022-7-5 19:56:04

多亏了你们两个,两种选择都对我有效。
奥地利的问候

Tharwat 发表于 2022-7-5 19:59:28

很好,欢迎你。

Lee Mac 发表于 2022-7-5 20:04:36

非常欢迎你

feargt 发表于 2022-7-5 20:06:32

大家好,我在这里收到了一条错误消息
 
 
我试图检索列表中外部参照插入点的X值,
但它返回一个错误。如果我尝试选项2,并在位置“n”处输入外部参照名称,然后仅在命令行中输入,则它可以工作。知道我在这里遗漏了什么吗
 
 

(foreach n xrf
   
OPTION 1
(setq ss (ssget "X" '((0 . "INSERT")(67 . 0)(2 . n))))
(setq x (car (cdr (assoc 10 (entget ss)))))
      
OPTION 2
(setq x (car (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . n))) 0))))))

(print x)

Tharwat 发表于 2022-7-5 20:10:45

试试这个。
 

(setq ss (ssget "_X" (list '(0 . "INSERT")'(67 . 0)(cons 2 (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) xrf))))))
页: [1] 2
查看完整版本: 修改外部参照列表