russ079 发表于 2022-7-5 15:37:30

需要wblock lisp的帮助

你好
 
我以前没有写过任何lisps,现在已经读了大约2周了,正在看代码等等。我设法拼凑了一个Lisp程序,它可以作为两个一半,但我不能让它一起工作。
 
我画了很多零件,旁边有一个叫做“head”的块,还有一个“PCE\u NAM”的标签。每个零件的值不同。
 
我想选择一个part&block窗口,然后wblock到一个新文件,该文件的名称来自标记。然后自动循环再做一次。
 
这是我拼凑起来的花了我一个多星期的时间哈哈。
 
(defun c:nest ( / file sel1 LM:GetAttributeValue ss attValue name)
(setq p1 (getpoint "\nFirst Corner: "))
(setq p2 (getcorner p1 "\nSecond Corner: "))
(setq sel1 (ssget "_W" p1 p2 ))
(vl-load-com)
(defun LM:GetAttributeValue (blk tag / val enx)
   (while
   (and
       (null val)
       (= "ATTRIB"
          (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
       )
   )
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
      (setq val (cdr (assoc 1 enx)))
      )
   )
)

(if (and (setq ss (ssget "_W" p1 p2 '((0 . "INSERT") (2 . "Head") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "PCE_NAM"))
   )
   (prompt (strcat "\n : " attValue))
)
(command "FILEDIA" "0")
(COMMAND "-WBLOCK" (strcat "C:\\autocad\\" attvalue "Y" "" "0,0" sel1 ""))
(command "oops" )
(prompt "\nWBlocking complete.")
(princ)
);defun
 
我得到第一个工作位进行选择,它告诉我标签值。
我也可以将所选内容wblock到文件中,但我无法将标记值作为文件名来获取wblock。
 
如果有任何正确方向的帮助和指针,我们将不胜感激。
P12.dwg
我附上了一个示例文件。
 
谢谢
俄罗斯

russ079 发表于 2022-7-5 15:49:37

抱歉,我刚刚意识到我没有包装我的代码,找不到编辑按钮

russ079 发表于 2022-7-5 16:02:39

(defun c:nest ( / file sel1 LM:GetAttributeValue ss attValue name)
(setq p1 (getpoint "\nFirst Corner: "))
(setq p2 (getcorner p1 "\nSecond Corner: "))
(setq sel1 (ssget "_W" p1 p2 ))
(vl-load-com)
(defun LM:GetAttributeValue (blk tag / val enx)
   (while
   (and
       (null val)
       (= "ATTRIB"
          (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
       )
   )
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
      (setq val (cdr (assoc 1 enx)))
      )
   )
)

(if (and (setq ss (ssget "_W" p1 p2 '((0 . "INSERT") (2 . "Head") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "PCE_NAM"))
   )
   (prompt (strcat "\n : " attValue))
)
(command "FILEDIA" "0")
(COMMAND "-WBLOCK" (strcat "C:\\autocad\\" attvalue "Y" "" "0,0" sel1 ""))
(command "oops" )
(prompt "\nWBlocking complete.")
(princ)
);defun

ronjonp 发表于 2022-7-5 16:24:21

尝试将wblock命令调用更改为:
(command "-WBLOCK" (strcat "C:\\autocad\\" attvalue) "Y" "" '(0. 0. 0.) (ssname ss 0) "")

russ079 发表于 2022-7-5 16:29:50

谢谢
 
现在它开始工作了。
 
干杯

ronjonp 发表于 2022-7-5 16:41:03

 
很乐意帮忙
页: [1]
查看完整版本: 需要wblock lisp的帮助