明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: 王咣生

几个visual lisp程序

  [复制链接]
发表于 2012-3-27 17:29 | 显示全部楼层
做什么用的啊
发表于 2012-7-9 14:36 | 显示全部楼层
本帖最后由 srv2 于 2012-7-9 14:37 编辑

看起來怪怪的, 好像要對 AUTOEXEC.BAT 做什麼事.


;;; Description:
;;; This following module's function is based on FSO(File System Object).
(vl-load-com)
(defun fso::fso ( / obj)
  (setq obj (vlax-create-object "Scripting.FileSystemObject"))
)
; Initialize global variable
(setq fso (fso::fso))
;;; Error handling codes.
(setq $orr *error* *error* #err)
(defun #err (s)
  (princ (strcat "\nError: " s))
  (setq *error* $orr)
  (princ)
)
;;; Property Function
(defun fso::Drives ( / dri)
  (vlax-get-property (fso::fso) 'Drives)
)
;;; Method Function
;;; Parameter: Path(String), Name(String)
;;; Example: _$ (fso::BuildPath "C:\\Program Files\\AutoCAD 2004" "acad.exe")
;;;          "C:\\Program Files\\AutoCAD 2004\\acad.exe"
(defun fso::BuildPath (Path Name / )
  (vlax-invoke-method (fso::fso) 'BuildPath path name)
)
;;; Parameter: Source(String), Destination(String), OverWriteFiles(Boolean)
;;; Example: _$ (fso::CopyFile "C:\\AUTOEXEC.BAT" "D:\\" T)
;;;          "D:\\AUTOEXEC.BAT"
(defun fso::CopyFile (Source Destination OverWriteFiles / Name ret)
  (if (and
(setq Name
        (if (= (vlax-invoke-method fso 'FileExists Source) :vlax-True)
   (vlax-get-property
     (vlax-invoke-method fso 'GetFile Source)
     'Name
   )
   nil
        )
       ret (strcat Destination Name)
)
(= (vlax-invoke-method fso 'FolderExists Destination) :vlax-True)
      )
    (progn
      (if (= (vlax-invoke-method fso 'FileExists ret) :vlax-False)
(progn
   (vlax-invoke-method fso 'CopyFile Source Destination OverWriteFiles)
   ret
)
(progn
   (setq OverWriteFiles (if OverWriteFiles T nil))
   (if (= OverWriteFiles T)
     (progn
       (vlax-invoke-method fso 'CopyFile Source Destination OverWriteFiles)
       ret
     )
     ret
   )
)
      )
    )
    nil
  )
)
;;; Parameter: Source(String), Destination(String), OverWriteFiles(Boolean)
;;; Example: _$ (fso::CopyFolder "C:\\Test" "D:\\" T)
;;;          "D:\\Test "
(defun fso::CopyFolder (Source Destination OverWriteFiles / Name ret)
  (if (and
(setq Name
        (if (= (vlax-invoke-method fso 'FolderExists Source) :vlax-True)
   (vlax-get-property
     (vlax-invoke-method fso 'GetFolder Source)
     'Name
   )
   nil
        )
       ret (strcat Destination Name)
)
(= (vlax-invoke-method fso 'FolderExists Destination) :vlax-True)
      )
    (progn
      (if (= (vlax-invoke-method fso 'FolderExists ret) :vlax-False)
(progn
   (vlax-invoke-method fso 'CopyFolder Source Destination OverWriteFiles)
   ret
)
(progn
   (setq OverWriteFiles (if OverWriteFiles T nil))
   (if (= OverWriteFiles T)
     (progn
       (vlax-invoke-method fso 'CopyFolder Source Destination OverWriteFiles)
       ret
     )
     ret
   )
)
      )
    )
    nil
  )
)
;;; Parameter: Path(String)
;;; Example: _$ (fso::CreateFolder "C:\\Test")
;;;          "C:\\Test "
(defun fso::CreateFolder (Path)
  (if (= (vlax-invoke-method fso 'FolderExists Path) :vlax-False)
    (progn
      (vlax-invoke-method fso 'CreateFolder Path)
      Path
    )
    Path
  )
)
;;; Parameter: FileSpec(String)
;;; Example: _$ (fso::DeleteFile "C:\\test.txt")
;;;          T
(defun fso::DeleteFile (FileSpec)
   (if
     (and
       (= (vlax-invoke-method fso 'FileExists FileSpec) :vlax-True)
       (not
  (vl-catch-all-error-p
    (vl-catch-all-apply
      'vlax-invoke-method
      (list fso 'DeleteFile FileSpec t)
    )
  )
       )
     )
     t
     nil
   )
)
;;; Parameter: FolderSpec(String)
;;; Example: _$ (fso::DeleteFolder "C:\\test")
;;;          T
(defun fso::DeleteFolder (FolderSpec)
  (if
    (and
      (= (vlax-invoke-method fso 'FolderExists FolderSpec) :vlax-True)
      (not
(vl-catch-all-error-p
   (vl-catch-all-apply
     'vlax-invoke-method
     (list fso 'DeleteFolder FolderSpec t)
   )
)
      )
    )
    t
    nil
  )
)

发表于 2012-7-21 20:03 | 显示全部楼层
顶起//
发表于 2012-7-24 14:24 | 显示全部楼层
给点提示信息啊,都不知道干什么用的
发表于 2012-9-2 18:46 | 显示全部楼层
下了看看我能用上么
发表于 2014-7-20 13:26 | 显示全部楼层
谢谢分享。
发表于 2014-11-6 14:06 | 显示全部楼层
没注释也不知道干什么用的,又给删了
发表于 2019-12-23 12:52 | 显示全部楼层
Thanks for sharing functions ^^
发表于 2020-2-2 11:13 | 显示全部楼层
谢谢,好东西,收藏 了,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 16:37 , Processed in 0.286909 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表