- 积分
- 14584
- 明经币
- 个
- 注册时间
- 2016-1-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
;操作方法,默认是当前图形的目录,可以点击浏览,选择其他目录.方法是先选中其他目录下的一个文件,单击打开,就定位到新的目录,再在对话框那儿选文件.
点击浏览后,可以在对话框的输入框那黏贴地址,还是比较方便的.
(defun MULTI_FILE_SELECT (/ dcl_id file_list selected_files current_path)
(setq dcl_code
"multi_file_select : dialog {
label = \"选择多个文件\";
: row {
: edit_box {
key = \"path\";
label = \"路径:\";
width = 40;
}
: button {
key = \"browse\";
label = \"浏览...\";
}
}
: list_box {
key = \"filelist\";
label = \"可用文件:\";
height = 15;
width = 50;
multiple_select = true;
}
: row {
: button {
key = \"accept\";
label = \"确定\";
is_default = true;
}
: button {
key = \"cancel\";
label = \"取消\";
is_cancel = true;
}
}
}")
; 将DCL写入临时文件
(setq dcl_file (strcat (getvar "TEMPPREFIX") "multi_file_select.dcl"))
(setq fp (open dcl_file "w"))
(write-line dcl_code fp)
(close fp)
; 设置初始路径
(setq current_path
(if (wcmatch (getvar "DWGPREFIX") "*\\")
(getvar "DWGPREFIX")
(strcat (getvar "DWGPREFIX") "\\")
)
)
; 获取文件列表函数
(defun update_file_list (path)
(setq file_list (vl-directory-files path "*.dwg" 1))
(if (not file_list)
(setq file_list '("没有找到文件")))
(start_list "filelist")
(mapcar 'add_list file_list)
(end_list)
)
; 加载并显示对话框
(setq dcl_id (load_dialog dcl_file))
(if (not (new_dialog "multi_file_select" dcl_id))
(exit)
)
; 设置初始路径和文件列表
(set_tile "path" current_path)
(update_file_list current_path)
; 设置按钮动作
(action_tile "browse"
"(progn
(setq new_path (getfiled \"选择文件夹\" current_path \"\" 16))
(if new_path
(progn
(setq temp_path (vl-filename-directory new_path))
(setq current_path
(if (wcmatch temp_path \"*\\\\\")
temp_path
(strcat temp_path \"\\\\\")
)
)
(set_tile \"path\" current_path)
(update_file_list current_path)
)
)
)"
)
(action_tile "accept" "(setq selected_files (get_tile \"filelist\")) (done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
; 启动对话框
(setq dialog_result (start_dialog))
(unload_dialog dcl_id)
; 删除临时DCL文件
(vl-file-delete dcl_file)
; 处理选择结果
(if (= dialog_result 1)
(progn
(setq selected_files (read (strcat "(" selected_files ")")))
(if selected_files
(progn
(princ "\n选择的文件:")
(mapcar '(lambda (x)
(princ (strcat "\n" (nth x file_list))))
selected_files)
(mapcar '(lambda (x)
(strcat current_path (nth x file_list)))
selected_files)
)
(princ "\n未选择任何文件")
)
)
(princ "\n操作已取消")
)
)
(defun C:TEST ()
(princ "\n1")
(setq result (MULTI_FILE_SELECT))
(if result
(progn
(princ "\n返回的文件路径:")
(mapcar (function (lambda (x) (princ (strcat "\n" x)))) result)
)
)
(princ)
)
|
评分
-
查看全部评分
|