程序搜索选定图层上的所有多段线。
对于初学者,请尝试以下方法:
- (defun c:aa () ; V : 13.01.2013 ; 12.01.2013 .
- (setvar "cmdecho" 0)
- (setq osm (getvar "osmode") )
- (setvar "osmode" 0)
- (if (setq ht 0.2 lsel 0 ob (car (entsel "\n Select an Object for LAYER : < Pick > : ")) )
- (progn
- (command "zoom" "e")
- (setq str (cdr (assoc 8 (entget ob)) ) sel (ssget "X" (list '(0 . "LWPOLYLINE,POLYLINE") (cons 8 str)) ) ) ;
- (if sel
- (progn
- (command "zoom" "o" sel "") (sssetfirst nil sel) ; Selectare Vizualizare Selectie !
- (if (/= (getstring (strcat "\n SELECTED objects on LAYER : " str " ;\n Any = NO ; Enter = OK : ")) "") (setq sel nil))
- (sssetfirst sel) ; DeSelectare Vizualizare Selectie !
- ) ) ; if sel
- (if sel
- (progn (or (vl-load-com))
- (setq lsel (sslength sel) cale (strcat (getvar "dwgprefix") (getvar "dwgname") " - " (rtos (getvar "cdate") 2 6) ".csv")
- f (open cale "w") i 0)
- (write-line "\nLabel, Area\n-------------------------------" f)
- (while (< i lsel)
- (setq nobi (ssname sel i) nobv (vlax-ename->vla-object nobi) ar (vla-get-Area nobv) ars (rtos ar 2 5) i (1+ i)
- lc (vlax-safearray->list (vlax-variant-value (vla-get-Coordinates nobv))) llc (length lc) n (/ llc 2.) j 0 sx 0 sy 0)
- (while (< j llc) (setq sx (+ (nth j lc) sx) j (1+ j) sy (+ (nth j lc) sy) j (1+ j) ) ) ; wh
- (command "text" "m" (list (/ sx n) (/ sy n) 0) ht 0 (strcat "\n Area " (itoa i) " = " ars))
- (princ (strcat "\n Area " (itoa i) " : " ars))
- (write-line (strcat "Area " (itoa i) ", " ars) f)
- ) ; wh <
- (if (and cale (findfile cale)) (close f))
- ) ) ; if sel
- )) ; if ob
- (setvar "osmode" osm)
- (setvar "cmdecho" 1)
- (princ (strcat "\n Height of Texts : " (rtos ht 2 5)
- "\n Number of Areas : " (itoa lsel) " ."))
- (princ "\n END !")(princ)
- ) ; end defun c:aa
该程序不直接在Excel中编写,但您可以打开结果文件。带Excel的CSV。CSV文件保存到DWG路径。
要在Excel中编写内容,需要一个函数来打开并写入Excel,这更为复杂。
简单明了。仅处理选定层。不检查不同:
-如果多段线有2个顶点,面积为0;
-不要检查多段线是否闭合;
-高度文本;
-开始写标签;
-等等。
Lisp程序大约用了30分钟。 |