Halb10 发表于 2022-7-5 15:34:54

使用属性库另存为目录

你好
 
有没有办法使用属性值将我的图形及其名称保存在目录中。
 
例子:
 
图纸名称:测试。图纸
区块名称:标题栏
属性:SF:WE
属性值:test2
 
它应该将图形保存在:
 
C: 绘图/测试绘图/(属性值)/。。。
 
但它应该在对话框中,这样我可以选择特定的子文件夹
 
属性值之前的direcotry是fix。

Halb10 发表于 2022-7-5 15:48:49

(defun c:FOO (/ LM:GetAttributeValue ss attValue)

(setvar "filedia" 0)

(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 "X" '((0 . "INSERT") (2 . "TitleBlock") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "SF:WE"))
   )
   (command "_saveas" "_2007" (getfiled "Speichern" (strcat "C:\\drawing\\test drawing\\(*****)" (vl-filename-base (getvar "dwgname"))) "dwg" 1)
   )

   ;(prompt (strcat "\n : " attValue))
)
(princ)
(setvar "filedia" 1)
)
 
有这个密码。但我不能让它工作。(****)应该有attValue。

rlx 发表于 2022-7-5 16:07:21

首先,我将把getfield放在命令函数之外,因为所有的错误检查都必须在运行它之前完成。其次,你确定这个文件夹一直存在吗?此外,您还需要在(****)和(vl filename base(getvar“dwgname”)之间加上一个“\\”,并在同一表达式的末尾加上一个。
 
(getfiled "testje" "d:\\temp\\lisp" "dwg" 0) 与
(getfiled "testje" "d:\\temp\\lisp\\" "dwg" 0) (末尾有\\
 
gr.Rlx

Halb10 发表于 2022-7-5 16:13:08

好的,像这样
 

(command "_saveas" "2007")
(getfiled "Speichern" (strcat C:\\drawing\\test drawing\\(attValue)\\" (vl-filename-base (getvar "dwgname"))) "dwg" 0)

 
是的,文件夹存在。
这种代码可以做到这一点吗?因为我不知道如何获取目录中的属性值。

rlx 发表于 2022-7-5 16:26:47

未经测试:
 
 

(defun c:FOO (/ LM:GetAttributeValue ss attValue fol fn)
(vl-load-com)(setvar "filedia" 0)

(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 "X" '((0 . "INSERT") (2 . "TitleBlock") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "SF:WE"))
   (vl-file-directory-p (setq fol (strcat "C:\\drawing\\test drawing\\" attValue)))
   (setq fn (getfiled "Speichern" (strcat fol "\\" (vl-filename-base (getvar "dwgname"))) "dwg" 1))
   )
   (command "_saveas" "_2007" fn)
)
(setvar "filedia" 1)
(princ)
)

Halb10 发表于 2022-7-5 16:45:37

这很好。这正是我需要的。
 
谢谢你rlx
页: [1]
查看完整版本: 使用属性库另存为目录