tjsantos 发表于 2022-7-6 10:38:48

将图形另存为多属性

大家好,
 
我正在寻找一个LISP例程,它将使用由块中的属性组成的文件名保存图形。
 
即。
块名称='标题栏'
属性1='Drg\U No'=12345
属性2=‘Drg\U Rev’=A
属性3='日期发布'=2010年2月1日
 
该例程将图形保存为“12345\u A\u 01022010”,保存在图形当前文件夹中名为“Archive”的sbu文件夹下
 
任何帮助都将不胜感激。

alanjt 发表于 2022-7-6 10:47:53

如果您已经用新信息编辑了文件,那么归档文件有什么好处?

tjsantos 发表于 2022-7-6 10:56:21

这是因为图形仅保存在图形编号下,当我们更新它时,我们使用上述方法将图形手动保存在存档文件夹中。我想自动化这个。
 
干杯

alanjt 发表于 2022-7-6 11:05:17

完全可行。有编程经验吗?

dbroada 发表于 2022-7-6 11:08:46

另外,您可能需要重新考虑yyyymmdd的日期格式。当按日期顺序查找文件时,按ddmmyyyy或mmddyyyy进行操作会得到一个非常未排序的列表。

tjsantos 发表于 2022-7-6 11:17:32

Alanjt公司
 
我用AutoCAD编程的唯一经验是“调整”其他人的lisp例程。这是我第一次努力写作。
 
dbroada公司
 
好主意,我会记住的。谢谢。

alanjt 发表于 2022-7-6 11:21:52

所以你在找人帮你写?

tjsantos 发表于 2022-7-6 11:26:05

 
最好是这样。

Phiphi 发表于 2022-7-6 11:32:48

 
类似主题:http://www.cadtutor.net/forum/showthread.php?41895-将图形另存为属性值

Lee Mac 发表于 2022-7-6 11:43:59

试试这个:
 

(defun c:dwgsave ( / path ss )
(vl-load-com)
;; © Lee Mac 2010

(cond
   (
   (not
       (or
         (findfile
         (setq path
             (strcat (getvar 'dwgprefix) "Archive")
         )
         )
         (vl-mkdir path)
       )
   )

   (princ "\n** Unable to Locate Save Path **")
   )
   ( (not (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Title Block") (66 . 1)))))

   (princ "\n** No Title Block Found **")
   )
   (t

   (
       (lambda ( string )
         (vla-saveas
         (vla-get-ActiveDocument
             (vlax-get-acad-object)
         )
         (strcat path "\\" string)
         )
       )
       (
         (lambda ( attribs )
         (LM:lst->str
             (mapcar
               (function
               (lambda ( tag / x l ) (setq x (cdr (assoc tag attribs)))
                  
                   (cond
                     ( (and x (eq "DATE_ISSUE" tag))
                        
                     (apply (function strcat)
                         (reverse
                           (setq l (LM:StringParser x "/"))
                         )
                     )
                     )
                     ( x ) ( "" )
                   )
               )
               )
               '("DRG_NO" "DRG_REV" "DATE_ISSUE")
             )
             "_"
         )
         )
         (
         (lambda ( object )
             (mapcar
               (function
               (lambda ( x )
                   (cons
                     (strcase (vla-get-TagString x)) (vla-get-TextString x)
                   )
               )
               )
               (append
               (vlax-safearray->list
                   (vlax-variant-value
                     (vla-getAttributes object)
                   )
               )
               (if
                   (not
                     (vl-catch-all-error-p
                     (setq x
                         (vl-catch-all-apply (function vlax-safearray->list)
                           (list
                           (vlax-variant-value
                               (vla-getConstantAttributes object)
                           )
                           )
                         )
                     )
                     )
                   )
                   x
               )
               )
             )
         )
         (vlax-ename->vla-object (ssname ss 0))
         )
       )
   )
   )
)
(princ)
)

;;--------------------=={ String Parser }==-------------------;;
;;                                                            ;;
;;Separates a string into a list of strings using a         ;;
;;specified delimiter string                              ;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;str - string to process                                 ;;
;;del - delimiter by which to separate the string         ;;
;;------------------------------------------------------------;;
;;Returns:A list of strings                               ;;
;;------------------------------------------------------------;;

(defun LM:StringParser ( str del )
;; © Lee Mac 2010
(if (setq pos (vl-string-search del str))
   (vl-remove ""
   (cons (substr str 1 pos)
       (LM:StringParser
         (substr str (+ pos 1 (strlen del))) del
       )
   )
   )
   (list str)
)
)

;;-------------------=={ List to String }==-------------------;;
;;                                                            ;;
;;Constructs a string from a list of strings separating   ;;
;;each element by a specified delimiter                     ;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;lst - a list of strings to process                        ;;
;;del - delimiter by which to separate each list element    ;;
;;------------------------------------------------------------;;
;;Returns:String containing each string in the list       ;;
;;------------------------------------------------------------;;

(defun LM:lst->str ( lst del )
;; © Lee Mac 2010
(if (cdr lst)
   (strcat (car lst) del (LM:lst->str (cdr lst) del))
   (car lst)
)
)

   
页: [1]
查看完整版本: 将图形另存为多属性