-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBtachPolyLine.lsp
More file actions
83 lines (81 loc) · 3.1 KB
/
BtachPolyLine.lsp
File metadata and controls
83 lines (81 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;;; Copyright 2025 李靖康
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.
(princ "\n[提示] 已加载 BatchPoyLine 插件 (版本 0.1.0)\n")
(princ "Copyright 2025 李靖康 All rights reserved.\n")
(princ "运行 \"BATPL\" 命令以开始绘制闭合线框\n\n")
(defun c:BATPL (/ file f line points coords)
(alert "请打开保存有坐标(X、Y)集合的.txt文件\n\n格式要求:\n1. 每行一个坐标对\n2. 坐标间用西文逗号或空格分隔\n3. 文件编码为不带 BOM 的 UTF-8")
(command "ucs" "w")
(vl-load-com)
(setq file (getfiled "选择坐标文件(UTF-8无BOM格式)" "" "txt" 0))
(if (setq f (open file "r"))
(progn
(while (setq line (read-line f))
(if (> (strlen line) 0)
(progn
(setq line (vl-string-trim " \t\r\n" line))
(setq line (vl-string-subst " " "," line))
(setq coords (read (strcat "(" line ")"))) ; 原代码此处缺少右括号
(if (and (listp coords)
(= (length coords) 2)
(numberp (car coords))
(numberp (cadr coords)))
(setq points (cons (list (cadr coords) (car coords)) points))
(princ
(strcat
"\n[错误] 无效行: \"" line "\"\n"
" 要求: X、Y需通过西文逗号或空格分隔,坐标之间需换行\n"
" 示例: 100,200 或 300 400\n"
)
)
)
)
)
)
(close f)
(setq points (reverse points))
(if points
(progn
(command "pline")
(foreach pt points (command pt))
(command "c")
(command "zoom" "e")
(command "zoom" "0.8x")
(alert "线框绘制完成!")
)
(alert
(strcat
"未找到有效坐标!\n\n"
"可能原因:\n"
"1. 文件内容为空\n"
"2. 所有行格式错误\n"
"3. 分隔符使用中文标点\n"
"解决方案:检查文件并确保符合格式要求"
)
)
)
)
(alert
(strcat
"文件打开失败!\n\n"
"常见解决方法:\n"
"1. 检查文件路径是否包含特殊字符\n"
"2. 确认文件未在其他程序中打开\n"
"3. 确保文件编码为不带 BOM 的 UTF-8\n"
" (可用记事本另存为时选择编码)"
)
)
)
(princ)
)