- 积分
- 90249
- 明经币
- 个
- 注册时间
- 2005-3-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2010-7-19 16:29:00
|
显示全部楼层
下面的程序就可以!- (defun C:MakeShape(/ f1 CT)
- (defun ShapeName (sfn / ofn n k k1 zc$ zc1$ spn zs ID_shape)
- (setq ofn (open sfn "r") n 0 ID_Shape '())
- (while (setq zc$ (read-line ofn))
- (if (eq (substr zc$ 1 1) "*")
- (progn
- (setq n (1+ n) k (strlen zc$) k1 1 spn "" dh 0)
- (repeat k
- (setq zc1$ (substr zc$ k1 1))
- (if (= zc1$ ";") (setq zs T zc1$ ""))
- (if (< dh 2)
- (if (eq "," zc1$) (setq dh (1+ dh)))
- (if zs
- ()
- (setq spn (strcat spn zc1$))
- )
- );if
- (setq k1 (1+ k1))
- );repeat
- (if (/= "" spn) (setq ID_Shape (cons spn ID_Shape)))
- );progn
- );if
- );while
- (close ofn)
- (setq ID_Shape (reverse ID_Shape))
- )
- ;(setIerr)
- (setq CT T)
- (while (not (setq fina1 (getfiled "形文件名" "" "shp" 1)))
- (abcdefg)
- )
- (if (setq f1 (open fina1 "r"))
- (progn
- (setq ID_Shape (shapeName fina1))
- (close f1)
- );progn
- (setq ID_Shape '())
- );if
- (setq fs (open fina1 "a"))
- (while Ct
- (setq su (1+ (length ID_SHAPE)))
- ; (princ su)
- ;(princ (strcat "\nNumber = " (itoa su)))
- (while (= "" (setq fina (strcase (getstring "\n请输入拟生成的形名 : "))))
- (alert "\n请输入拟生成的形名 : ")
- )
- (while (member fina ID_Shape)
- (PrinC "\n这个形名已经存在了!")
- (while (= "" (setq fina (strcase (getstring "\n请重新起名..."))))
- (alert "\n请输入拟生成的形名 : ")
- )
- )
- (setq ID_SHAPE (cons fina ID_SHAPE))
- (if (> (length ID_SHAPE) 255) (abcdefg))
-
- ;|(while (not (setq su (getint "\n请输入拟生成的形文件编号(1 - 255) :")))
- (alert "\n请输入拟生成的形文件编号(1 - 255) :")
- )
- |;
- (setq fst nil snd nil k 0 p1 nil)
- (setq fst (getpoint "\n请输入欲生成形文件的图形区域的一个角点 : "))
- (setq snd (getcorner fst "\n请输入欲生成形文件的图形区域的另一个角点 : "))
- (initget 7 "Yes No ")
- (setq a$ (strcase (getKword "\n坐标值为整数吗?(Yes/No)<N>")))
- (if (= a$ "") (setq a$ "No"))
- (if (= a$ "Yes")
- (setq k1$ 125)
- (progn
- (setq k$ (distance fst snd))
- (setq p1 (getpoint "\n最长图形目标的一个端点 :"))
- (if (/= p1 nil)
- (setq k1$ (getdist p1 "\n最长图形目标的另一个端点 :"))
- (setq k1$ k$)
- )
- )
- )
- (setq dd$ (fix (/ 125 k1$)))
- (setq dd$ (if (= dd$ 0) 1 dd$))
- (if (> dd$ 125) (setq dd$ 125))
- (setq a (ssget "c" fst snd))
- (setq count 3)
- (setq nu (sslength a))
- (while (< k nu)
- (setq enta (entget (ssname a k)))
- (setq b$ (cdr (assoc 0 enta)))
- (if (or (= b$ "POLYLINE") (= b$ "LWPOLYLINE"))
- (explo)
- (if (= b$ "BLOCK")
- (explo)
- (if (= b$ "INSERT")
- (explo)
- )
- )
- )
- (setq k (1+ k))
- )
- (setq k 0)
- (setq a (ssget "c" fst snd))
- (setq nu (sslength a))
- (while (< k nu)
- (setq enta (entget (ssname a k)))
- (setq b$ (cdr (assoc 0 enta)))
- (if (= b$ "LINE")
- (setq count (+ 8 count))
- (if (= b$ "ARC")
- (setq count (+ 15 count))
- (if (= b$ "VERTEX")
- (setq count (+ 2 count))
- (if (= b$ "CIRCLE")
- (setq count (+ 12 count))
- )
- )
- )
- )
- (setq k (1+ k))
- )
- ;(setq fina1 (getfiled "形文件名" "" "shp" 1))
- ; (setq fs (open fina1 "a"))
- (setq b$ (strcat "*" (itoa su) "," (itoa count) "," fina))
- (write-line b$ fs)
- (setq a$ (strcat "3," (itoa dd$) ","))
- (write-line a$ fs)
- ;(setq p3 (cdr (assoc 10 (entget (ssname a 0)))))
- (setq p3 (getpoint "\n选择插入基点 :"))
- (setq k 0)
- (while (< k nu)
- (setq e (entget (ssname a k)))
- (setq estr (cdr (assoc 0 e)))
- (if (= estr "LINE")
- (progn
- (setq p1 (cdr (assoc 10 e)))
- (setq dx1 (fix1 (mul (- (car p1) (car p3)))))
- (setq dy1 (fix1 (mul (- (cadr p1) (cadr p3)))))
- (setq p2 (cdr (assoc 11 e)))
- (setq dx (fix1 (mul (- (car p2) (car p1)))))
- (setq dy (fix1 (mul (- (cadr p2) (cadr p1)))))
- (setq a$ (strcat "2,8," (itoa dx1) "," (itoa dy1) ","))
- (setq b$ (strcat "1,8," (itoa dx) "," (itoa dy) ","))
- (setq c$ (strcat a$ b$))
- (write-line c$ fs)
- (setq p3 p2)
- )
- (if (= estr "CIRCLE")
- (progn
- (setq p1 (cdr (assoc 10 e)))
- (setq r1 (cdr (assoc 40 e)))
- (setq r (fix (+ 0.5 (mul r1))))
- (setq dx (fix1 (mul (+ r1 (- (car p1) (car p3))))))
- (setq dy (fix1 (mul (- (cadr p1) (cadr p3)))))
- (setq a$ (strcat "2,8," (itoa dx) "," (itoa dy) ","))
- (setq b$ (strcat "1,10,(" (itoa r) ",000),"))
- (setq c$ (strcat "2,8,-" (itoa r) ",0"))
- (write-line (strcat a$ b$ c$) fs)
- (setq p3 p1)
- )
- (if (= estr "ARC")
- (progn
- (setq p1 (cdr (assoc 10 e)))
- (setq sa1 (cdr (assoc 50 e)))
- (setq ea1 (cdr (assoc 51 e)))
- (setq r1 (cdr (assoc 40 e)))
- (setq dx (fix1 (mul (+ (* r1 (cos sa1))
- (- (car p1) (car p3))))))
- (setq dy (fix1 (mul (+ (* r1 (sin sa1))
- (- (cadr p1) (cadr p3))))))
- (setq r (fix (+ 0.5 (mul r1))))
- (setq sad (rtd sa1) ead (rtd ea1))
- (setq saa (/ sad 45))
- (setq eaa (/ ead 45))
- (setq sa0 (fix saa) ea0 (fix eaa))
- (setq sa (fix (+ 0.5 (/ (* (rem sad 45) 256) 45))))
- (setq ea (fix (+ 0.5 (/ (* (rem ead 45) 256) 45))))
- (if (= 0 (rem ead 45))
- (setq ea0 (1- ea0))
- )
- (if (= 256 sa)
- (setq sa 0 sa0 (1+ sa0))
- )
- (if (= 256 ea)
- (setq ea 0)
- )
- (if (> sad ead)
- (setq c (+ 9 (- ea0 sa0)))
- (setq c (+ 1 (- ea0 sa0)))
- )
- (if (= 8 sa0) (setq sa0 0))
- (if (> r (* dd$ 255))
- (setq rr r)
- (setq rr 0)
- )
- (setq a$ (strcat "2,8,"
- (itoa dx) ","
- (itoa dy) ","))
- (setq b$ (strcat "1,11,("
- (itoa sa) ","
- (itoa ea) ","
- (itoa rr) ","
- (itoa r) ",0"
- (itoa sa0)
- (itoa c) "),"))
- (setq dx1 (- 0 (fix1 (mul (* r1 (cos ea1))))))
- (setq dy1 (- 0 (fix1 (mul (* r1 (sin ea1))))))
- (setq c$ (strcat "2,8,"
- (itoa dx1) ","
- (itoa dy1) ","))
- (write-line (strcat a$ b$ c$) fs)
- (setq p3 p1)
- )
- )
- )
- )
- (setq k (1+ k))
- )
- (write-line "0" fs)
- (initget 7 "Yes No ")
- (setq k$ (getkword "\n继续制作形文件?[<Yes>/<No>]<Yes>:"))
- (if (or (= "Yes" k$) (= "" K$))
- (setq CT T)
- (setq CT nil)
- )
- );while
- (close fs)
- ;(reerr)
- )
|
|