DCMZ 发表于 2019-12-2 11:06:55

请问怎么批量操作同一文件夹下的dwg,差最后一步了

以下是原代码,麻烦大家看一下红色的地方

(defun c:dk (/)
(setq dir(qf_getFolder "选择文件夹:"))
(setq jiewei(substr dir(strlen dir)1))
(if (/= jiewei "\\")(setq dir(strcat dir"\\")))
;(setq ff (open (strcat dir "acad.lsp") "w"))
;(write-line kt1 ff)(write-line kt2 ff)(write-line kt3 ff)(write-line kt4 ff)(write-line kt5 ff)(write-line "(C:DD)" ff)
;(close ff)
(setq file(vl-directory-files dir "*.dwg"))
(foreach n file
(zzxx (strcat dir n))
)
;(vl-file-delete (strcat dir "acad.lsp") )
(prompt"\n全部打印完成")
)
(defun qf_getFolder (msg / WinShell shFolder path catchit)
(vl-load-com)
(setq winshell (vlax-create-object "Shell.Application"))
(setq shFolder (vlax-invoke-method WinShell 'BrowseForFolder 0 msg 1))
(setq
    catchit (vl-catch-all-apply
       '(lambda ()
   (setq shFolder (vlax-get-property shFolder 'self))
   (setq path (vlax-get-property shFolder 'path))
      )
   )
)
(if (vl-catch-all-error-p catchit)
    nil
    path
)
)
(defun zzxx (mldwg / acad cur_doc doc docs )
(setq Acad (vlax-get-acad-object))
(setq ActDoc (vla-get-activedocument Acad))
(setq MS (vla-get-ModelSpace ActDoc));ModelSpace
(vla-AddText MS "测试" (vlax-3D-point (list 0 0 0)) 50)
(setq cur_Doc(vla-get-activedocument acad))
(setq docs(vla-get-Documents acad))
(setq doc (vla-open docs mldwg))
(vla-Activate cur_Doc)
(vla-saveas doc mldwg)
(vla-close doc)
(vlax-release-object cur_Doc)
(vlax-release-object docs)
(vlax-release-object doc)
(vlax-release-object acad)
)


我想在每一个打开dwg中写入同一文本来试一下,但是运行结果只输出到第一个dwg了,其余dwg都没有,请问哪里错了呢

satan421 发表于 2019-12-2 14:44:42

代码只能在活动文档中执行,加载代码的活动文档没了,代码也就不执行了。
想要实现批量操作,论坛搜DBX。

DCMZ 发表于 2019-12-4 00:37:33

satan421 发表于 2019-12-2 14:44
代码只能在活动文档中执行,加载代码的活动文档没了,代码也就不执行了。
想要实现批量操作,论坛搜DBX。

谢谢,我试一下

wen1235 发表于 2019-12-4 17:16:01

DCMZ 发表于 2019-12-4 00:37
谢谢,我试一下

 改了一下可以达到你的效果


页: [1]
查看完整版本: 请问怎么批量操作同一文件夹下的dwg,差最后一步了