本帖最后由 183017064 于 2025-4-8 10:56 编辑
表格内多行的单行文字对齐[左中/中间/右中]
http://bbs.mjtd.com/forum.php?mo ... 685&fromuid=7333152
(出处: 明经CAD社区)
修改大佬lostbalance的代码,添加左右上下边距(字高倍数 ps:0.1字高),(可以按需修改)。强制文字宽度0.8(可以按需修改) - (setq texts lsti)
- (setq H_list (mapcar '(lambda (txt) (cdr (assoc 40 (entget txt)))) texts))
- (setq H_max (apply 'max H_list))
- (setq margin_top (* 0.2 H_max)) ; 上边距----------------------------------------------------------------------
- (setq margin_bottom (* 0.1 H_max)) ; 下边距---------------------------------------------------------------------
- (setq available_height (- (- py2 py1) margin_top margin_bottom))
- (setq py (/ available_height n))
 - (defun AdjustTextWidth (txtent ty px1 px2 / current_41 tmp_txtdata tbox original_width available_width new_41 height)
- (setq current_41 (cdr (assoc 41 txtent)))
- (setq height (cdr (assoc 40 txtent))) ; 获取当前文字高度
- (setq tmp_txtdata (subst (cons 72 0) (assoc 72 txtent) txtent))
- (setq tmp_txtdata (subst (cons 73 0) (assoc 73 tmp_txtdata) tmp_txtdata))
- (setq tmp_txtdata (subst (cons 41 1.0) (assoc 41 tmp_txtdata) tmp_txtdata))
- (setq tmp_txtdata (subst (cons 10 (list 0 0 0)) (assoc 10 tmp_txtdata) tmp_txtdata))
- (setq tbox (textbox tmp_txtdata))
- (if (and tbox (car tbox) (cadr tbox))
- (progn
- (setq original_width (- (caadr tbox) (caar tbox)))
- (setq available_width
- (cond
- ((= ty "s") (- (- px2 px1) (* 0.2 height))) ; 左边距0.1H -------------------------------------------------------
- ((= ty "d") (- (- px2 px1) (* 0.4 height))) ; 中间左右各0.2H边距----------------------------------------------------
- ((= ty "f") (- (- px2 px1) (* 0.2 height))) ; 右边距0.1H ---------------------------------------------------------
- )
- )
- (if (and (> original_width 0) (> (* original_width current_41) available_width))
- (progn
- (setq new_41 (min (/ available_width original_width) 0.8))
- (setq txtent (subst (cons 41 new_41) (assoc 41 txtent) txtent))
- )
- )
- ;; 强制宽度因子限制
- (setq current_41 (cdr (assoc 41 txtent)))
- (if (> current_41 0.8)
- (setq txtent (subst (cons 41 0.8) (assoc 41 txtent) txtent))
- )
- )
- )
- txtent
- )
|