简单的自定面板函数
本帖最后由 szmaicy 于 2011-6-10 11:05 编辑;修改版,向飞诗学习
(defun c:xxx ()
(mai_make_panel
(list
(list "梁"
(list "画 梁" "circle") ;(list按钮标签运行的命令)
(list "单线变梁" "mini_line_to_beam")
(list "筏板梁倒角" "mini_foundation_beam")
(list "修补梁柱" "mini_fix_beam")
(list "修补双线" "mini_fix_dline")
(list "框选修补线" "mini_fix_line")
) ;_ 结束list
(list "柱"
(list " + 型柱" "mini_c_column")
(list " L 型柱" "mini_l_column")
(list " T 型柱" "mini_t_column")
(list " ○ 型柱" "mini_O_column")
(list " □ 型柱" "mini_r_column")
(list "轴线布柱" "mini_axis_column")
(list "填 充 柱" "mini_fill_column")
(list "墙体填充" "mini_fill_wall")
(list "转PKPM GS柱" "mini_pline_to_beam")
(list "多线变柱" "mini_pline_to_column")
) ;_ 结束list
) ;_ 结束list
) ;_ 结束mai_mak_panel
(princ)
)
(defun mai_make_panel ( menulist / n num_nobut num_button nn nnn menuname val_lst add_dclrow tt order_lst in num_image)
(defun add_dclrow ( dstr / ) (if dstr (setq val_lst (cons dstr val_lst))))
(setq menuname (strcat (vl-filename-mktemp) "temp_pannel.dcl"))
(add_dclrow "curbutton:button{width=10;vertical_margin=none;vertical_margin=none;}")
(add_dclrow "curimage:image{width=10;height=0.2;vertical_margin=none;vertical_margin=none;}")
(add_dclrow "curpanel:dialog{label=\"迷你自定义面板\";alignment=centered;vertical_margin=none;horizontal_margin=none;")
(add_dclrow ":row{")
(setq len (apply 'max (mapcar 'length menulist))
order_lst (apply 'append (mapcar 'cdr menulist))
num_button 0
num_nobut 0
in 0
num_image 0
)
(foreach nn menulist
(setq in 0)
(add_dclrow (strcat " : boxed_column{label=\"" (car nn) "\";vertical_margin=none; horizontal_margin=none;"))
(foreach nnn (cdr nn)
(setq num_button (1+ num_button)
in (1+ in)
num_image (1+ num_image)
tt (car nnn)
tt (if tt tt "")
)
(add_dclrow (strcat ":curbutton{label=\"" tt "\";key=\"but" (itoa num_button) "\";}"))
(if (= 4 in)
(progn (add_dclrow (strcat ":curimage{key=\"ima" (itoa num_image) "\";color=18;}"))
(setq in 0)
)
)
)
(repeat (- len (length nn))
(setq num_nobut (1+ num_nobut)
in (1+ in)
num_image (1+ num_image)
)
(add_dclrow (strcat " : curbutton{key=\"butno" (itoa num_nobut) "\";color=-2;}"))
(if (= 4 in)
(progn (add_dclrow (strcat ":curimage{key=\"ima" (itoa num_image) "\";}"))
(setq in 0)
)
)
)
(add_dclrow "spacer;}")
)
(add_dclrow "}:button{label=\"关闭\";key=\"cancel\";is_cancel=true;width=10;fixed_width=true;alignment=centered;}}")
(vl-file-delete menuname)
(setq nn (open menuname "w"))
(foreach n (reverse val_lst) (write-line n nn))
(close nn)
(setq nnn (load_dialog menuname))
(if (not (new_dialog "curpanel" nnn)) (exit))
(setq n 0)
(repeat num_nobut (mode_tile (strcat "butno" (itoa num_nobut)) 1) (setq num_nobut (1- num_nobut)))
(foreach nn menulist
(foreach nnn (cdr nn)
(setq n (1+ n)
tt (car nnn)
tt (if tt tt "")
)
(if (= tt "")
(mode_tile (strcat "but" (itoa n)) 1)
(action_tile (strcat "but" (itoa n)) (strcat "\(done_dialog " (itoa n) "\)"))
)
)
)
(setq nn (start_dialog))
(unload_dialog nnn)
(vl-file-delete menuname)
(if (> nn 0)
(progn (setq tt (cadr (nth (1- nn) order_lst)))
(princ "\n")
(if (= (eval (read (strcat "(type c:" tt ")"))) 'SUBR)
(eval (read (strcat "(c:" tt ")")))
(vl-cmdf tt)
)
)
)
)
本帖最后由 redcat 于 2011-3-7 15:24 编辑
在老迈的基础上修改了一下:主要是文件生成和删除2个函数(请麦工不要生气,呵呵^_^);;用户可自己修改界面
(defun c:xxx ()
(mai_make_panel
(list
(list "梁"
(list "画 梁" "circle") ;(list按钮标签运行的命令)
(list "单线变梁" "mini_line_to_beam")
(list "筏板梁倒角" "mini_foundation_beam")
(list "修补梁柱" "mini_fix_beam")
(list "修补双线" "mini_fix_dline")
(list "框选修补线" "mini_fix_line")
) ;_ 结束list
(list "柱"
(list " + 型柱" "mini_c_column")
(list " L 型柱" "mini_l_column")
(list " T 型柱" "mini_t_column")
(list " ○ 型柱" "mini_O_column")
(list " □ 型柱" "mini_r_column")
(list "轴线布柱" "mini_axis_column")
(list "填 充 柱" "mini_fill_column")
(list "墙体填充" "mini_fill_wall")
(list "转PKPM GS柱" "mini_pline_to_beam")
(list "多线变柱" "mini_pline_to_column")
) ;_ 结束list
) ;_ 结束list
) ;_ 结束mai_make_panel
(princ)
) ;_ 结束defun
(defun mai_make_panel (menulist / m n nn nnn menuname val_lst tt order_lst)
(defun add_dclrow (dstr)
(ifdstr
(setq val_lst (cons dstr val_lst))
) ;_ 结束if
) ;_ 结束defun
(add_dclrow "curbutton : button{width=10;vertical_margin=none;vertical_margin=none;}")
(add_dclrow
"curpanel : dialog{label=\"迷你工具箱\";alignment=centered;vertical_margin=none;horizontal_margin=none;"
) ;_ 结束add_dclrow
(add_dclrow ":row{")
(setqlen (apply 'max (mapcar 'length menulist))
order_lst (apply 'append (mapcar 'cdr menulist))
n 0
m 0
) ;_ 结束setq
(foreach nn menulist
(add_dclrow
(strcat " : boxed_column{label=\"" (car nn) "\";vertical_margin=none; horizontal_margin=none;")
) ;添加列表框
(foreach nnn (cdr nn)
(setq n(1+ n)
tt (car nnn)
tt (if tt
tt
""
) ;_ 结束if
) ;_ 结束setq
(add_dclrow (strcat " : curbutton{key=\"but" (vl-princ-to-string n) "\";label=\"" tt "\";}"))
) ;添加列表框中的按钮
(repeat (- len (length nn))
(setq m (1+ m))
(add_dclrow (strcat " : curbutton{key=\"butno" (vl-princ-to-string m) "\";}"))
) ;按列补齐列表框中的按钮
(add_dclrow "}")
) ;_ 结束foreach
(add_dclrow
"}:button{label=\"关闭\";key=\"cancel\";is_cancel=true;width=10;fixed_width=true;alignment=centered;}}"
)
(setq menuname (vl-filename-mktemp "temp_pannel.dcl"))
(setq nn (open menuname "w"))
(foreach n (reverse val_lst) (write-line n nn))
(close nn)
(setq nnn (load_dialog menuname))
(vl-file-delete menuname)
(if (not (new_dialog "curpanel" nnn))
(exit)
) ;_ 结束if
(setq n 0)
(repeat m (mode_tile (strcat "butno" (vl-princ-to-string m)) 1) (setq m (1- m))) ;禁用补齐列表框中的按钮
(foreach nn menulist
(foreach nnn (cdr nn)
(setq n(1+ n)
tt (car nnn) ;tt order_lst
tt (if tt
tt
""
) ;_ 结束if
) ;_ 结束setq
(if (= tt "")
(mode_tile (strcat "but" (vl-princ-to-string n)) 1)
(action_tile
(strcat "but" (vl-princ-to-string n))
(strcat "(done_dialog " (vl-princ-to-string n) ")")
) ;_ 结束action_tile
) ;_ 结束if
) ;_ 结束foreach
) ;_ 结束foreach
(setq nn (start_dialog))
(unload_dialog nnn)
(if (> nn 0)
(progn (setq tt (cadr (nth (1- nn) order_lst))) ;取点击按钮的值(这个很关键)
(if (= (eval (read (strcat "(type c:" tt ")"))) 'SUBR)
(progn (princ "\n")
(eval (read (strcat "(c:" tt ")")))
) ;_ 结束progn
(progn
(princ "\n")
(vla-SendCommand (vla-get-ActiveDocument(vlax-get-acad-object)) (strcat tt "\n"))
) ;_ 结束progn
) ;_ 结束if
) ;_ 结束progn
) ;_ 结束if
) ;_ 结束defun
把结束部分的代码修改一下,以支持直接写lisp代码。
原代码:
(if (= (eval (read (strcat "(type c:" tt ")"))) 'SUBR)
(eval (read (strcat "(c:" tt ")")))
(vl-cmdf tt )
)
修改后:
(if (= (substr tt 1 1)"(" )
(eval (read tt))
(vl-cmdf tt )
)
改后支持定义表:
(list
(list "文本处理"
;;(list按钮标签运行的命令 ),命令类型分lisp代码和其它命令两种
(list "单行合并为单行" "(TextsCombine)" )
(list "单行合并为多行" "(***)")
(list "单行转多行" "(***)" )
(list "炸开文本" "***")
)
(list "数字处理"
(list "递增复制" "(c:***)")
)
) xj6019 发表于 2019-12-4 08:18
界面太小了点字体不够大谁提示一下 把界面和字体放大一点 改哪里的代码啊?
(add_dclrow "curbutton:button{width=8;vertical_margin=none;vertical_margin=none;}")
8改大些 好东西啊 这样可以自己定义按钮了 和信的有一拼,不过信的button带驱动 好东西,感谢楼主分享! 谢谢分享,进来学习。 多谢提供模板。 繁重的活路中解放出来了 真牛! 首先,非常感谢楼主提供的程序,非常好用!
可是有个小问题,在面板中点击“确认”时,会执行“画梁”命令?不知为何,请不吝赐教,谢谢 把ok让老迈去掉