我的第一个LSP,另存为老版本。另外请教一个问题
本帖最后由 CAD新军 于 2018-12-9 00:10 编辑我用2014画图发建筑和甲方都经常说版本太高打不开,所以发图前都要存为低版本,我一般选2007版本文件。实在常用就弄了个脚本,有三个命令。
1. cw 保存当前违建为2007格式
2. cwjt,保存当前文件后面是今天的日期,如果有同样格式的日期在最后会更新日期,即 “天面.dwg”会变成 “天面.dwg”,但天面".dwg" 会变成 “天面.dwg”
3. ct,出图用的,删掉一大堆计算书图层,另存为当前文件位置新建一个当前日期名字文件夹
请教一个问题就是,怎样把一个命令批量在多文件执行?比如我打开3个文件,怎样都执行我这个cw命令呢?
;;;本LSP有三个个命令,cw直接保存当前文件为07版本DWG,cwjt保存文件加日期后缀
;;;ct 为出图用,删除盈建科计算书图层,另存到【日期】文件夹,保存为2007格式
;;出图删除图层修改下面这行增加(setq delLayer (list "11""12""13""dsptext_planname""dsptext_col" "dsptext_beam""dsptext_wallcol""SPRE_SPECBE_LIAN""SPRE_SPECBE_TF" "SPRE_SPEC_HINGE" "SPRE_SPECCL_JIAO" "SPRE_SPECWA_SHORT" "jiantu""砼柱" "砼墙""砼梁" "板洞边线" "PKPM_WPJ" ))
(defun c:cw()
;;(setvar "oldCmdecho" (getvar "cmdecho"))
;;(setvar "cmdecho" 0)
(setq oldExpert (getvar "expert" ))
(setvar "expert" 5)
(command "saveas" 2007 (strcat (getvar "dwgprefix")(getvar "dwgname")))
(setvar "expert" oldExpert)
;;(setvar "cmdecho" oldCmdecho)
(princ "保存为2007格式")
)
(defun c:cwjt()
;;;保存为今天日期并存为ACAD2007版本 prompt 2007 2013
(setq dwgname (getvar "dwgname"))
(setq dwgnamelen (strlen dwgname))
(setq dwgname (substr dwgname 1 (- dwgnamelen 4)))
(prompt "\n>空格保存默认版本,输入任意字符2007:")
(setq saveVersion (getstring))
(if (= saveVersion "") (setq saveVersion 2013) (setq saveVersion 2007))
(defun mysaveas(newFileName)
;;;(princ newFileName)
;;(setvar "oldCmdecho" (getvar "cmdecho"))
;;(setvar "cmdecho" 0)
(setq oldExpert (getvar "expert" ))
(setvar "expert" 5)
(command "saveas" saveVersion newFileName)
(setvar "expert" oldExpert)
;;(setvar "cmdecho" oldCmdecho)
)
(setq cdate (rtos (getvar "cdate") 2 8))
(setq savedate (strcat "[" (substr cdate 1 4) "-" (substr cdate 5 2) "-" (substr cdate 7 2) "]"))
(if (> dwgnamelen 10)
;;;长度足够在判断
(progn
(if (wcmatch dwgname "*`[####`-##`-##`]")
;;;文件名后有日期
(progn
;;; (strcat "\n" (substr dwgname 1 (- dwgnamelen 16)) savedate ".dwg")
(mysaveas (strcat (getvar "dwgprefix") (strcat (substr dwgname 1 (- dwgnamelen 16)) savedate ".dwg")))
)
;;;文件名后没有日期
(progn
;;; (princ (strcat "\n" dwgname savedate ".dwg"))
(mysaveas (strcat (getvar "dwgprefix") (strcat dwgname savedate ".dwg")) )
)
)
)
;;;长度不足,直接加
(progn
;;;(strcat "\n" dwgname savedate ".dwg")
(mysaveas (strcat (getvar "dwgprefix") (strcat dwgname savedate ".dwg")) )
)
)
)
(defun c:ct()
;;;################删除出图不要的图层
(setq AcadObject (vlax-get-acad-object)
AcadDocument (vla-get-ActiveDocument AcadObject)
LayersObj (vla-get-layers AcadDocument)
);end setq
(setq delLayer (list "11""12""13""dsptext_planname""dsptext_col" "dsptext_beam""dsptext_wallcol""SPRE_SPECBE_LIAN""SPRE_SPECBE_TF" "SPRE_SPEC_HINGE" "SPRE_SPECCL_JIAO" "SPRE_SPECWA_SHORT" "jiantu""砼柱" "砼墙""砼梁" "板洞边线" "PKPM_WPJ" ))
(vlax-for vlay LayersObj
(if (vl-position (vla-get-name vlay) delLayer)
(progn
(princ (vla-get-name vlay))
(vl-cmdf "_.-laydel" "_N" (vla-get-name vlay) "" "_Y")
)
)
);end vlax-for
;保存为2007格式到日期子目录
(setq cdate (rtos (getvar "cdate") 2 0))
(setq oldExpert (getvar "expert" ))
(setvar "expert" 5)
(vl-mkdir (strcat (getvar "dwgprefix") cdate))
(command "saveas" 2007 (strcat (getvar "dwgprefix") cdate "\\" (getvar "dwgname")))
(princ(strcat "保存到" (getvar "dwgprefix") cdate "\\" (getvar "dwgname")))
(setvar "expert" oldExpert)
)
可以尝试将lisp文件名改为acad.lsp,最后一行写 (c:cw),放在需要批量处理的dwg文件夹内,然后打开dwg文件,就会自动执行acad.lsp。 还不错,第一个程序能做出来,鼓励一下 只是单独存为旧版,改选项的是不是也可以 qq1547325443 发表于 2018-12-13 10:06
只是单独存为旧版,改选项的是不是也可以
保存为当版本和保存为旧版本会快很多。我平时都存为新版本的,只有发给其他专业或者甲方时会另存为低版本。 很流鼻啊简直太棒了 很实用的功能,感谢 程序不长,功能却很实用:handshake
页:
[1]