代码改变世界

AutoLISP对话框设计查询图元个数

2011-04-25 00:08  精诚所至 金石为开  阅读(472)  评论(0编辑  收藏  举报

AutoLISP对话框设计查询图元个数,可查CIRCLE、LINE和TEXT的数量,DCL代码如下。

dia5d:dialog {
    label = "练习" ;
    :concatenation {
        :text_part {
            label = "共选到【" ;
        }
        :text {
            width = 6 ;
            key = "t_cir" ;
        }
        :text_part {
            label = "】个CIRCLE" ;
        }
    }
    :concatenation {
        :text_part {
            label = "共选到【" ;
        }
        :text {
            width = 6 ;
            key = "t_line" ;
        }
        :text_part {
            label = "】个LINE" ;
        }
    }
    :concatenation {
        :text_part {
            label = "共选到【" ;
        }
        :text {
            width = 6 ;
            key = "t_text" ;
        }
        :text_part {
            label = "】个TEXT" ;
        }
    }
    ok_cancel;
}

LSP代码如下。

(defun c:dia5d ()
    (setvar "cmdecho" 0)
    (sub_dia5d)
    (if    ss
    (dcl_dia5d)
    )
    (prin1)
)
(defun sub_dia5d ()
    (setq ss (ssget))
    (if    (null ss)
    (setq ss (ssadd))
    )
    (setq cir_num 0
      line_num 0
      text_num 0
    )
    (setq n 0)
    (repeat (sslength ss)
    (setq en (ssname ss n))
    (setq entype (cdr (assoc 0 (entget en))))
    (cond ((= entype "CIRCLE") (setq cir_num (1+ cir_num)))
          ((= entype "LINE") (setq line_num (1+ line_num)))
          ((= entype "TEXT") (setq text_num (1+ text_num)))
    )
    (setq n (1+ n))
    )
)
(defun dcl_dia5d ()
    (setq dcl_id (load_dialog "dia5d"))
    (if    (not (new_dialog "dia5d" dcl_id))
    (exit)
    )
    (set_tile "t_cir" (itoa cir_num))
    (set_tile "t_line" (itoa line_num))
    (set_tile "t_text" (itoa text_num))
    (setq dd (start_dialog))
)

代码完。

查询其它图元类似。