;; ╔══════════════════════════════════════════════════════════════════╗ ;; ;;; ║ 建筑标高转结构标高 (命令: bg3 - DCL对话框版) ║ ;; ;;; ║ 功能: 将选中的标高文本或天正标高统一减去高差值 ║ ;; ;;; ║ 更新: 预设4个常用高差值选项,支持手动输入,实时更新 ║ ;; ;;; ║ 自动记住上次选择,支持%%P0.000特殊处理 ║ ;; ;;; ║ DCL 中明确显示单位 m,输出不带单位 ║ ;; ;;; ║ 作者: 黄鲲 QQ353955675 | 修改: carrot1983 ║ ;; ╚══════════════════════════════════════════════════════════════════╝ ;; 全局变量(记住上次高差值和上次选择的选项) (if (null bg3_num) (setq bg3_num -0.030)) (if (null bg3_last_radio) (setq bg3_last_radio "radio_custom")) ;; 上次选择的选项 (DEFUN C:bg3 (/ e i new_num o ss sym txt v0 old_dimzin clean_txt num_val) (vl-load-com) ;; 保存原DIMZIN设置 (setq old_dimzin (getvar "DIMZIN")) (setvar "DIMZIN" 0) ;; 显示DCL对话框获取高差值 (if (null (bg3_dialog)) (progn (princ "\n已取消操作。") (setvar "DIMZIN" old_dimzin) (princ) (exit) ) ) (princ (strcat "\n建筑标高改成结构标高,作者黄鲲,命令bg3高差值: " (rtos bg3_num 2 3) "m")) ;; 只按实体类型选择,不限制文本内容 (setq ss (ssget '((0 . "TEXT,TCH_ELEVATION")))) (if (null ss) (progn (princ "\n未选择任何有效对象(文本或天正标高)。") (setvar "DIMZIN" old_dimzin) (princ) (exit) ) ) ;; 处理选中的对象 (setq i 0) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (setq o (vlax-ename->vla-object e)) (setq v0 (cdr (assoc 0 (entget e)))) ;; 根据对象类型确定属性名称 (cond ((= v0 "TEXT") (setq sym "TextString") ) ((= v0 "TCH_ELEVATION") (setq sym "Text") ) (t (setq sym nil) ) ) ;; 如果找到有效属性,进行修改 (if sym (progn ;; 获取原文本 (setq txt (vlax-get-property o sym)) ;; 特殊处理:%%P0.000 → 0.000 (setq clean_txt txt) (if (wcmatch clean_txt "%%P0.000,%%P0.00,%%P0.0,%%P0,±0.000") (progn (setq clean_txt "0.000") (princ (strcat "\n注意: 检测到特殊标高 \"" txt "\",已转换为 \"0.000\" 进行处理")) ) ) ;; 处理其他带%%P的情况(如%%P1.500 → 1.500) (if (and (wcmatch clean_txt "%%P*") (not (wcmatch clean_txt "%%P0*"))) (progn (setq clean_txt (substr clean_txt 4)) ;; 去掉%%P前缀 (princ (strcat "\n注意: 检测到带正负号标高 \"" txt "\",已转换为 \"" clean_txt "\" 进行处理")) ) ) ;; 检查是否为有效数字(排除纯文本如“说明”等) (setq num_val (atof clean_txt)) (if (or (= num_val 0.0) (/= (atof clean_txt) 0.0)) ;; 至少能转换为数字 (progn ;; 改颜色为品红色(6号色) (command "chprop" e "" "c" "6" "") ;; 计算新值(数字) (setq new_num (+ num_val bg3_num)) ;; 格式化为3位小数,输出不带单位 (setq new_num (rtos new_num 2 3)) ;; 更新文本 (vlax-put-property o sym new_num) ) (princ (strcat "\n警告: 跳过非数字文本 \"" txt "\"")) ) ) ) ) (princ (strcat "\n完成!共处理 " (itoa (sslength ss)) " 个对象,高差值: " (rtos bg3_num 2 3) "m")) ;; 恢复DIMZIN设置 (setvar "DIMZIN" old_dimzin) (princ) ) ;; DCL对话框函数(带单位显示) (DEFUN bg3_dialog (/ dcl_str dcl_id temp_num dcl_file file result radio_val radio_0030 radio_0050 radio_0100 radio_0120) (setq dcl_str "bg3_dialog : dialog { label = \"建筑标高改为 → 结构标高命令bg3,作者黄鲲\"; spacer_1; : boxed_radio_column { label = \"预设高差值(建筑面层厚度)\"; : radio_button { key = \"radio_0030\"; label = \"-0.030 m (常用)\"; } : radio_button { key = \"radio_0050\"; label = \"-0.050 m\"; } : radio_button { key = \"radio_0100\"; label = \"-0.100 m\"; } : radio_button { key = \"radio_0120\"; label = \"-0.120 m\"; } : radio_button { key = \"radio_custom\"; label = \"自定义 (单位: m):\"; } } spacer_1; : edit_box { key = \"num\"; label = \"\"; edit_width = 12; allow_accept = true; } spacer_1; : text { label = \"例: 建筑标高 0.000 → 结构标高 -0.030\"; alignment = centered; } : text { label = \"支持 %%P0.000 特殊处理 (自动转换为 0.000)\"; alignment = centered; } spacer_1; ok_cancel; }" ) ;; 加载DCL (setq dcl_id (load_dialog dcl_str)) ;; 如果直接加载失败,使用临时文件 (if (< dcl_id 0) (progn (setq dcl_file (vl-filename-mktemp "bg3.dcl")) (setq file (open dcl_file "w")) (write-line dcl_str file) (close file) (setq dcl_id (load_dialog dcl_file)) (if (< dcl_id 0) (progn (princ "\n错误: 无法加载DCL对话框!") (exit) ) ) ) ) ;; 创建对话框实例 (if (not (new_dialog "bg3_dialog" dcl_id)) (progn (princ "\n错误: 无法创建对话框实例!") (unload_dialog dcl_id) (if dcl_file (vl-file-delete dcl_file)) (exit) ) ) ;; 根据上次保存的选项设置单选按钮 (set_tile bg3_last_radio "1") ;; 设置编辑框的值(仅数字,不带 m) (set_tile "num" (rtos bg3_num 2 3)) ;; 如果不是自定义模式,禁用编辑框 (if (/= bg3_last_radio "radio_custom") (mode_tile "num" 1) ;; 禁用 (mode_tile "num" 0) ;; 启用 ) ;; 设置编辑框提示文字 (set_tile "num" (rtos bg3_num 2 3)) ;; 单选按钮动作函数 (defun update_from_radio (val) (cond ((= val "radio_0030") (setq bg3_num -0.030) (set_tile "num" (rtos bg3_num 2 3)) (mode_tile "num" 1) ;; 禁用编辑框 ) ((= val "radio_0050") (setq bg3_num -0.050) (set_tile "num" (rtos bg3_num 2 3)) (mode_tile "num" 1) ) ((= val "radio_0100") (setq bg3_num -0.100) (set_tile "num" (rtos bg3_num 2 3)) (mode_tile "num" 1) ) ((= val "radio_0120") (setq bg3_num -0.120) (set_tile "num" (rtos bg3_num 2 3)) (mode_tile "num" 1) ) ((= val "radio_custom") (mode_tile "num" 0) ;; 启用编辑框 (mode_tile "num" 2) ;; 焦点到编辑框 ) ) (setq bg3_last_radio val) ) ;; 动作响应 (action_tile "radio_0030" "(update_from_radio \"radio_0030\")") (action_tile "radio_0050" "(update_from_radio \"radio_0050\")") (action_tile "radio_0100" "(update_from_radio \"radio_0100\")") (action_tile "radio_0120" "(update_from_radio \"radio_0120\")") (action_tile "radio_custom" "(update_from_radio \"radio_custom\")") (action_tile "num" "(if (and $value (setq temp_val (atof $value)) (or (= bg3_last_radio \"radio_custom\") (progn (mode_tile \"radio_custom\" 2) (setq bg3_last_radio \"radio_custom\") (mode_tile \"num\" 0) t))) (setq bg3_num temp_val))") (action_tile "accept" "(if (and (or (= bg3_last_radio \"radio_custom\") (progn (setq bg3_last_radio \"radio_custom\") t)) (setq temp_str (get_tile \"num\")) (setq temp_val (atof temp_str))) (setq bg3_num temp_val) (if (= bg3_last_radio \"radio_0030\") (setq bg3_num -0.030) (if (= bg3_last_radio \"radio_0050\") (setq bg3_num -0.050) (if (= bg3_last_radio \"radio_0100\") (setq bg3_num -0.100) (if (= bg3_last_radio \"radio_0120\") (setq bg3_num -0.120) (setq bg3_num -0.030)))))) (done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") ;; 显示对话框 (setq result (start_dialog)) ;; 清理 (unload_dialog dcl_id) (if (and dcl_file (findfile dcl_file)) (vl-file-delete dcl_file)) ;; 处理返回值 (if (= result 1) (progn ;; 确保 bg3_num 有有效值 (if (null bg3_num) (setq bg3_num -0.030)) T ) nil ) ) (princ "\n命令 bg3 已加载 (DCL 中显示单位 m,处理后的标高不带单位)") (princ)