You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoCAD LT 2024中如何为.scr脚本设置基于当前文件的相对路径?

AutoCAD LT 2024 SCR脚本实现相对路径批量处理文件

问题说明

使用AutoCAD LT 2024,编程能力有限,选择用.scr脚本批量打开、清理GIS导出的DXF文件并另存为DWG。现有脚本依赖绝对路径,每次换项目都要修改路径,希望改成基于当前打开文件的相对路径。尝试过LISP(需嵌套在脚本中,操作麻烦)和VBA(AutoCAD LT 2024中不可用),寻求可行方案。

原脚本代码:

_.open "T:\DXF output\Canopies and Boles.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\Canopies and Boles.dwg" Y _.close _.open "T:\DXF output\LabelLines.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\LabelLines.dwg" Y _.close _.open "T:\DXF output\LabelText.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\LabelText.dwg" Y _.close _.open "T:\DXF output\LabelWhiteOuts.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\LabelWhiteOuts.dwg" Y _.close _.open "T:\DXF output\RPAs.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\RPAs.dwg" Y _.close _.open "T:\DXF output\Tree Markers.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\Tree Markers.dwg" Y _.close _.open "T:\DXF output\Zones Boles Canopies.dxf" _.Zoom E _.PURGE all * N _.save LT2018 "T:\DXF output\Zones Boles Canopies.dwg" Y _.close

解决方案

SCR脚本本身无法直接获取当前打开文件的路径,但可以通过锚点文件+相对路径的方式实现需求:

  1. 创建锚点文件:在项目根目录(与DXF output文件夹同级)新建一个空白DWG文件,命名为ProjectAnchor.dwg。
  2. 设置工作目录:运行脚本前,先手动打开这个ProjectAnchor.dwg,AutoCAD会自动将当前工作目录设为该文件所在的路径。
  3. 修改脚本为相对路径:把原脚本中的绝对路径替换为相对路径,比如"DXF output\Canopies and Boles.dxf",这样脚本会基于当前工作目录(锚点文件所在目录)定位文件。

修改后的脚本示例(拆分多行提升可读性,SCR脚本支持换行执行):

_.open "DXF output\Canopies and Boles.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\Canopies and Boles.dwg" Y
_.close

_.open "DXF output\LabelLines.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\LabelLines.dwg" Y
_.close

_.open "DXF output\LabelText.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\LabelText.dwg" Y
_.close

_.open "DXF output\LabelWhiteOuts.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\LabelWhiteOuts.dwg" Y
_.close

_.open "DXF output\RPAs.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\RPAs.dwg" Y
_.close

_.open "DXF output\Tree Markers.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\Tree Markers.dwg" Y
_.close

_.open "DXF output\Zones Boles Canopies.dxf"
_.Zoom E
_.PURGE all * N
_.save LT2018 "DXF output\Zones Boles Canopies.dwg" Y
_.close

注意事项

  • 确保ProjectAnchor.dwg与DXF output文件夹在同一目录下,否则相对路径会失效。
  • 脚本中的空格是AutoCAD命令参数的分隔符,请勿随意删除。
  • 执行脚本时,必须先打开锚点DWG,再运行SCR脚本。

内容的提问来源于stack exchange,提问作者Sethinacan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:27:06