乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 6

[编程交流] 使用将dwg保存在子文件夹中

[复制链接]

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:15:17 | 显示全部楼层 |阅读模式
你好
我正在使用我找到的一个非常有用的lisp代码(稍加修改),它用日期和时间戳保存dwg文件。
有人能帮我把日期和时间显示在文件名之前吗?
例如,我希望文件读取“test 09-09-16\u 12.22'28.dwg”,而不是“09-09-16\u 12.22'28”test.dwg”
 
更重要的是,每个文件是否可以保存在自动创建的子文件夹中,该子文件夹与文件同名?因此,如果文件名为“test.dwg”,则会自动创建一个子文件夹,并将其命名为“test”,而无需用户进行任何输入,其中包含所有保存的文件。
提前谢谢你。
 
这是我正在使用的代码:
 
  1. ;; TED KRUSH 9/23/02
  2. ;;; Routine that was created @ Southern Maine Technical College.
  3. ;;; Saves Drawing an eariler version and then resaves as
  4. ;;; orginal version to maitain defualt save.
  5. ;; UPDATED 02/02/03 Added Date Sub-Routine
  6. ;; UPDATED 03/11/05 Revise version save 2002/R14 to 2004/2000 per upgrade to Autocad 2005 version
  7. ;; UPDATED 04/05/06 Adde StrPath Sub-Rountine, so as new file can be saved to folder.
  8. ;;;; *** Now We go to to Commerical Break for the Typical Legal Mumbo Jumbo ***
  9. ;;;; Permission to use, copy, modify, and distribute this software
  10. ;;;; for any purpose and without fee is hereby granted.
  11. ;;;;
  12. ;;;; I PROVIDE THIS PROGRAM "AS IS" AND WITH ALL FAULTS. I SPECIFICALLY DISCLAIM ANY
  13. ;;;; IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. I DO NOT
  14. ;;;; WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
  15. (defun c:scon ()
  16. ;;Error Trap utilizing the TedError Function
  17. (command ".undo" "m")
  18. (setq old_error *error*)
  19. (setq *error* tederror)
  20. ;;Start of Date defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. (defun TODAY (/ d yr mo day hr m s) ;define the function and declare all variabled local
  22. (setq d (rtos (getvar "CDATE") 2 6)
  23. ;get the date and time and convert to text
  24. yr (substr d 3 2) ;extract the year
  25. mo (substr d 5 2) ;extract the month
  26. day (substr d 7 2) ;extract the day
  27. hr (substr d 10 2) ;extract the hour
  28. m (substr d 12 2) ;extract the minute
  29. s (substr d 14 2) ;extract the second
  30. )
  31. (setq dates (strcat mo "-" day "-" yr "_" hr "." m "'" s"'' ")) ;string 'em together
  32. (princ)
  33. )
  34. ;;End of Date defun
  35. ;;Start of StrPath defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. (defun StrPath ()
  37. (setq OldName (getvar "dwgname"))
  38. ;; Extracts the Drawing File Name
  39. (setq OldPath (getvar "dwgprefix"))
  40. ;; Extracts the Drawing Location
  41. (setq NewPath (vl-string-subst
  42. "\\Transfer-Outgoing\"
  43. "\\Drawings\"
  44. OldPath
  45. )
  46. )
  47. (setq OldFile (strcat OldPath OldName))
  48. ; Text String for Old File
  49. (setq NewFile (strcat NewPath dates Oldname))
  50. ; Text String for New File
  51. (princ)
  52. )
  53. ;;End of StrPath defun
  54. ;; Main Rountine
  55. (today)
  56. (StrPath)
  57. (vl-mkdir NewPath)
  58. (setvar "expert" 4)
  59. (command "saveas" "2004" NewFile) ;New file with date Prefix
  60. (command "saveas" "2004" OldFile) ;Saves back to the Orginal File.
  61. (setvar "expert" 0)
  62. (setq *error* old_error)
  63. (princ)
  64. )
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-5 17:32:45 | 显示全部楼层
请阅读代码发布指南并编辑您的帖子,将代码包含在代码标签中。[NOPARSE]
  1. Your Code Here
[/NOPARSE]=
  1. Your Code Here
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:37:17 | 显示全部楼层
我正在努力,通过反复试验,我找到了创建与dwg文件同名的空子文件夹的代码。如果有人能合并它
对于代码的其余部分,我将不胜感激,因为我完全不懂这一点。
 
  1. (vl-mkdir (vl-filename-base (getvar "dwgname")))
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:53:25 | 显示全部楼层
  1. (defun c:scon ( / path oldExpert time)
  2. (if (zerop (getvar 'dwgtitled))
  3.    (princ "\nError: save drawing first ")
  4.    (progn
  5.      (setq oldExpert (getvar 'expert))
  6.      (setvar 'expert 4)
  7.      (command "_.saveas" "_2004" "") ; Save original file.
  8.      (setvar 'expert oldExpert)
  9.      (setq time (vl-file-systime (strcat (getvar 'dwgprefix) (getvar 'dwgname))))
  10.      (setq path
  11.        (strcat
  12.          (vl-string-subst "\\Transfer-Outgoing\" "\\Drawings\" (getvar 'dwgprefix))
  13.          (vl-filename-base (getvar 'dwgname))
  14.          "\"
  15.        )
  16.      )
  17.      (vl-mkdir path)
  18.      (setq path ; Add drawing name to path.
  19.        (strcat
  20.          path ; Ending in "\".
  21.          (vl-filename-base (getvar 'dwgname))
  22.          " "
  23.          (strcat (if (> 10 (nth 1 time)) "0" "") (itoa (nth 1 time))) ; Month.
  24.          "-"
  25.          (strcat (if (> 10 (nth 3 time)) "0" "") (itoa (nth 3 time))) ; Day of the month.
  26.          "-"
  27.          (substr (itoa (nth 0 time)) 3) ; Year.
  28.          "_"
  29.          (strcat (if (> 10 (nth 4 time)) "0" "") (itoa (nth 4 time))) ; Hour.
  30.          "."
  31.          (strcat (if (> 10 (nth 5 time)) "0" "") (itoa (nth 5 time))) ; Minute.
  32.          "'"
  33.          (strcat (if (> 10 (nth 6 time)) "0" "") (itoa (nth 6 time))) ; Second.
  34.          "''"
  35.          ".dwg"
  36.        )
  37.      )
  38.      (vl-file-delete path) ; Just in case...
  39.      (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) path)
  40.    )
  41. )
  42. )
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:02:49 | 显示全部楼层
罗伊,我真的很感谢你的帮助!我尝试了您的代码,但它没有将任何内容保存到创建的文件夹中,并返回错误:“命令:;错误:错误的参数类型:consp nil”。
有什么想法吗?不过,谢谢你的努力和时间。
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 18:08:37 | 显示全部楼层
显然,在AutoCAD中,(vl文件系统)存在问题。BricsCAD没有这个问题。
 
试试这个:
  1. (defun c:scon ( / path oldExpert time)
  2. (if (zerop (getvar 'dwgtitled))
  3.    (princ "\nError: save drawing first ")
  4.    (progn
  5.      (setq oldExpert (getvar 'expert))
  6.      (setvar 'expert 4)
  7.      (command "_.saveas" "_2004" "") ; Save original file.
  8.      (setvar 'expert oldExpert)
  9.      (setq time (getvar 'tdupdate))
  10.      (setq path
  11.        (strcat
  12.          (vl-string-subst "\\Transfer-Outgoing\" "\\Drawings\" (getvar 'dwgprefix))
  13.          (vl-filename-base (getvar 'dwgname))
  14.          "\"
  15.        )
  16.      )
  17.      (vl-mkdir path)
  18.      (setq path ; Add drawing name to path.
  19.        (strcat
  20.          path ; Ending in "\".
  21.          (vl-filename-base (getvar 'dwgname))
  22.          (menucmd (strcat "m=$(EDTIME," (rtos time 2  ", mo-dd-yy_hh.mm'ss'')"))
  23.          ".dwg"
  24.        )
  25.      )
  26.      (vl-file-delete path) ; Just in case...
  27.      (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname)) path)
  28.    )
  29. )
  30. (princ)
  31. )
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:19:38 | 显示全部楼层
罗伊,它工作得很好!我真是太感谢你了,我一个人永远也做不到!
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 08:14 , Processed in 0.359899 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表