[转帖]完美统计图块数量及图块图例的显示(非伪源码)
<p>是在看不下去,特地抽了点时间整理了一下,申明:次源码来源于“小小工具集”,要感谢的去找该作者,我只是把部分源码提出来了,呵呵,看不惯某些人的“伪源码”!!!</p><p> </p>
<p><font face="Verdana">;;==============================块统计</font></p><font face="Verdana">
<p><br/>;;;----------------------------------------------------------------------------------------------<br/>;;;检查输入的原始参数表是否使用了组件的别名,如果使用了,便把别名改成组件全名。无论是否已使用组件的别名,都返回可供后续程序使用的参数表。<br/>(defun listFormatInputList (listInput / listComponentAlias listFormatedInput listMemberOfInput<br/> boolIsAlias intDefinedAliasNumber k strInputComponentName strAlias<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;定义组件别名表,形式为 ( ( 组件别名 组件原名) )<br/> (setq listComponentAlias '(("bt" "button")<br/> ("edit" "edit_box")<br/> ("edit12" "edit12_box")<br/> ("edit32" "edit32_box")<br/> ("listbox" "list_box")<br/> ("ComboBox" "popup_list")<br/> ("btRadio" "radio_button")<br/> ("tg" "toggle")<br/> ("btOK" "ok_only")<br/> ("btCancel" "cancel_button")<br/> ("btErrer" "errtile")<br/> ("btHelp" "help_button")<br/> ("btInfo" "info_button")<br/> ("btOC" "ok_cancel")<br/> ("btOCH" "ok_cancel_help")<br/> ("btOCHE" "ok_cancel_help_errtile")<br/> ("btOCHI" "ok_cancel_help_info")<br/> ("color17" "color_palette_1_7")<br/> ("color19" "color_palette_1_9")<br/> ("color09" "color_palette_0_9")<br/> ("color250255" "color_palette_250_255")<br/> ("stdColor" "std_rq_color")<br/> )<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/> (setq listFormatedInput nil)<br/> (foreach listMemberOfInput listInput<br/> (setq k 0<br/> boolIsAlias "No"<br/> )<br/> (setq strInputComponentName (strcase (car listMemberOfInput) T))<br/> (setq intDefinedAliasNumber (length listComponentAlias))<br/> (while (and (< k intDefinedAliasNumber) (= boolIsAlias "No"))<br/> (setq strAlias (strcase (car (nth k listComponentAlias)) T))<br/> (if (= strInputComponentName strAlias)<br/> (progn (setq boolIsAlias "Yes")<br/> (setq listFormatedInput (append listFormatedInput<br/> (list (cons (cadr (nth k listComponentAlias))<br/> (cdr listMemberOfInput)<br/> )<br/> )<br/> )<br/> )<br/> )<br/> )<br/> (setq k (1+ k))<br/> )<br/> (if (= boolIsAlias "No")<br/> (setq listFormatedInput (append listFormatedInput<br/> (list (cons (strcase (car listMemberOfInput) T)<br/> (cdr listMemberOfInput)<br/> )<br/> )<br/> )<br/> )<br/> )<br/> )<br/> listFormatedInput<br/>)<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;把输入的参数表转换为字符串表<br/>(defun listInputToString (listInput / listMemberOfInput listCdrMemberOfInput<br/> listMemberOfComponentParameters listComponentParameters listCadrMemberOfComponentParameters<br/> listResult k j boolDefinementFound<br/> strTmp test1 test2<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;组件定义参数表,形式为 ( ( 组件名列表) ( 对应参数名列表) )<br/>;;; 无属性控件,生成dcl文件时,在组件名后添加" ; “即可;如为“end”,在dcl文件里加上"}"字符即可<br/>;;; 容器控件及带属性控件,需要在名前添加” : ",名后加 "{"<br/> (setq listComponentParameters '((("容器控件" "dialog")<br/> ("label" "key" "value" "initial_focus"<br/> "height" "width" "children_alignment" "children_fixed_height"<br/> "children_fixed_width"<br/> )<br/> )<br/> (("容器控件" "boxed_column" "boxed_row" "boxed_radio_column"<br/> "boxed_radio_row" "column" "row" "radio_row" "radio_column"<br/> "concatenation" "paragraph"<br/> )<br/> ("label" "key" "is_enabled" "alignment"<br/> "height" "width" "fixed_height" "fixed_width"<br/> "children_alignment" "children_fixed_height" "children_fixed_width"<br/> )<br/> )<br/> (("带属性控件" "button")<br/> ("label" "key" "action" "alignment" "height" "width" "horizontal_margin"<br/> "vertical_margin" "fixed_height" "fixed_width" "is_cancel" "is_default" "is_enabled" "is_tab_stop"<br/> "mnemonic"<br/> )<br/> )<br/> (("带属性控件" "edit_box" "edit12_box" "edit32_box" "fcf_ebox" "fcf_ebox1")<br/> ("label" "key" "value" "action" "alignment" "height"<br/> "width" "fixed_height" "fixed_width" "allow_accept" "edit_limit" "edit_width"<br/> "is_enabled" "is_tab_stop" "mnemonic" "password_char"<br/> )<br/> )<br/> (("带属性控件" "image" "image_block" "icon_image")<br/> ("key" "value" "action" "alignment" "height" "width"<br/> "fixed_height" "fixed_width" "is_enabled" "is_tab_stop" "mnemonic" "aspect_ratio"<br/> "color"<br/> )<br/> )<br/> (("带属性控件" "image_button" "swatch" "fcf_ibut" "fcf_ibut1")<br/> ("key" "action" "alignment" "height" "width" "fixed_height"<br/> "fixed_width" "is_enabled" "is_tab_stop" "mnemonic" "allow_accept" "aspect_ratio"<br/> "color"<br/> )<br/> )<br/> (("带属性控件" "list_box")<br/> ("label" "key" "value" "action" "alignment" "height"<br/> "width" "fixed_height" "fixed_width" "allow_accept" "fixed_width_font"<br/> "is_enabled" "is_tab_stop" "list" "mnemonic" "multiple_select"<br/> "tabs" "tab_truncate"<br/> )<br/> )<br/> (("带属性控件" "popup_list")<br/> ("label" "key" "value" "action" "alignment" "height"<br/> "width" "fixed_height" "fixed_width" "edit_width" "fixed_width_font"<br/> "is_enabled" "is_tab_stop" "list" "mnemonic" "tabs" "tab_truncate"<br/> )<br/> )<br/> (("带属性控件" "radio_button")<br/> ("label" "key" "value" "action" "is_enabled" "is_tab_stop"<br/> "mnemonic" "alignment" "height" "width" "fixed_height" "fixed_width"<br/> )<br/> )<br/> (("带属性控件" "slider")<br/> ("label" "key" "value" "action" "alignment" "height"<br/> "width" "fixed_height" "fixed_width" "big_increment" "layout" "max_value"<br/> "min_value" "mnemonic" "small_increment"<br/> )<br/> )<br/> (("带属性控件" "spacer")<br/> ("value" "height" "width" "fixed_height" "fixed_width")<br/> )<br/> (("带属性控件" "text" "text_part" "text_25")<br/> ("label" "key" "value" "alignment" "height" "width" "fixed_height" "fixed_width" "is_bold")<br/> )<br/> (("带属性控件" "toggle")<br/> ("label" "key" "value" "action" "alignment" "height" "width" "fixed_height" "fixed_width" "is_enabled"<br/> "is_tab_stop")<br/> )<br/> (("无属性控件" "cancel_button" "errtile" "help_button"<br/> "info_button" "ok_cancel" "ok_cancel_help" "ok_cancel_help_errtile"<br/> "ok_cancel_help_info" "ok_only" "spacer" "spacer_0"<br/> "spacer_1" "color_palette_1_7" "color_palette_1_9" "color_palette_0_9"<br/> "color_palette_250_255" "std_rq_color"<br/> )<br/> )<br/> (("无属性控件" "end")) ;以"end"作为单个组件定义的结束,生成dcl文件时,以“}“代替<br/> )<br/> )<br/>;;;---------------------------------------------------------------------------------------------- <br/> (setq listResult nil)<br/> (setvar "dimzin" 8)<br/> (foreach listMemberOfInput listInput<br/> (setq k 0<br/> boolDefinementFound "NotYet"<br/> )<br/> (while (and (= boolDefinementFound "NotYet")<br/> (< k (length listComponentParameters))<br/> ) ;未找到组件参数名列表且未搜索完组件预定义列表时循环<br/> (setq listMemberOfComponentParameters (nth k listComponentParameters))<br/> (if (and (member (car listMemberOfInput)<br/> (car listMemberOfComponentParameters)<br/> )<br/> (if (= "spacer" (car listMemberOfInput))<br/> (>= (length listMemberOfInput)<br/> (length listMemberOfComponentParameters)<br/> )<br/> T<br/> ) ;因spacer既可为无属性控件也可为带属性控件,故特别处理<br/> )<br/> (progn (setq boolDefinementFound "Found"<br/> listCdrMemberOfInput (cdr listMemberOfInput)<br/> )<br/> (cond ((or (= "容器控件" (car (car listMemberOfComponentParameters)))<br/> (= "带属性控件" (car (car listMemberOfComponentParameters)))<br/> )<br/> listCdrMemberOfInput ;组件参数值有数据时<br/> (setq listResult (append listResult<br/> (list (strcat ":" (car listMemberOfInput) "{\n"))<br/> )<br/> )<br/> (setq j 0<br/> listCadrMemberOfComponentParameters (cadr listMemberOfComponentParameters)<br/> )<br/> (while (< j (length listCdrMemberOfInput))<br/> (if (not (= "" (nth j listCdrMemberOfInput)))<br/> (progn ;参数值非空时<br/> (if (numberp (nth j listCdrMemberOfInput))<br/> (setq strTMP (strcat (nth j listCadrMemberOfComponentParameters)<br/> "="<br/> (rtos (nth j listCdrMemberOfInput) 2 3)<br/> ";\n"<br/> )<br/> ) ;参数为数值时<br/> (setq strTMP (strcat (nth j listCadrMemberOfComponentParameters)<br/> "=\""<br/> (nth j listCdrMemberOfInput)<br/> "\";\n"<br/> )<br/> ) ;参数非数值时<br/> )<br/> (setq listResult (append listResult (list strTMP)))<br/> )<br/> )<br/> (setq j (1+ j))<br/> )<br/> (if (= "带属性控件" (car (car listMemberOfComponentParameters)))<br/> (setq listResult (append listResult (list "}\n")))<br/> ) ;带属性控件时,在字符串末尾加上组件结束标志 "}"<br/> )<br/> ((= (car listMemberOfInput) "end")<br/> (setq listResult (append listResult (list "}\n")))<br/> )<br/> (T ;(= "无属性控件" (car (car listMemberOfComponentParameters))) ,默认为无属性控件<br/> (setq listResult (append listResult<br/> (list (strcat (car listMemberOfInput) ";\n"))<br/> )<br/> )<br/> )<br/> )<br/> )<br/> (setq k (1+ k))<br/> )<br/> )<br/> )<br/> listResult<br/>)<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;生成并显示输入对话框<br/>;;;调用形式 ( listGenerateDCL DCL文件名(无路径及后缀)<br/>;;; 表( ( ( "组件名或别名") ( 参数值表 ) ) ...)<br/>;;; 表( ( "组件编号" "组件初始值" ) ...) ;组件显示值初始化<br/>;;; 表( ( "组件编号" "动作代码" ) ...) ;需设置动作的组件及对应的动作<br/>;;; 表("组件编号" ...) ) ;用户点“确定”键时,需获取输入值的组件名<br/>;;;注意,调用参数均为字符串形式<br/>;;;返回值为表,形式为 ( 关闭对话框的整数代码 指定组件返回值列表)<br/>(defun listGenerateDCL (strDCLFileName listInputDefinements listKeysAndValues listKeysAndActions<br/> listKeysToGetValue / listFormatedInput intDialogCloseType listKeysValue<br/> listResult fStream strFileFullName objectFile fileStream<br/> templist i dclid<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;按 ( ( “组件名” “值" ) ) 表,设置各组件的值<br/> (defun SetDCLValues (listKeysAndValues / listEachKeyAndValue)<br/> (foreach listEachKeyAndValue listKeysAndValues<br/> (set_tile (car listEachKeyAndValue)<br/> (cadr listEachKeyAndValue)<br/> )<br/> )<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;按 ( ( “组件名” “动作" ) ) 表,把组件与动作关联<br/> (defun SetDCLActions (listKeysAndActions / listEachKeyAndAction)<br/> (foreach listEachKeyAndAction listKeysAndActions<br/> (action_tile (car listEachKeyAndAction)<br/> (cadr listEachKeyAndAction)<br/> )<br/> )<br/> )<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;按 ( “组件名” ) 表,查询各组件值并返回值表<br/> (defun listGetDCLValues (listKeys / listEachKey listValues)<br/> (setq listValues nil)<br/> (foreach listEachKey listKeys<br/> (setq listValues (append listValues (list (get_tile listEachKey))))<br/> )<br/> listValues<br/> )<br/>;;;---------------------------------------------------------------------------------------------- <br/> (setq strFileFullName (vl-filename-mktemp (strcat strDCLFileName ".dcl")))<br/> (setq objectFile (open strFileFullName "w"))<br/> (setq listFormatedInput (listFormatInputList listInputDefinements))<br/> (setq fileStream (append (list strDCLFileName)<br/> (listInputToString listFormatedInput)<br/> )<br/> )<br/> (foreach fStream fileStream (princ fStream objectFile))<br/> (close objectFile)<br/> ;;以上生成dcl文件,以下调用DCL,设置组件值、关联动作,获取返回值<br/> (setq listResult nil)<br/> (setq dclid (load_dialog strFileFullName))<br/> (if (not (new_dialog strDCLFileName dclid ""))<br/> (progn (alert "对话框加载失败!") (exit))<br/> )<br/> (if listKeysAndValues<br/> (SetDCLValues listKeysAndValues)<br/> )<br/> (if listKeysAndActions<br/> (SetDCLActions listKeysAndActions)<br/> )</p>
<p> (if listKeysToGetValue<br/> (action_tile "accept" "(setq listKeysValue (listGetDCLValues listKeysToGetValue)) (done_dialog 1)" )<br/> )<br/> (setq intDialogCloseType (start_dialog))<br/> (unload_dialog dclid)<br/> (vl-file-delete strFileFullName)<br/> (setq listResult (append (list intDialogCloseType) listKeysValue))<br/> listResult<br/>)<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;----------------------------------------------------------------------------------------------<br/>;;;----------------------------------------------------------------------------------------------</p>
<p>;;;;funlib.lsp<br/>;;; -------------------------------------------------------------------------<br/>;;;计算以当前设置书写的文本占用长度<br/>;;;调用参数形式 ( 字符串 )<br/>(defun strLength (str / sLength x1 x2 lst)<br/> (setq lst (textbox (list (cons 1 str))))<br/> (setq x1 (car (nth 0 lst))<br/> x2 (car (nth 1 lst))<br/> )<br/> (setq sLength (abs (- x2 x1)))<br/> sLength<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;以当前设置初始化文本高、宽<br/>(defun initText (/ pt str eTextN)<br/> (setq pt (list 0 0))<br/> (setq str "初始化")<br/> (command "text" pt #ZiGao# 0 str)<br/> (setq eTextN (entlast))<br/> (entdel eTextN)<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;; 返回polyline的点表<br/>;;;调用参数形式 ( 多义线图元名 )<br/>(defun getplpts (pl / mark pts ver1 i ee pt)<br/> (if (= "POLYLINE" (cdr (assoc 0 (entget pl))))<br/> (progn ; read points of ployline<br/> (setq mark "VERTEX"<br/> i 0<br/> ver1 (entnext pl)<br/> )<br/> (while (= "VERTEX" mark)<br/> (setq pts (append pts (list (cdr (assoc 10 (entget ver1))))))<br/> (setq ver1 (entnext ver1)<br/> i (1+ i)<br/> )<br/> (setq mark (cdr (assoc 0 (entget ver1))))<br/> )<br/> )<br/> (progn ; read points of lwployline<br/> (setq ee (entget pl))<br/> (foreach pt ee<br/> (if (= 10 (car pt))<br/> (setq<br/> pts (append<br/> pts<br/> (list (append (cdr pt) (list (cdr (assoc 38 ee)))))<br/> )<br/> )<br/> )<br/> )<br/> )<br/> )<br/> pts<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;实数转换为桩号,并返回转换后的结果<br/>;;;调用参数形式 ( 里程的数值 里程的前缀 )<br/>(defun rtoZhuanHao (rZhuanHao QianZhui / sZhuanHao QianMi)<br/> ; rZhuanHao为需要转换为桩号的实数<br/> ; bzZhuanHao为桩号的前缀<br/> ; SZhuanHao为转换后的桩号字串<br/> (if (< rZhuanHao 0)<br/> (progn<br/> (setq QianZhui (strcat "-" QianZhui))<br/> (setq rZhuanHao (abs rZhuanHao))<br/> )<br/> )<br/> (setq rZhuanHao (fixreal rZhuanHao 2))<br/> (setq QianMi (fix (/ rZhuanHao 1000)))<br/> (setq rZhuanHao (- rZhuanHao (* QianMi 1000)))<br/> (setq sZhuanHao (strcat QianZhui (rtos QianMi 2 0) "+"))<br/> (if (< rZhuanHao 10)<br/> (setq sZhuanHao (strcat sZhuanHao "00"))<br/> (if (< rZhuanHao 100)<br/> (setq sZhuanHao (strcat sZhuanHao "0"))<br/> )<br/> ) ;不足位数桩号在前缀补位<br/> (setq sZhuanHao (strcat sZhuanHao (rtos rZhuanHao 2 2)))<br/> sZhuanHao<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;将ag调整到-pi/2~pi/2,并返回调整后的结果<br/>(defun AngInHalfPi (ag)<br/> (setq ag (if (and (> ag (/ pi 2)) (< ag (* pi 1.5)))<br/> (- ag pi)<br/> ag<br/> )<br/> )<br/> ag<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;将ag调整到0~pi,并返回调整后的结果<br/>(defun AngInPi (ag / twoPi)<br/> (setq twoPi (* 2 pi))</p>
<p> (if (< ag 0)<br/> (while (< ag 0)<br/> (setq ag (+ ag twoPi))<br/> )</p>
<p> (while (>= ag twoPi)<br/> (setq ag (- ag twoPi))<br/> )<br/> )</p>
<p> ag<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;; 读取纬地道路软件格式的纵断面文件,并返回数据表,失败时返回nil<br/>;|<br/>(defun GetDateFromZDMFile<br/> (/ FileName File1 LST STR zdmList nt n ZH GaoCheng R ch zdmDateFormat)<br/> (setq zdmList nil)</p>
<p> (if (setq FileName (getfiled "选择纬地纵断面文件" "" "zdm" 4))<br/> (progn<br/> ;;读模式打开纵断面数据文件<br/> (setq File1 (open FileName "r"))</p>
<p> ;;逐行读入<br/> (setq n 1<br/> zdmDateFormat<br/> "正确格式"<br/> )<br/>;;;n用于记录当前行序号为第一行或非第一行<br/> (while (and (setq STR (read-line File1))<br/> (= zdmDateFormat "正确格式")<br/> )<br/> (if (= n 1)<br/> (progn<br/> (setq nt (read str))<br/> (if (numberp nt)<br/> (setq zdmList (list (list nt)))</p>
<p> (progn<br/> (setq zdmList nil)<br/> (setq zdmDateFormat "错误格式")<br/> (princ (strcat "\n纵断面数据文件第1行数格式有误:不是整数!"))<br/> )<br/> )<br/> )</p>
<p> (progn<br/> (setq ZH nil<br/> GaoCheng nil<br/> R nil<br/> )</p>
<p> (setq ZH (read str))</p>
<p> (while (and (/= (setq ch (substr str 1 1)) " ")<br/> (>= (strlen str) 1)<br/> )<br/> (setq str (substr str 2))<br/> )<br/> (while (and (= (setq ch (substr str 1 1)) " ")<br/> (>= (strlen str) 1)<br/> )<br/> (setq str (substr str 2))<br/> )<br/> (setq GaoCheng (read str))<br/>;;;取得高程</p>
<p> (while (and (/= (setq ch (substr str 1 1)) " ")<br/> (>= (strlen str) 1)<br/> )<br/> (setq str (substr str 2))<br/> )<br/> (while (and (= (setq ch (substr str 1 1)) " ")<br/> (>= (strlen str) 1)<br/> )<br/> (setq str (substr str 2))<br/> )<br/> (setq R (read str))<br/>;;;取得高程</p>
<p> (if (and (numberp ZH)<br/> (numberp GaoCheng)<br/> (numberp R)<br/> )<br/> (setq zdmList (append zdmList (list (list ZH GaoCheng R))))</p>
<p> (progn<br/> (setq zdmList nil)<br/> (setq zdmDateFormat "错误格式")<br/> (princ<br/> (strcat "\n纵断面数据文件第" (rtos n 2 0) "行数据格式有误!")<br/> )<br/> )<br/> )<br/> )<br/> )</p>
<p> (setq n (1+ n))<br/> )<br/> ;;关闭文件<br/> (close File1)<br/> )<br/> )<br/> (if (/= nt (- n 2))<br/> (progn<br/> (setq zdmList nil)<br/> (princ<br/> "\n纵断面数据文件格式有误:数据文件中指定的变坡点总数与实际的变坡点总数不符!"<br/> )<br/> )<br/> )</p>
<p> zdmList<br/>) ;_ 结束defun<br/>|;<br/>(defun GetDateFromZDMFile (/ strFileName objectFile LineN listN zdmList )<br/> (setq zdmList nil)</p>
<p> (if (setq strFileName (getfiled "选择纬地道路软件或鸿业市政道路软件的纵断面设计数据文件(*.zdm或*.bgs)" "" "" 4))<br/> (progn<br/> ;;读模式打开纵断面数据文件<br/> (setq objectFile (open strFileName "r"))</p>
<p> ;;逐行读入<br/> (while (setq LineN (read-line objectFile)) <br/> (setq listN (read LineN)) ;单行字符串以"("开始,以")"结尾时,如鸿业市政道路软件数据文件格式<br/> (if (not (listp listN)) <br/> (setq listN (read (strcat "(" LineN ")" ))) ;单行字符串无小括号时,如纬地道路软件数据文件格式<br/> )</p>
<p> (if (and (> (length listN) 2)<br/> (numberp (car listN))<br/> (numberp (cadr listN))<br/> (numberp (caddr listN))<br/> )<br/> (setq zdmList (append zdmList (list listN)))<br/> )<br/> )</p>
<p> (close objectFile)</p>
<p> (if (> (length zdmList) 1)<br/> (setq zdmList (append (list (list (length zdmList))) zdmList))</p>
<p> (progn<br/> (setq zdmList nil)<br/> (princ "\n纵断面数据文件格式有误,有效变坡点可能不足两个!" )<br/> )<br/> )<br/> )<br/> )<br/> zdmList<br/>)<br/>;;;------------------------------------------------------------------------<br/>;;;计算指定里程点的高程,成功则返回计算结果,否则返回提示出错原因的字符串<br/>;;;调用参数形式 ( 纵断面设计数据表( 由GetDateFromZDMFile计算得到 ) 需查询高程的里程 )<br/>(defun ZDMBiaoGao (zdmList ZhuanHao / zhQ bgQ zhA bgA rA TA zhTA TB zhTB zhB bgB<br/> rB zhH bgH iQA iAB iBH diA diB<br/>;;;zh开头表示桩号;bg开头表示标高;r开头表示竖曲线;<br/>;;;A,B当前里程所在区间前后点<br/>;;;Q,A点之前变坡点;Ta,A处竖曲线,A点后切线点;TB,B处竖曲线,B点前切线点;H,B点后变坡点<br/>;;;iQA iAB iB di,分别为前坡段坡度,AB坡度,后坡段坡度,坡度差<br/>;;;T表示切点<br/> h0<br/>;;;未计竖曲线时高程<br/> hc<br/>;;;竖曲线高程修正高程<br/> h<br/>;;;设计高程<br/> AoTuR<br/>;;;竖曲线凹凸,ao,凹;tu,凸<br/> n nt x rStr OK RorS<br/> )</p>
<p> (setq nt (car (nth 0 zdmList)))<br/> (setq RorS "str")</p>
<p> (if (>= nt 2)<br/> (progn<br/> (setq zhA (car (nth 1 zdmList)))<br/> (setq zhB (car (nth nt zdmList)))</p>
<p> (cond<br/> <br/> ((< ZhuanHao zhA) (setq rStr "桩号过小"))<br/> <br/> ((> ZhuanHao zhB) (setq rStr "桩号过大"))<br/> <br/> ((<= zhA ZhuanHao zhB)<br/> <br/> (progn<br/> <br/> (setq n 2)<br/> (setq OK 0)<br/> <br/> (while (= OK 0)<br/> <br/> (setq zhB (car (nth n zdmList)))<br/> (if (<= ZhuanHao zhB)<br/> (progn<br/>;;;开始数据准备<br/> (setq bgA (cadr (nth (1- n) zdmList)))<br/> (setq bgB (cadr (nth n zdmList)))<br/> (setq iAB (/ (- bgB bgA) (- zhB zhA)))</p>
<p> (if (= n 2)<br/> (progn<br/> (setq diA 0)<br/> (setq rA 1)</p>
<p> (if (> nt 2)<br/>;;;纵断面不只有一个坡段时<br/> (progn<br/> (setq rB (caddr (nth 2 zdmList)))<br/> (setq zhH (car (nth 3 zdmList)))<br/> (setq bgH (cadr (nth 3 zdmList)))<br/> (setq iBH (/ (- bgH bgB) (- zhH zhB)))<br/> (setq diB (- iBH iAB))<br/> )<br/> )<br/> )<br/> )<br/>;;;点在第一段纵坡上时</p>
<p> (if (= n nt)<br/> (progn<br/> (setq diB 0)<br/> (setq rB 1)</p>
<p> (if (> nt 2)<br/>;;;纵断面不只有一个坡段时<br/> (progn<br/> (setq rA (caddr (nth (1- n) zdmList)))<br/> (setq zhQ (car (nth (- n 2) zdmList)))<br/> (setq bgQ (cadr (nth (- n 2) zdmList)))<br/> (setq iQA (/ (- bgA bgQ) (- zhA zhQ)))<br/> (setq diA (- iAB iQA))<br/> )<br/> )<br/> )<br/> )<br/>;;;点在最后一段纵坡上时</p>
<p> (if (and (/= n 2) (/= n nt))<br/> (progn<br/> (setq rA (caddr (nth (1- n) zdmList)))</p>
<p> (setq zhQ (car (nth (- n 2) zdmList)))<br/> (setq bgQ (cadr (nth (- n 2) zdmList)))</p>
<p> (setq rB (caddr (nth n zdmList)))</p>
<p> (setq zhH (car (nth (1+ n) zdmList)))<br/> (setq bgH (cadr (nth (1+ n) zdmList)))</p>
<p> (setq iQA (/ (- bgA bgQ) (- zhA zhQ)))<br/> (setq iBH (/ (- bgH bgB) (- zhH zhB)))<br/> (setq diA (- iAB iQA))<br/> (setq diB (- iBH iAB))<br/> )<br/> )<br/>;;;点不在第一段也不在最后一段纵坡上时</p>
<p> (setq TA (abs (* diA (* 0.5 rA))))<br/> (setq TB (abs (* diB (* 0.5 rB))))</p>
<p> (setq zhTA (+ zhA TA))<br/> (setq zhTB (- zhB TB))<br/>;;;结束数据准备</p>
<p> (cond<br/> ((< ZhuanHao zhTA)<br/> (progn<br/> (setq x (- zhTA ZhuanHao))<br/> (setq hc (* 0.5 (/ (* x x) rA)))<br/> (if (< diA 0)<br/> (setq AoTuR "tu")<br/> (setq AoTuR "ao")<br/> )<br/> )<br/> )<br/>;;;里程点在A点竖曲线上时</p>
<p> ((<= zhTA ZhuanHao zhTB)<br/> (progn<br/> (setq hc 0)<br/> ;;竖曲线修正值为0<br/> (setq AoTuR "ao")<br/>;;;里程点不在竖曲线上,采用凹曲线的计算公式<br/> )<br/> )<br/>;;;里程点不在竖曲线上时</p>
<p> ((> ZhuanHao zhTB)<br/> (progn<br/> (setq x (- ZhuanHao zhTB))<br/> (setq hc (* 0.5 (/ (* x x) rB)))</p>
<p> (if (< diB 0)<br/> (setq AoTuR "tu")<br/> (setq AoTuR "ao")<br/> )<br/> )<br/> )<br/>;;;里程点在B点竖曲线上时</p>
<p> <br/> )<br/>;;;计算竖曲线高程修正值,并判断曲线的凹凸</p>
<p> (setq h (+ bgA (* iAB (- ZhuanHao zhA))))<br/>;;;计算未含竖曲线修正值时的设计高程</p>
<p> (if (= AoTuR "ao")<br/> (setq h (+ h hc))<br/> (setq h (- h hc))<br/> )<br/>;;;计算最终设计高程<br/> (setq OK 1)<br/> (setq RorS "real")<br/> )<br/> (progn<br/> (setq zhA zhB)<br/> (setq n (1+ n))<br/> )<br/> <br/> )<br/> )<br/> )<br/> <br/> )<br/> )<br/> )</p>
<p> (setq rStr "数据文件有误")<br/> )<br/> (if (= RorS "real")<br/> h<br/> rStr<br/> )<br/>;;;输出返回值<br/>) ;_ 结束defun<br/>;;;------------------------------------------------------------------------<br/>;;;判断点位位曲线的左侧、右侧、还是在曲线上<br/>;;;返回结果为字符串,有三种:"右侧" "左侧" "在中线上"<br/>;;;调用参数形式 ( 曲线图元名 需判断左右的点 点与曲线的垂足 垂足到曲线起点的曲线长度 里程增加方向 )<br/>(defun strZhuoYou (oblname PJ PjP LPjP FS / ZhuoYou PP agPJ agPP agD)<br/> (if (/= (distance PJ PjP) 0)<br/> (progn<br/> (if (= FS "同向")<br/> (setq PP (vlax-curve-getPointAtDist oblname (- LPjP 0.001)))<br/> (setq PP (vlax-curve-getPointAtDist oblname (+ LPjP 0.001)))<br/> )<br/>;;;取得里程比井里程小0.001的点坐标</p>
<p> (setq agPP (angle PjP PP))<br/>;;;PjP->PP方位角(0~2 Pi)<br/> (setq agPJ (angle PjP PJ))<br/>;;;PjP->PJ方位角(0~2 Pi)</p>
<p> (setq agD (- agPJ agPP))<br/>;;;方位角差</p>
<p> (if (or (< (abs (- agD (* pi 0.5))) 0.5)<br/> (< (abs (+ agD (* pi 1.5))) 0.5)<br/> )<br/>;;;方位角差为pi/2或1.5pi,最大误差为0.5<br/> (setq ZhuoYou "右侧")<br/> (setq ZhuoYou "左侧")<br/> )<br/>;;;点位于道路左侧或右侧<br/> )</p>
<p> (setq ZhuoYou "在中线上")<br/> )<br/> ZhuoYou<br/>)<br/>;;;------------------------------------------------------------------------<br/>;;;回四舍五入函数,返四舍五入后的实数<br/>;;;调用参数形式 ( 数值 小数位数 )<br/>(defun fixReal (数值 小数位数 / N2 n10 NReturn)<br/> (setq n10 (expt 10 小数位数))<br/> (setq N2 (fix (* 数值 2 n10)))</p>
<p> (setq NReturn (+ (/ N2 2) (rem N2 2)))<br/> (setq NReturn (/ (float NReturn) (float N10)))<br/> NReturn<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;; 选择圆,允许按直径条件过滤,并返回选择集表<br/>;;;调用参数形式 ( “提示需要进行的操作”+“圆及其修饰” 的文本 )<br/>(defun SelectCircles (OperationStr / obcName nob obc obcK i KeyW KeyR cR cList nList obType)<br/> (if (ssgetfirst) <br/> (setq obc (ssget "_P" '((0 . "circle"))))<br/> ) ;有预选择时,从预选择集中找出被选择的圆选择集</p>
<p> (if (not obc)<br/> (progn<br/> (princ (strcat "\n选择需要" OperationStr ":"))<br/> (setq obc (ssget '((0 . "circle")))) ; 创建选择集 obc<br/> ) ;无预选择或预选择中无圆图元时<br/> )</p>
<p> (if obc<br/> (progn<br/> (setq nob (sslength obc))</p>
<p> (initget "Y N R _Yes No ReSelect")<br/> (setq KeyW<br/> (getkword<br/> (strcat "\n是否选择了不需要"<br/> OperationStr<br/> "[是(Y)/否(N)/重新选择(R)]<N>:"<br/> )<br/> )<br/> )<br/> (cond<br/> ((= KeyW "Yes")<br/> (initget 6)<br/> (setq<br/> KeyR (getreal<br/> (strcat<br/> "\n指定需要"<br/> OperationStr<br/> "的直径(右键或回车表示所有选择的圆均需要进行操作):"<br/> )<br/> )<br/> )<br/> (if (numberp KeyR)<br/> (progn<br/> (setq i 0<br/> cList nil<br/> )<br/> (repeat nob<br/> (setq obcK (ssname obc i))<br/> (setq cR (cdr (assoc 40 (entget obcK))))</p>
<p> (if (/= cR (/ KeyR 2.0))<br/> (setq cList (append cList (list obcK)))<br/> )<br/> (setq i (1+ i))<br/> ) ;计算需要从选择集中去除的图元的名称表</p>
<p> (setq i 0)<br/> (repeat (length cList)<br/> (ssdel (nth i cList) obc)</p>
<p> (setq i (1+ i))<br/> )<br/> ;从选择集中去除不符合条件的图元<br/> )<br/> )<br/> )</p>
<p> ((= KeyW "ReSelect")<br/> (princ (strcat "\n重新选择需要" OperationStr ":"))<br/> (setq obc (ssget '((0 . "circle")))) ; 创建选择集 obc<br/> )</p>
<p> (T nil)<br/> )<br/> )<br/> )<br/> obc<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;根据里程计算井点的坐标,成功则返回表 ( 坐标,点所在里程处中线在里程增加方向的切线角) , 否则返回nil<br/>;;;为减少程序的计算量,调用参数多设置了两个<br/>;;;调用参数形式 ( 中线对象 中线长度 起点里程 里程方向 终点里程 里程 左右 距离 )<br/>(defun getPointByLiChengZhuoYouJuLi (中线对象 中线长度 起点里程 里程方向 终点里程 里程 左右 距离 / ag Dst obPoint lst)<br/> (setq obPoint nil<br/> ag 0<br/> lst nil<br/> )</p>
<p> (if (or (and (= 里程方向 "同向") (<= 起点里程 里程 终点里程))<br/> (and (/= 里程方向 "同向") (>= 起点里程 里程 终点里程))<br/> )<br/> (progn<br/> (setq Dst (abs (- 里程 起点里程)))<br/> (setq ZhongDian (vlax-curve-getPointAtDist 中线对象 Dst))<br/> ;;根据里程计算中点坐标</p>
<p> (if (= 距离 0) ;判断井是否在路中线上<br/> (setq obPoint ZhongDian)</p>
<p> (progn<br/> (setq ag (AngleQieXiang 中线对象 ZhongDian))<br/> ;;计算切线角</p>
<p> (if (or (and (= 里程方向 "同向") (= 左右 "左侧"))<br/> (and (/= 里程方向 "同向") (/= 左右 "左侧"))<br/> )<br/> (setq obPoint (polar ZhongDian (+ ag (* pi 0.5)) 距离))</p>
<p> (setq obPoint (polar ZhongDian (+ ag (* pi 1.5)) 距离))<br/> )<br/> ) ;计算要求点不在路中线上时的坐标<br/> )</p>
<p> (if (and (/= 距离 0)<br/> (/= 里程方向 "同向")<br/> )<br/> (setq ag (+ ag pi))<br/> ) ;点所在里程处中线在里程增加方向的切线角</p>
<p> (setq lst (list obPoint ag)) ;计算成功时,生成结果表<br/> )<br/> ) ;里程有效时,计算坐标及切线角度<br/> lst ;返回结果表<br/>)<br/>;;; -------------------------------------------------------------------------<br/>;;;如果成功,返回表: ( 中线 中线起点里程 里程增加与曲线正向的关系 终点里程 中线长 ) ;否则返回nil<br/>;;;调用形式( GetZhongXiang nil或任意值) 如果参数不为nil时,将强制重新设置路中线扩展数据<br/>;;;生成的扩展数据格式为:( "PS_DLZX" (1040 起点里程) (1040 终点里程) ) 注:此处的起终点为cad线图的起终点,非道路真实起终点<br/>(defun GetZhongXiang (strResetXData / intSelectedSetNumber ssSelected<br/> strZhongXiangEntityName listZhongXiangXData LZhongXiang<br/> QiDianLiCheng ZhongDianLiCheng LiChengFangXiang strLiChengQianZhui listResult keyW<br/> )<br/>;;;-------------------------------------------------------------<br/>;;;获取中线的xdata数据,并计算道路资料<br/> (defun GetFromXData (/ keyword tmpList )<br/> (setq strLiChengQianZhui (cdr (cadr listZhongXiangXData)))</p>
<p> (setq tmpList (caddr listZhongXiangXData))<br/> (setq QiDianLiCheng (cadr tmpList))<br/> (setq ZhongDianLiCheng (caddr tmpList))</p>
<p> (if (<= QiDianLiCheng ZhongDianLiCheng)<br/> (setq LiChengFangXiang "同向")<br/> (setq LiChengFangXiang "反向")<br/> )<br/> (setq LZhongXiang<br/> (vlax-curve-getDistAtParam<br/> strZhongXiangEntityName<br/> (- (vlax-curve-getEndParam strZhongXiangEntityName)<br/> (vlax-curve-getStartParam strZhongXiangEntityName)<br/> )<br/> )<br/> ) ;中线长度<br/> (if (< -1<br/> (- (abs (- ZhongDianLiCheng QiDianLiCheng)) LZhongXiang)<br/> 1<br/> ) ;判断定义路中线后,中线对象是否被改变<br/> (if (<= QiDianLiCheng ZhongDianLiCheng) ;中线对象未被修改或仅被微调时<br/> (setq ZhongDianLiCheng (+ QiDianLiCheng LZhongXiang))<br/> (setq QiDianLiCheng (+ ZhongDianLiCheng LZhongXiang))<br/> ) ;根据实际的道路起点里程及 道路长度重新计算路终里程,以免若路中线被微调,所计得到的设置不正确</p>
<p> (progn ;中线对象已被修改时<br/> (initget "A R _AutoSet Reset")<br/> (setq keyword (getkword<br/> "路中线在定义后已被改变[按原定义的起点及方向自动调整(A)/重新定义(R)]<A>:"<br/> )<br/> )<br/> (if (= keyword "Reset")<br/> (InterSet)</p>
<p> (if (<= QiDianLiCheng ZhongDianLiCheng)<br/> (setq ZhongDianLiCheng (+ QiDianLiCheng LZhongXiang))<br/> (setq QiDianLiCheng (+ ZhongDianLiCheng LZhongXiang))<br/> ) ;根据实际的道路起点里程及 道路长度重新计算路终里程<br/> )<br/> )<br/> )<br/> )<br/>;;;-------------------------------------------------------------<br/>;;;以交互形式设置中线信息<br/> (defun InterSet (/ ckPointA KCKPA ckPointB kw zhFangShang LCKPA LCKPB LinShiPoint)<br/> ;;zhFangShang为用于判断里程增加方向,为正时,曲线开始点为里程起点,反之为终点<br/> (setvar "osmode" 431)<br/> (setq ckPointA nil<br/> ckPointB nil<br/> LinShiPoint nil<br/> )</p>
<p> (while (not ckPointA)<br/> (setq ckPointA (getpoint "\n指定中线上一点:"))<br/> (setq LinShiPoint (vlax-curve-getClosestPointTo strZhongXiangEntityName ckPointA T ) )<br/> (if (<= (distance ckPointA LinShiPoint) 0.5) ;两点的距离在0~0.5之间时<br/> (setq ckPointA LinShiPoint)</p>
<p> (progn<br/> (setq ckPointA nil)<br/> (princ "\n所指定的点不在指定的道路中心线上,请重新指定!")<br/> )<br/> )<br/> )</p>
<p> (if (not (setq KCKPA (getreal "\n输入参考点的里程数值<0>:")))<br/> (setq KCKPA 0)<br/> )</p>
<p> (while (not ckPointB)<br/> (setq ckPointB (getpoint "\n指定路中线上的另一点:"))<br/> (setq LinShiPoint (vlax-curve-getClosestPointTo strZhongXiangEntityName ckPointB T ) )<br/> (if (<= (distance ckPointB LinShiPoint) 5.0) ;两点的距离在0~5.0之间时<br/> (setq ckPointB LinShiPoint)</p>
<p> (progn<br/> (setq ckPointB nil)<br/> (princ "\n所指定的点不在指定的道路中心线上,请重新指定!")<br/> )<br/> )</p>
<p> (if (and ckPointB<br/> (<= (distance ckPointB ckPointA) 0.1) ;如果两点的距离在0~0.1之间时,两点看做为同一点<br/> )<br/> (progn<br/> (setq ckPointB nil)<br/> (princ<br/> "\n第二次指定的点与第一次指定的点相同,请重新指定与第一点不同的点!"<br/> )<br/> )<br/> )<br/> )</p>
<p> (setvar "osmode" 0)</p>
<p> (initget "A S _Add Sub")<br/> (setq kw (getkword<br/> "\n第二点里程相对第一点的里程是[增加(A)/减少(S)]<A>:"<br/> )<br/> )<br/> (if (= kw "Sub")<br/> (setq zhFangShang -1)<br/> (setq zhFangShang 1)<br/> ) ; 默认相对里程为增加</p>
<p> (setq LCKPA (vlax-curve-getDistAtPoint strZhongXiangEntityName ckPointA)) ; 第一点到曲线起点的长度<br/> (setq LCKPB (vlax-curve-getDistAtPoint strZhongXiangEntityName ckPointB)) ; 第二点到曲线起点的长度</p>
<p> (setq LZhongXiang<br/> (vlax-curve-getDistAtParam<br/> strZhongXiangEntityName<br/> (- (vlax-curve-getEndParam strZhongXiangEntityName)<br/> (vlax-curve-getStartParam strZhongXiangEntityName)<br/> )<br/> )<br/> ) ;中线长度</p>
<p> (if (> (* zhFangShang (- LCKPB LCKPA)) 0)<br/> (progn<br/> (setq QiDianLiCheng (- KCKPA LCKPA)) ; 中线起点(曲线起点)里程<br/> (setq ZhongDianLiCheng (+ QiDianLiCheng LZhongXiang))<br/> ;;终点里程<br/> (setq LiChengFangXiang "同向") ; 里程增加方向与中线起点到终点方向相同<br/> )<br/> (progn<br/> (setq QiDianLiCheng (+ KCKPA LCKPA)) ; 中线起点(曲线起点)里程<br/> (setq ZhongDianLiCheng (- QiDianLiCheng LZhongXiang)) ;终点里程<br/> (setq LiChengFangXiang "反向") ; 里程增加方向与中线起点到终点方向不同<br/> )<br/> ) ;判断里程方向与曲线方向的关系,并确定曲线起终点的里程</p>
<p> (if (= "" (setq strLiChengQianZhui (getstring "\n输入里程的前缀<K>:")))<br/> (setq strLiChengQianZhui "K")<br/> )</p>
<p> (SetXdata strZhongXiangEntityName<br/> (list "PS_DLZX"<br/> (cons 1000 strLiChengQianZhui)<br/> (list 1010 QiDianLiCheng ZhongDianLiCheng 0)<br/> )<br/> )<br/> ;;把起点里程及 终点里程定义添加到中线对象的标记为"PS_DLZX" 的扩展数据中<br/> )<br/>;;;-------------------------------------------------------------<br/> (setq listResult nil)<br/> (vl-cmdf "ucs" "w")</p>
<p> (setq intSelectedSetNumber 2)<br/> (while (> intSelectedSetNumber 1)<br/> (princ "\n选择路中线(只能选择一条线):")<br/> (setq ssSelected (ssget '((0 . "*line,arc")))) ; 创建选择集 ssSelected<br/> (if ssSelected<br/> (setq intSelectedSetNumber (sslength ssSelected))<br/> (setq intSelectedSetNumber 2)<br/> )<br/> )</p>
<p> (setq strZhongXiangEntityName (ssname ssSelected 0)) ; oblname,取得中线对象名</p>
<p> (setq listZhongXiangXData (cadr (assoc -3 (entget strZhongXiangEntityName '("PS_DLZX")) )))</p>
<p> (if listZhongXiangXData<br/> (if (= strResetXData "是")<br/> (progn<br/> (initget "S R _Set Remain")<br/> (setq keyW (getkword "该路中线已经被定义![重新定义(S)/保留原定义(R)]<R>:" ) )<br/> (if (= keyW "Set")<br/> (InterSet) ;如果指定重新设置,设置路中线信息<br/> )<br/> )</p>
<p> (GetFromXData) ;不指定重新设置时,从扩展数据计算路中线信息<br/> ) ;存在已定义的路中线扩展数据时</p>
<p> (InterSet) ;未设置有扩展的路中线数据时,重头设置路中线信息<br/> )</p>
<p> (setq listResult (list strZhongXiangEntityName QiDianLiCheng LiChengFangXiang ZhongDianLiCheng LZhongXiang strLiChengQianZhui) )<br/> listResult<br/>)<br/>;;;-------------------------------------------------------------<br/>;| (SetXdata strEntityName listApp) = entmod方式,给实体添加或更新或删除扩展数据.-----梁雄啸.2004.10.1<br/>参数: strEntityName = 实体名.<br/> listApp = '("注册名" 项1 项2 ...) ;用于添加或更新. 如(list "test" '(1070 . 1234)'(1003 . "0"))<br/> '("注册名") ; 用于删除相关注册项的xdata.<br/> nil ; 用于删除实体全部的xdata.<br/>说明: 支持所有实体.非图形实体不支持viewport(必须用 vlax-ldata-put.或setxdata方法).<br/> 参考 entmod 帮助.<br/>相关: 参照 ()函数=vla方式,支持所有的扩展数据修改.<br/>实例: 1.增加(如已经有,则为更新)指定注册名的xdata:<br/> (SetXdata (car(entsel)) (list "test" (cons 1070 1234)))<br/> 2.删除指定注册名的xdata:<br/> (SetXdata (car(entsel)) '("test"))<br/> 3.删除所有的扩展数据:<br/> (SetXdata (setq strEntityName(car(entsel))) nil)<br/>|;<br/>(defun SetXdata (strEntityName listApp / listApps)<br/> (if listApp<br/> (regapp (car listApp))<br/> )<br/> ;;无论是否已经有,均注册.有重复的话无不利影响.<br/> (if listApp<br/> (entmod (list (cons -1 strEntityName) (list -3 listApp)))<br/> ;;新建,更新,或删除指定app,{用 '("注册名") }.<br/> (progn ;;删除所有的扩展数据.<br/> (setq listApps (mapcar 'car (cdr (assoc -3 (entget strEntityName '("*"))))))<br/> (entmod (list (cons -1 strEntityName)<br/> (cons -3 (mapcar 'list listApps))<br/> )<br/> )<br/> )<br/> )<br/>)<br/>;;;-------------------------------------------------------------<br/>;;;计算曲线上一点处的正向切线角0~2 pi<br/>;;;调用形式 (曲线对象名 曲线上一点的坐标) :未处理坐标不在曲线上的情况<br/>(defun AngleQieXiang (曲线 pt / para Pt1 ag)<br/> (setq para (vlax-curve-getParamAtPoint 曲线 pt))<br/> (setq Pt1 (vlax-curve-getFirstDeriv 曲线 para))<br/> (setq ag (angle '(0 0) Pt1))<br/> ;;计算切线角<br/> ag<br/>)<br/>;;;-------------------------------------------------------------<br/>;;;在当前图层、当前空间画直线<br/>;;;调用形式 ( AddLine 起点坐标 终点坐标 ),如果成功,返回定义数据的图元表,否则返回 nil。<br/>(defun AddLine (listStartPoint listEndPoint)<br/> (entmake (list '(0 . "LINE")<br/> (cons 10 listStartPoint)<br/> (cons 11 listEndPoint)<br/> )<br/> )<br/>)<br/>;;;-------------------------------------------------------------<br/>;;;计算从角1到角2逆时针的角度差<br/>;;;返回0~2 pi的正值<br/>(defun AngleDelta ( fStartAngle fTargetAngle / fDelta)<br/> (setq fDelta (- fTargetAngle fStartAngle ))<br/> (if (< fDelta 0)<br/> (setq fDelta (+ fDelta (* 2 pi)))<br/> )<br/> fDelta<br/>)<br/>;;;-------------------------------------------------------------<br/>;;;在当前图层、当前空间画圆<br/>;;;调用形式 ( AddCircle 圆心坐标 半径 ),如果成功,返回定义数据的图元表,否则返回 nil。<br/>(defun AddCircle (listCenterPoint floatRadius)<br/> (entmake (list '(0 . "CIRCLE")<br/> (cons 10 listCenterPoint)<br/> (cons 40 floatRadius)<br/> )<br/> )<br/>)<br/>;;;------------------------------------------------------------------------<br/>;;;在当前图层、当前空间、按文本居中方式,写单行文本<br/>;;;调用形式 ( AddText_AlignmentMiddle 插入点坐标 字高 文本旋转角度(rad) 文本内容 宽高比例 字体样式名),如果成功,返回定义数据的图元表,否则返回 nil。<br/>(defun AddText_AlignmentMiddle (listInsertPoint floatTextHigh floatRotateAngle strText floatScaleFactor strStyleName)<br/> (entmake (list '(0 . "TEXT")<br/> '(10 0 0 0)<br/> (cons 11 listInsertPoint)<br/> (cons 40 floatTextHigh)<br/> (cons 1 strText)<br/> (cons 50 floatRotateAngle)<br/> (cons 41 floatScaleFactor)<br/> (cons 7 strStyleName)<br/> '(72 . 1)<br/> '(100 . "AcDbText")<br/> )<br/> )<br/>)<br/>;;;------------------------------------------------------------------------<br/>;;;在当前图层、当前空间、按文本左对齐方式,写单行文本<br/>;;;调用形式 ( AddText_AlignmentLeft 插入点坐标 字高 文本旋转角度(rad) 文本内容 宽高比例 字体样式名),如果成功,返回定义数据的图元表,否则返回 nil。<br/>(defun AddText_AlignmentLeft (listInsertPoint floatTextHigh floatRotateAngle strText floatScaleFactor strStyleName)<br/> (entmake (list '(0 . "TEXT")<br/> (cons 10 listInsertPoint)<br/> (cons 40 floatTextHigh)<br/> (cons 1 strText)<br/> (cons 50 floatRotateAngle)<br/> (cons 41 floatScaleFactor)<br/> (cons 7 strStyleName)<br/> '(100 . "AcDbText")<br/> )<br/> )<br/>)<br/>;;;------------------------------------------------------------------------<br/>;;;在当前图层、当前空间插入块<br/>;;;调用形式 ( InsertBlock 块名 插入点 旋转角度 )<br/>;;;成功时,返回dxf组码,否则返回nil<br/>(defun InsertBlock ( strBlockName listInsertPoint floatRotateAngle )<br/>(entmake (list '(0 . "INSERT")<br/>'(100 . "AcDbEntity")<br/>'(100 . "AcDbBlockReference")<br/>(cons 2 strBlockName)<br/>(cons 10 listInsertPoint)<br/>(cons 50 floatRotateAngle)))<br/> )<br/>;;;-------------------------------------------------------------<br/>;;;标记undo编组开始点<br/>(defun BeginUndoGroup()<br/> (command "undo" "be")<br/> )<br/>;;; -------------------------------------------------------------------------<br/>;;;标记undo编组结束点<br/>(defun EndUndoGroup()<br/> (command "undo" "e")<br/> )<br/>;;; -------------------------------------------------------------------------<br/>;;; -------------------------------------------------------------------------<br/>;;; -------------------------------------------------------------------------<br/>;;; -------------------------------------------------------------------------<br/>;;; -------------------------------------------------------------------------<br/>;;块统计.LSP</p>
<p> </p>
<p><br/>;;;--------------------------------------------------------------------------------<br/>;;;从块选择集中选择指定块名的对象,并返回结果选择集<br/>(defun intCountSingleBlock (ssOriginal strTargetBlockName /<br/> strEntityName listEntityDXF strBlockName intSingleBlockCount k)<br/> (setq intSingleBlockCount 0<br/> k -1 )<br/> (repeat (sslength ssOriginal) ; 循环与所选择的对象数量相等的次数<br/> (setq strEntityName (ssname ssOriginal (setq k (1+ k)))) ; strEntityName,取得第k个对象名<br/> (setq listEntityDXF (entget strEntityName))<br/> (setq strBlockName (cdr (assoc 2 listEntityDXF)))<br/> (if (= strBlockName strTargetBlockName)<br/> (setq intSingleBlockCount (1+ intSingleBlockCount))<br/> )<br/> )<br/> intSingleBlockCount<br/>)<br/>;;;--------------------------------------------------------------------------------<br/>;;;从块选择集中删除指定块名的对象,并返回结果选择集<br/>(defun ssDelEntitysFromBlockSelectionSet (ssOriginal strTargetBlockName<br/> / strEntityName listEntityDXF strBlockName ssResult k)<br/> (setq ssResult (ssadd)<br/> k -1 )<br/> (repeat (sslength ssOriginal) ; 循环与所选择的对象数量相等的次数<br/> (setq strEntityName (ssname ssOriginal (setq k (1+ k)))) ; strEntityName,取得第k个对象名<br/> (setq listEntityDXF (entget strEntityName))<br/> (setq strBlockName (cdr (assoc 2 listEntityDXF)))<br/> (if (/= strBlockName strTargetBlockName)<br/> (setq ssResult (ssadd strEntityName ssResult))<br/> )<br/> )<br/> ssResult<br/>)<br/>;;;--------------------------------------------------------------------------------<br/>;;;插入块缩略图<br/>(defun PrintBlockMiniature (floatBasicPointX floatBasicPointY strBlockName<br/> / floatMaxBlockWidth floatMaxBlockHigh<br/> floatBlockOriginalWidth floatBlockOriginalHigh floatBlockWidthScale<br/> floatBlockHighScale floatBlockBoundingBoxTargetMinPointX<br/> floatBlockBoundingBoxTargetMinPointY floatBlockBoundingBoxTargetMaxPointX<br/> floatBlockBoundingBoxTargetMaxPointY listTargetBlockCenterPoint<br/> listBlockBoundingBoxMinPoint listBlockBoundingBoxMaxPoint objectBlockEntity<br/> strEntityName listInsertPoint floatBlockScale<br/> listBlockEntityDXF listBlockCenterPoint<br/> )<br/> ;; floatBasicPointX floatBasicPointY 缩略图所在表格单元左下角点坐标<br/> ;;计算图块缩略图在图中允许放置范围的左下及右上角点坐标的X、Y数值<br/> (setq floatMaxBlockWidth 21<br/> floatMaxBlockHigh 8<br/> )<br/> (setq floatBlockBoundingBoxTargetMinPointX (+ floatBasicPointX 2)<br/> floatBlockBoundingBoxTargetMinPointY (+ floatBasicPointY 1)<br/> floatBlockBoundingBoxTargetMaxPointX (+ floatBasicPointX floatMaxBlockWidth 2)<br/> floatBlockBoundingBoxTargetMaxPointY (+ floatBasicPointY floatMaxBlockHigh 1)<br/> )<br/> (setq listTargetBlockCenterPoint (list (/ (+ floatBlockBoundingBoxTargetMinPointX floatBlockBoundingBoxTargetMaxPointX ) 2)<br/> (/ (+ floatBlockBoundingBoxTargetMinPointY floatBlockBoundingBoxTargetMaxPointY ) 2 )<br/> 0<br/> )<br/> )</p>
<p> (setq listInsertPoint (list floatBlockBoundingBoxTargetMinPointX floatBlockBoundingBoxTargetMinPointY ) )<br/> (InsertBlock strBlockName listInsertPoint 0)<br/> ;;以块缩略图允许放置范围的左下角点为块缩略图的基点插入图块</p>
<p> (setq strEntityName (entlast))<br/> (setq objectBlockEntity (vlax-ename->vla-object strEntityName))<br/> (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-GetBoundingBox <br/> (list objectBlockEntity 'listBlockBoundingBoxMinPoint 'listBlockBoundingBoxMaxPoint ))<br/> ) ;判断块是否存在边框,若块含无限长直线等时,则不存在边框<br/> (AddText_AlignmentMiddle listBlockCenterPoint 3 0 "本块无缩略图" 0.8 "hztxt")<br/> <br/> (progn<br/> (setq listBlockBoundingBoxMinPoint (vlax-safearray->list listBlockBoundingBoxMinPoint) )<br/> (setq listBlockBoundingBoxMaxPoint (vlax-safearray->list listBlockBoundingBoxMaxPoint) )<br/> <br/> (if (> (car listBlockBoundingBoxMaxPoint) (car listBlockBoundingBoxMinPoint) )<br/> (setq floatBlockWidthScale (/ floatMaxBlockWidth<br/> (- (car listBlockBoundingBoxMaxPoint) (car listBlockBoundingBoxMinPoint) ) <br/> )<br/> )<br/> (setq floatBlockWidthScale 0)<br/> )<br/> <br/> (if (> (cadr listBlockBoundingBoxMaxPoint) (cadr listBlockBoundingBoxMinPoint) )<br/> (setq floatBlockHighScale (/ floatMaxBlockHigh<br/> (- (cadr listBlockBoundingBoxMaxPoint) (cadr listBlockBoundingBoxMinPoint) )<br/> )<br/> )<br/> (setq floatBlockHighScale 0)<br/> )<br/> ;计算块缩略图允许放置范围的边框长宽与块外框长宽的比值<br/> <br/> (cond <br/> ((= (+ floatBlockWidthScale floatBlockHighScale) 0) (setq floatBlockScale 1)) ;块为单点时,缩放比例取为1<br/> ((= floatBlockWidthScale 0) (setq floatBlockScale floatBlockHighScale) ) ;块为竖直短线时<br/> ((= floatBlockHighScale 0) (setq floatBlockScale floatBlockWidthScale) ) ;块为水平短线时<br/> ((> floatBlockWidthScale floatBlockHighScale ) (setq floatBlockScale floatBlockHighScale) ) ;数值较小者为块的控制缩放比例<br/> (T (setq floatBlockScale floatBlockWidthScale) ) <br/> ) </p>
<p> (setq listBlockEntityDXF (entget strEntityName))<br/> (entmod (subst (cons 41 floatBlockScale) (assoc 41 listBlockEntityDXF) listBlockEntityDXF ) )<br/> (entupd strEntityName)</p>
<p> (setq listBlockEntityDXF (entget strEntityName))<br/> (entmod (subst (cons 42 floatBlockScale) (assoc 42 listBlockEntityDXF) listBlockEntityDXF ) )<br/> (entupd strEntityName)</p>
<p> (setq listBlockEntityDXF (entget strEntityName))<br/> (entmod (subst (cons 43 floatBlockScale) (assoc 43 listBlockEntityDXF) listBlockEntityDXF ) )<br/> (entupd strEntityName)<br/> ;;缩放块</p>
<p> (vla-GetBoundingBox objectBlockEntity 'listBlockBoundingBoxMinPoint 'listBlockBoundingBoxMaxPoint)<br/> (setq listBlockBoundingBoxMinPoint (vlax-safearray->list listBlockBoundingBoxMinPoint) )<br/> (setq listBlockBoundingBoxMaxPoint (vlax-safearray->list listBlockBoundingBoxMaxPoint) )<br/> (setq listBlockCenterPoint (list (* 0.5 (+ (car listBlockBoundingBoxMaxPoint) (car listBlockBoundingBoxMinPoint) ) )<br/> (* 0.5 (+ (cadr listBlockBoundingBoxMaxPoint) (cadr listBlockBoundingBoxMinPoint) ) )<br/> 0<br/> )<br/> )<br/> (vla-move objectBlockEntity (vlax-3d-point listBlockCenterPoint) (vlax-3d-point listTargetBlockCenterPoint))<br/> )<br/> )</p>
<p>)<br/>;;;--------------------------------------------------------------------------------<br/>;;;打印统计结果表<br/>(defun PrintCountResultList (listResult / i ListLength strBlockName<br/> intNumberOfSSSingleBlockName strNumberOfSSSingleBlockName pt pt1<br/> pt2 pt3 x y x1 y1<br/> x2 x3 floatTextHigh<br/> )<br/> (setq pt (getpoint "\n点取要标注块统计结果信息的位置:"))<br/> (setq x (car pt)<br/> y (cadr pt)<br/> i 0<br/> floatTextHigh 4<br/> )</p>
<p> (setq ListLength (length listResult))</p>
<p> (setq y1 (- y (* (1+ ListLength) 10))) ;行高取10<br/> (while (<= i 3)<br/> (setq x1 (+ x (* i 25))) ;列宽取25</p>
<p> (setq pt1 (list x1 y 0)<br/> pt2 (list x1 y1 0)<br/> )</p>
<p> (AddLine pt1 pt2)<br/> (setq i (1+ i))<br/> )<br/>;;;画竖向表格线</p>
<p> (setq i 0)<br/> (setq x1 (+ x (* 3 25)))<br/> (while (<= i (1+ ListLength))<br/> (setq y1 (- y (* i 10)))</p>
<p> (setq pt1 (list x y1 0)<br/> pt2 (list x1 y1 0)<br/> )</p>
<p> (AddLine pt1 pt2)<br/> (setq i (1+ i))<br/> )<br/>;;;画横向表格线</p>
<p>;;;------------------------------------------------------------------------<br/> (setq x1 (+ x (* 0.5 25))<br/> x2 (+ x (* 1.5 25))<br/> x3 (+ x (* 2.5 25))<br/> y1 (- y 7)<br/> )</p>
<p> (setq pt1 (list x1 y1 0)<br/> pt2 (list x2 y1 0)<br/> pt3 (list x3 y1 0)<br/> )</p>
<p> (AddText_AlignmentMiddle pt1 floatTextHigh 0 "块缩略图" 0.8 "hztxt")<br/> (AddText_AlignmentMiddle pt2 floatTextHigh 0 "块名称" 0.8 "hztxt")<br/> (AddText_AlignmentMiddle pt3 floatTextHigh 0 "块数量" 0.8 "hztxt")<br/> ;;输出表头<br/>;;;------------------------------------------------------------------------<br/> (setq i 0<br/> floatTextHigh 3 )<br/> (while (< i ListLength)<br/> (setq y1 (+ y (* -10 (+ i 2))))</p>
<p> (setq ;pt1 (list x1 y1 0)<br/> pt2 (list x2 (+ y1 3) 0)<br/> pt3 (list x3 (+ y1 3) 0)<br/> )</p>
<p> (setq strBlockName (car (nth i listResult))<br/> intNumberOfSSSingleBlockName (cadr (nth i listResult))<br/> )<br/> (setq strNumberOfSSSingleBlockName (itoa intNumberOfSSSingleBlockName))</p>
<p> (AddText_AlignmentMiddle pt2 floatTextHigh 0 strBlockName 0.8 "hztxt")<br/> (AddText_AlignmentMiddle pt3 floatTextHigh 0 strNumberOfSSSingleBlockName 0.8 "hztxt")<br/> <br/> (if (vl-catch-all-error-p (vl-catch-all-apply 'PrintBlockMiniature (list x y1 strBlockName)))<br/> (AddText_AlignmentLeft (list (+ x 1) (+ y1 2)) 3 0 "生成块缩略图时出错" 0.8 "hztxt")<br/> )</p>
<p> (setq i (1+ i))<br/> )<br/>;;;打印表内容<br/>)<br/>;;;--------------------------------------------------------------------------------<br/>(defun GetBlocksSelectionRange (/ strDCLFileName listInputDefinements listKeysAndValues listKeysAndActions listKeysToGetValue<br/> listDCLReturn intButtonClick strSelectRange)</p>
<p> (setq strSelectRange "UserSelection" )<br/> (setq strDCLFileName "BlocksSelectionRange")<br/> (setq listInputDefinements '(("dialog" "指定统计范围" "")<br/> ("spacer")<br/> ("radio_column" "进行块统计的范围:")<br/> ("btRadio" "手工选择" "brUserSelection")<br/> ("btRadio" "整个图形" "brDrawingFile")<br/> ("end")<br/> ("text" "注:不统计含无限长直线的块!")<br/> ("spacer")<br/> ("btOK")<br/> ("end")<br/> )<br/> )<br/> (setq listKeysAndValues '(("brUserSelection" "1")))<br/> (setq listKeysAndActions '(("brUserSelection" "(setq strSelectRange \"UserSelection\")")<br/> ("brDrawingFile" "(setq strSelectRange \"DrawingFile\")")) )<br/> (setq listKeysToGetValue nil)</p>
<p> (setq listDCLReturn (listGenerateDCL strDCLFileName listInputDefinements listKeysAndValues listKeysAndActions listKeysToGetValue) )<br/> (setq intButtonClick (car listDCLReturn ) )<br/> strSelectRange<br/>)<br/>;;;--------------------------------------------------------------------------------<br/>;;;块数量统计<br/>(defun tktj (/ ssObjects strEntityName listEntityDXF strBlockName<br/> listResult intSingleBlockCount listMinPoint listInsertPoint floatBlockRotateAngle<br/> ;;listResult 用于记录统计结果,形式为(( 块名 块数量 同名块中一个实体的对象名 )...)<br/> )<br/>; (initget "D S _DrawingFile UserSelection")<br/>; (setq strSelectRange (getkword "\n统计块的范围[全图(D)/选择(S)]<S>:"))<br/> (setq strSelectRange (GetBlocksSelectionRange))</p>
<p> (if (= strSelectRange "DrawingFile")<br/> (setq ssObjects (ssget "X" '((0 . "insert")(100 . "AcDbBlockReference")))) ; 创建选择集 ssObjects</p>
<p> (progn<br/> (princ "\n请选择需要统计的块:\n")<br/> (setq ssObjects (ssget '((0 . "INSERT")(100 . "AcDbBlockReference")))) ; 创建选择集 ssObjects<br/> )<br/> )</p>
<p> (if ssObjects<br/> (progn<br/> (setq listResult nil)<br/> (while (> (sslength ssObjects) 0)<br/> (setq strEntityName (ssname ssObjects 0)) ; strEntityName,取得第1个对象名<br/> (setq listEntityDXF (entget strEntityName))<br/> (setq strBlockName (cdr (assoc 2 listEntityDXF)))<br/> (setq intSingleBlockCount (intCountSingleBlock ssObjects strBlockName ) )<br/> (setq ssObjects (ssDelEntitysFromBlockSelectionSet ssObjects strBlockName))</p>
<p> (setq listResult (append listResult<br/> (list (list strBlockName intSingleBlockCount))<br/> )<br/> )<br/> )</p>
<p> (setvar "dimzin" 8)<br/> (setvar "osmode" 0)<br/> (if (tblsearch "style" "hztxt")<br/> ;;判断是否存在"hztxt"字体,有则设为当前,无则创建。<br/> (setvar "textstyle" "hztxt")<br/> (command "_style" "hztxt" "sceie.shx,sceic.shx" 0 0.8 0 "N" "N" "N")<br/> )</p>
<p> (PrintCountResultList listResult)<br/> (setvar "osmode" 16383)<br/> )<br/> )</p>
<p> (princ)<br/>)</p>
<p><br/>(defun c:ktj()(dim_scei_tktj))<br/>;;;--------------------------------------------------------------------------------</font></p> 感谢分享真正的源码。
打击“伪货、伪人、伪**。。。人人有责”!
不提示需要另外的函数的伪代码就是耍流氓,骗币!
花了钱下载下来之后缺这个少那个,又不明说,真的是耍流氓!
分享还有什么意义!
估计坛友们用过会来上那么一句吧,嘎嘎.... 感谢分享,收藏了,这些函数说不定哪天就能用上 好東西,謝謝分享,感謝!!! 感谢分享真正的源码。 打击“伪货、伪人、伪**。。。人人有责”! <p>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div id="textstyle_2" style="FONT-SIZE: 12pt; OVERFLOW: hidden; WORD-BREAK: break-all; TEXT-INDENT: 0px; WORD-WRAP: break-word">感谢分享真正的源码。 </div></td></tr></tbody></table>可惜刚开始学,不知道怎么调用,:-)希望大虾们稍微讲解一下!解惑。。</p> <p>最后一行改成</p>
<p>(defun c:ktj() (tktj))<br/></p> 不是很好用 非常不错,支持源码,下下来学学 狂好的软件!喜欢 <p>谢谢分享</p>
<p> </p> 感謝樓主無私分享