gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15946
  • QQ554730525
  • 铜币25338枚
  • 威望15363点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:3323回复:4

等高线圆滑拟合

楼主#
更多 发布于:2004-07-15 14:58
将源代码粘贴到写字板里,后缀改为LSP:
(defun c:ni()
(load"qx")
(command"layer""unlock" "dgx" "")
;(command"zoom" "e")
(c:LWPOLYLINE)
(setq ent (ssget "x" '((8 . "dgx")(0 . "POLYLINE"))))
(if ent (progn
(setq long-ent (sslength ent))
(setq num-ent 0)
(write-line"\n   ***正在拟合等高线.....")
(repeat long-ent
(setq ty (ssname ent num-ent))
;(Setq ty (car (entsel)))
(c:get-yuanma)
(c:get-listnew)
(c:regen-line)
(setq num-ent (1+ num-ent))
)
(write-line"\n  拟合完毕,请检查大拐弯处是否有点线矛盾!")
);progn
(write-line"\n 图形中没有等高线")
);if
(print)
)

(defun c:get-yuanma()
(command"pedit" ty "d" "")
(c:max-min)
(Setq data-dgx (entget ty))
(setq tc (assoc 8 data-dgx)
line-type (assoc 6 data-dgx)
width (cdr (assoc 40 data-dgx))
thi (cdr (assoc 39 data-dgx))
color (cdr (assoc 62 data-dgx))
)
)

(defun c:LWPOLYLINE()
(setq ent (ssget"x" '((8 . "dgx")(0 . "LWPOLYLINE"))))
(if ent (progn
(setq long-ent (sslength ent))
(setq num-ent 0)
(repeat long-ent
(setq ty (ssname ent num-ent))
(command"pedit" ty "f" "")
(setq num-ent (1+ num-ent))
)
))
)

(defun c:get-listnew() ;减掉过密顶点
(setq long-new (length list-p))
(Setq p-listnew (list (car list-p)))
(setq num-new 0 k 0)
(setq p1 (nth num-new list-p))
(setq num-new (1+ num-new))
(while (setq p2 (nth num-new list-p))
(setq dis (distance p1 p2))
(if (< dis 5.0) (progn
(setq num-new (1+ num-new))
(while (and (< dis 5.0)(> long-new num-new))
(setq p2 (nth num-new list-p))
(setq dis (distance p1 p2))
(setq num-new (1+ num-new))
)
(setq p-listnew (append p-listnew (list p2)))
);progn
(setq p-listnew (append p-listnew (list p2)))
)
(setq p1 p2)
(setq num-new (1+ num-new))
);while
(setq d-end (distance (last p-listnew) (last list-p)))
(if (/= 0 d-end)
(setq p-listnew (append p-listnew (list (last list-p))))
)
);defun

(defun c:regen-line()
(command"erase" ty "")
(command "pline")
(apply 'command p-listnew)
(command "")
(command"pedit" (entlast) "w" width "s" "")
(command"change" (entlast) "" "p" "t" thi "")
(setq data-line (entget (entlast)))
(setq tc-old (assoc 8 data-line)
line-typeold (assoc 6 data-line)
)
(setq da (subst line-type line-typeold data-line))
(entmod da)
(setq da (subst tc tc-old data-line))
(entmod da)
(if color (command"change" (entlast) "" "p" "c" color ""))
)
喜欢0 评分0
shengl
路人甲
路人甲
  • 注册日期2004-09-02
  • 发帖数1
  • QQ
  • 铜币107枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-09-02 16:09
gis你不是什么语言都搞吧?
举报 回复(0) 喜欢(0)     评分
hexiaoming
路人甲
路人甲
  • 注册日期2003-11-10
  • 发帖数57
  • QQ
  • 铜币160枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-09-17 11:47
<img src="images/post/smile/dvbbs/em05.gif" />
举报 回复(0) 喜欢(0)     评分
wzjtxz
路人甲
路人甲
  • 注册日期2008-03-01
  • 发帖数7
  • QQ
  • 铜币121枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2009-04-19 14:03
在CAD中加载成功后,命令行提示:错误: 参数类型错误: numberp: nil
举报 回复(0) 喜欢(0)     评分
wzjtxz
路人甲
路人甲
  • 注册日期2008-03-01
  • 发帖数7
  • QQ
  • 铜币121枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2009-04-19 14:05
<P>(defun c:zhxx();转换新线形</P>
<P>(prompt "请选择线: ")<BR>(setq object (entsel))<BR>    (SETQ SSS (ssget "x" '((-4 . "<OR") <BR>           (0 . "LWPOLYLINE") <BR>    (0 . "POLYLINE")<BR>             (-4 . "OR>"))<BR>     ))<BR>   (setq i 0)<BR>   (if sss<BR>      (while (< i (sslength sss))<BR>        (setq OBJ (ssname sss i))<BR>       (huan2)<BR>            (setq i (+ i 1))<BR>   ) ;WHILE<BR>  ) ;IF SSS</P>
<P> (setq b  (itoa  i) )<BR> (setq b1 (strcat "图中共检查修改旧line线划有:"  b   "条"  ) )</P>
<P>)</P>
<P><BR>(defun huan2()<BR>(setvar "CMDECHO" 0)<BR>   (command"osnap" "off")<BR>(setq obj_38 nil)<BR>   (setq  obj_b(entget obj  '("SHANXI" "SOUTH")))<BR>   (setq obj_la (cdr(assoc 8 obj_b)))<BR>   (setq obj_lt (cdr(assoc 6 obj_b)))<BR>   (setq obj_color (cdr(assoc 62 obj_b)))<BR>   (setq obj_70 (cdr(assoc 70 obj_b)))<BR>   (setq obj_40 (cdr(assoc 40 obj_b)))<BR>   (setq obj_38 (cdr(assoc 38 obj_b)))<BR>   (if(= obj_38 nil)<BR>     (setq obj_38 (nth 2 (cdr(assoc 10 obj_b))))<BR>    )<BR>   (setq obj_xdata (assoc -3 obj_b) )<BR>   (command "layer" "S" obj_la "") <BR>   (setq  obj_b (qd_b1 obj) ) <BR>   (setq nnn(length obj_b))<BR>   (setq j (- nnn 1))<BR>   (if(or(= obj_70 5)(= obj_70 133)) (setq nnn (- nnn 1)))<BR>   (setq p0(nth j obj_b))<BR>   (command "pline")<BR>   (repeat nnn<BR>     (setq p1(nth j obj_b))<BR>     (command p1)<BR>     (setq j (- j 1))<BR>   )<BR>      (if( /= (/ obj_70 2) (/ obj_70 2.0) ) <BR>    (command p0))<BR>  (command)<BR>  (command"erase" obj "")<BR> <BR>  (if (/= obj_lt nil)(command"change" (entlast) "" "p" "lt" obj_lt "")  )<BR>  (if (/= obj_color nil) (command"change" (entlast) "" "p" "c" obj_color "")  )<BR>  (if (/= obj_40 nil) (command"pedit" (entlast) "w" obj_40 "")  )<BR>  (if (/= obj_38 nil) (command"change" (entlast) "" "p" "e" obj_38 "")  )</P>
<P>  (setq object  (entget (entlast)))</P>
<P>   (if (/= obj_xdata nil)(progn<BR>   (setq xdata (list obj_xdata))<BR>   (setq nent (append object  xdata))<BR>   (entmod nent) <BR> ))<BR> (setq object (entlast) ) <BR>)</P>
<P>(defun huan3()<BR>(setvar "CMDECHO" 0)<BR>   (command"osnap" "off")<BR>(setq obj_38 nil)<BR>   (setq  obj_b(entget obj  '("SHANXI" "SOUTH")))<BR>   (setq obj_la (cdr(assoc 8 obj_b)))<BR>   (setq obj_lt (cdr(assoc 6 obj_b)))<BR>   (setq obj_color (cdr(assoc 62 obj_b)))<BR>   (setq obj_70 (cdr(assoc 70 obj_b)))<BR>   (setq obj_40 (cdr(assoc 40 obj_b)))<BR>   (setq obj_38 (cdr(assoc 38 obj_b)))<BR>   (if(= obj_38 nil)<BR>     (setq obj_38 (nth 2 (cdr(assoc 10 obj_b))))<BR>    )<BR> <BR>  (setq obj_xdata (assoc -3 obj_b) )<BR>   (command "layer" "S" obj_la "") </P>
<P>   (setq  obj_b (qd_b1 obj) ) <BR>   (setq nnn(length obj_b))<BR>   (setq j 0)<BR>   (if(or(= obj_70 5)(= obj_70 133)) (setq nnn (- nnn 1)))<BR>   (setq p0(nth j obj_b))<BR>   (command "pline")<BR>   (repeat nnn<BR>     (setq p1(nth j obj_b))<BR>     (command p1)<BR>     (setq j (+ j 1))<BR>   )<BR>   <BR>   (if( /= (/ obj_70 2) (/ obj_70 2.0) ) <BR>    (command p0))<BR>  (command)<BR>  (command"erase" obj "")<BR> <BR>  (if (/= obj_lt nil)(command"change" (entlast) "" "p" "lt" obj_lt "")  )<BR>  (if (/= obj_color nil) (command"change" (entlast) "" "p" "c" obj_color "")  )<BR>  (if (/= obj_40 nil) (command"pedit" (entlast) "w" obj_40 "")  )<BR>  (if (/= obj_38 nil) (command"change" (entlast) "" "p" "e" obj_38 "")  )</P>
<P>  (setq object  (entget (entlast)))</P>
<P>   (if (/= obj_xdata nil)(progn<BR>   (setq xdata (list obj_xdata))<BR>   (setq nent (append object  xdata))<BR>   (entmod nent) <BR> ))<BR> (setq object (entlast) ) <BR>)</P>
<P><BR>(defun qd_b1(obj_1971);    获取新旧线坐标<BR>  (setq dxfb_1971(entget obj_1971))<BR>  (setq obty_1971 (cdr (assoc 0 dxfb_1971)) )<BR>  (SETQ DB_PL '())<BR>  (Cond<BR>    ((= obty_1971 "POLYLINE")  <BR>      (setq obj_1971 (entnext obj_1971))<BR>      (setq dxfb_1971 (entget obj_1971)) <BR>      (setq po_1971 (cdr (assoc  10  dxfb_1971)))<BR>      (SETQ DB_PL '())<BR>      (while (/= (cdr (assoc 0 dxfb_1971)) "SEQEND")<BR>        (setq po_1971(list (nth 0 po_1971) (nth 1 po_1971) (nth 2 po_1971)))<BR>            (SETQ DB_PL(APPEND DB_PL (list po_1971)))<BR>        (setq obj_1971 (entnext obj_1971))<BR>        (setq dxfb_1971 (entget obj_1971)) <BR>        (while(= (cdr (assoc 70 dxfb_1971)) 16) <BR>          (setq obj_1971 (entnext obj_1971))<BR>          (setq dxfb_1971 (entget obj_1971)) <BR>          )<BR>        (setq po_1971 (cdr (assoc  10  dxfb_1971)))<BR>           )<BR>        )<BR>    ((= obty_1971 "LWPOLYLINE")<BR>       (SETQ NNN(length dxfb_1971))<BR>         (SETQ K 0)<BR>         (SETQ DB_PL '())<BR>         (REPEAT NNN<BR>           (SETQ po_1971 (NTH K dxfb_1971))<BR>           (if(= (car po_1971) 10)<BR>             (setq DB_PL(append DB_PL (list (cdr po_1971))))<BR>             )<BR>           (SETQ K (+ K 1))<BR>           )<BR>        )<BR>      </P>
<P>    ((= obty_1971 "LINE")<BR>       (SETQ NNN(length dxfb_1971))<BR>         (SETQ K 0)<BR>         (SETQ DB_PL '())<BR>         (REPEAT NNN<BR>           (SETQ po_1971 (NTH K dxfb_1971))<BR>           (if( or (= (car po_1971) 10)(= (car po_1971) 11))<BR>             (setq DB_PL(append DB_PL (list (cdr po_1971))))<BR>             )<BR>           (SETQ K (+ K 1))<BR>           )<BR>        )<BR>      )</P>

<P>  DB_PL<BR>)</P>

<P><BR>(defun c:dgxxg();等高线连接修改<BR>   (command "osnap" "off")<BR>   (prompt "选择实体的断点处")<BR>   (setq obj1(entsel))<BR>   (setq ob_pp (car (cdr obj1)))<BR>   (setq obja (car obj1))<BR>   (SETQ OBJC OBJA)    (setq  obj_b(entget obja))<BR>   (setq obj_la (cdr(assoc 8 obj_b)))    (setq obj_lt (cdr(assoc 6 obj_b)))<BR>   (setq wid (cdr(assoc 40 obj_b)))    (setq w38 (cdr(assoc 38 obj_b)))<BR>   (setq c70 (cdr(assoc 70 obj_b))) <BR>   (if (= c70 129) (setq c70 1))<BR>   (command"linetype" "s" obj_lt "")    (command"layer" "s" obj_la "")<BR>   (setq p1 (list (nth 0 ob_pp) (nth 1 ob_pp)))  <BR>  ; (command "pedit" obja "d" "x")<BR>   (setq ssb (ssget "x" (LIST (cons 0 "polyline,lwpolyline")(cons 38 w38)(cons 8 obj_la))))<BR>   (setq i 0) (if ssb (while (< i (sslength ssb))  (redraw (ssname ssb i) 3) (setq i (+ i 1)) ))    <BR>   (plin2a)<BR>   (setq i 0) (if ssb (while (< i (sslength ssb))  (redraw (ssname ssb i) 4) (setq i (+ i 1)) ))    <BR>   (setq ssb nil)<BR>   (setq vwi (getvar "VIEWSIZE"))<BR>   (setq pzjl (/  vwi 50))</P>
<P>   (setq zbd nil)  (setq zbd (qd_b1 object) ) <BR>   (setq pb1 (nth 0 zbd))<BR>   (setq pb2 (nth (- (length zbd) 1) zbd))    </P>
<P> ''''''''''''<BR>   (setq zbb nil)  (setq zbb (qd_b1 obja) ) <BR>   (if (= c70 1)  (setq zbb (append zbb (list (nth 0 zbb)))) ) <BR>   (if (equal (nth 0 zbb) (nth (- (length zbb) 1) zbb) 1)  (setq c70 1))<BR>   (setq p1 pb1) (setq i 1)  (jdjs) (setq ds i)<BR>   (setq jda (/ (* (angle (nth (- i 1) zbb) (nth i zbb)) 180) pi))<BR>   (setq jdb (/ (* (angle (nth 0 zbd) (nth 1 zbd)) 180) pi))<BR>   (setq jdc (- jda jdb))<BR>   (if (< jdc 0) (setq jdc (- 0 jdc)))<BR>   (if (> jdc 180) (setq jdc (- 360 jdc)))<BR>   (setq xxfz 0)<BR>   (if (> jdc 90) (progn (setq zbb (reverse zbb)) (setq ds (- (length zbb) ds)) (setq xxfz 1) ))  <BR>   (if (= c70 1) (progn<BR>    (setq zbs '()) (setq i (- ds 1))<BR>    (repeat (- (length zbb) ds) (setq zbs (append zbs (list (nth i zbb)))) (setq i (+ i 1)))<BR>    (setq i 0)<BR>    (repeat ds (setq zbs (append zbs (list (nth i zbb)))) (setq i (+ i 1)))<BR>    (setq zbb zbs) (setq zbs nil) (setq ds 1)<BR>   ))</P>
<P>   (setq zb '())<BR>   (setq i 0) (repeat (- ds 1)  (setq zb (append zb (list (nth i zbb))))   (setq i (+ 1 i))  )<BR>   (entdel object) (setq i 0) (command "pline") (command (nth (- ds 1) zbb))<BR>   (repeat (length zbd)   (command (nth i zbd))  (setq i (+ i 1)) )  (command "")<BR>   (setq object (entlast))   (setq zbd nil)  (setq zbd (qd_b1 object) ) <BR>   (setq jdzb nil)<BR>   (setq q1 (polar pb2 3.97 pzjl))  (setq q2 (polar pb2 0.83 pzjl)) <BR>   (setq ssa (ssget "c" q1 q2 (LIST (cons 0 "polyline,lwpolyline")(cons 38 w38)(cons 8 obj_la))))<BR>   (if ssa (if (ssmemb object ssa)  (setq ssa (ssdel object ssa)) ) )<BR>   (if ssa (if (= (sslength ssa) 0) (setq ssa nil)))<BR>   (if ssa<BR>   (if (ssmemb obja ssa)<BR>    (progn '''同一实体<BR>      (setq p1 pb2) (setq i ds)  (jdjs)  (setq ds1 i)<BR>      (entdel object) (setq i 0) (command "pline")    <BR>      (repeat (- (length zbd) 1)   (command (nth i zbd))  (setq i (+ i 1)) )   <BR>      (command jdzb)  (command (nth ds1 zbb))(command "")<BR>      (setq object (entlast))   (setq zbd nil)  (setq zbd (qd_b1 object) ) <BR>   )<BR>   (progn  '''不同实体<BR>      (setq OBJb (ssname ssa 0))     <BR>      (setq zbb nil)<BR>      (setq zbb (qd_b1 objb) ) <BR>      (setq p1 pb2) (setq i 1)  (jdjs)  (setq ds1 i)<BR>      (setq jda (/ (* (angle (nth (- i 1) zbb) (nth i zbb)) 180) pi))<BR>      (setq zbdl (- (length zbd) 1))<BR>      (setq jdb (/ (* (angle (nth (- zbdl 1) zbd) (nth zbdl zbd)) 180) pi))<BR>      (setq jdc (- jda jdb))<BR>      (if (< jdc 0) (setq jdc (- 0 jdc)))<BR>      (if (> jdc 180) (setq jdc (- 360 jdc)))<BR>      (if (> jdc 90) (progn (setq zbb (reverse zbb)) (setq ds1  (- (length zbb) ds1)  ) ))  <BR>      (entdel object) (setq i 0) (command "pline")    <BR>      (repeat (- (length zbd) 1)   (command (nth i zbd))  (setq i (+ i 1)) )   <BR>      (command jdzb)  (command (nth ds1 zbb))(command "")<BR>      (setq object (entlast))   (setq zbd nil)  (setq zbd (qd_b1 object) ) <BR>      (entdel objb)        <BR>   )<BR>  )  <BR> )</P>
<P>    (command"pedit" object "s" "")  (setq obj object)(huan3)<BR>    (setq obj object) (cd1)  (setq object (entlast))<BR>    (setq zba nil)   (setq zba (qd_b1 object) ) <BR>    (setq i 1) (repeat (- (length zba) 1)  (setq zb (append zb (list (nth i zba))))   (setq i (+ 1 i))  )<BR> <BR>     (if jdzb (progn<BR>       (setq  i (+ ds1 1))<BR>       (repeat (- (- (length zbb) ds1) 1)  (setq zb (append zb (list (nth i zbb))))   (setq i (+ 1 i)) )  <BR>     ))<BR>    (if (= xxfz 1) (setq zb (reverse zb)) )     <BR>    (setq i 0) (command "pline")<BR>    (repeat (length zb)   (command (nth i zb))  (setq i (+ i 1))    )<BR>    (if (= c70 1)   (command "c")(command ""))<BR>    (if (/= wid nil) (command"pedit" (entlast) "w" wid "")  )<BR>    (if (/= w38 nil) (command"change" (entlast) "" "p" "e" w38 "")  )<BR>    (COMMAND "_matchprop" OBJ1 (entlast) "")<BR>    (command "redraw")<BR>    (ENTDEL OBJECT)   (ENTDEL OBJC )<BR>)</P>
<P><BR>(defun cd1()<BR>   (setq obj_40 nil)<BR>   (setq obj_lt nil)<BR>   (setq obj_color nil)<BR>   (setq  obj_b(entget obj  ))<BR>   (setq obj_la (cdr(assoc 8 obj_b)))<BR>   (setq obj_lt (cdr(assoc 6 obj_b)))<BR>   (setq obj_color (cdr(assoc 62 obj_b)))<BR>   (setq obj_70 (cdr(assoc 70 obj_b)))<BR>   (setq obj_40 (cdr(assoc 40 obj_b)))<BR>   (setq obj_xdata (assoc -3 obj_b) )<BR>  <BR>   (setq  DB_zb (qd_b1 obj) ) <BR>  <BR>  <BR>    (setq nnn(length db_zb))<BR>    (if(or(= obj_70 5)(= obj_70 133)) (setq nnn (- nnn 1)))<BR>    <BR>   (setq p0(nth 0 db_zb))<BR>   (setq p2 p0)<BR>   (command "osnap" "off")<BR>   (command "pline" p0 "w" 0 0)<BR>   (setq j 1)<BR>   (setq jdd 0)<BR>   (repeat (- nnn 2)<BR>     (setq p1(nth j db_zb))<BR>     (setq p3(nth (+ j 1) db_zb))<BR>      (setq jda (angle p2 p1))<BR>      (setq jdb (angle p2 p3))<BR>      (setq jdc (abs (- jda jdb)))<BR>      (if (> jdc pi) (setq jdc (- (* 2 pi) jdc)))</P>
<P>      (if (or (> (distance p1 p2) 4) (> (+ jdd jdc) 0.05)) <BR>       (progn<BR>         (command p1)<BR>         (setq jdd 0)         <BR>         (setq p2 p1)<BR>      )<BR>        (setq jdd (+ jdd jdc)) <BR>      )<BR>     (setq j (+ j 1))<BR>   )<BR> <BR>   (setq p1 (nth (- nnn 1) db_zb))<BR>   (command p1)  </P>
<P><BR>   <BR>    (if( /= (/ obj_70 2) (/ obj_70 2.0) ) (command p0))<BR>   (command)</P>

<P>  (command"erase" obj "")</P>
<P>  <BR>  (setq object  (entget (entlast)))</P>
<P>  (if obj_la  <BR>    (setq object (subst (cons 8 obj_la) (assoc 8 object) object))<BR>  )<BR>  (if obj_lt  <BR>    (setq object (subst (cons 6 obj_lt) (assoc 6 object) object))<BR>  )<BR>  (if obj_color  <BR>    (setq object (subst (cons 62 obj_color) (assoc 62 object) object))<BR>  )<BR> </P>
<P>     (entmod object)<BR>   (if (/= obj_xdata nil)(progn<BR>     (setq xdata (list obj_xdata))<BR>     (setq nent (append object  xdata))<BR>     (entmod nent) <BR>   ))<BR>(if obj_40 (progn<BR>    (command "pedit" (entlast) "w" obj_40 "x")<BR>  <BR>  ))</P>
<P>) </P>

<P><BR>(defun plin2a()<BR>   (command"pline" "near" p1 "w" wid wid)  <BR>    (setq i 1) <BR>     (while (/= p1 nil)<BR>       (initget 128)                       <BR>       (setq p1 (getpoint p1 "\n/Undo退回/Point选择新点: "))    <BR>       (if (= 'STR (type p1))    <BR>         (progn<BR>           (setq p1 (strcase p1))  <BR>           (if (= p1 "U")<BR>             (progn<BR>               (if (> i 1) (setq i (- i 1)))               <BR>               (command p1)(setq p1 p2)<BR>             );progn<BR>           ) <BR>        <BR>         ) ;progn<BR>         (progn<BR>           (if (/= p1 nil)<BR>             (setq p2 p1) <BR>           )                              <BR>           (command p1) (print p1)<BR>           (setq i (+  i 1)) <BR>        ) ;progn<BR>         ) ;if<BR>     );while<BR>    (setq object (entlast))<BR>      <BR>)</P>
<P>(defun jdjs()<BR>  (setq jdzb nil)<BR>  (setq q1 (nth (- i 1) zbb))<BR>  (while (and (= jdzb nil) (< i (length zbb)))<BR>   (setq q2 q1)    <BR>   (setq q1 (nth i zbb))<BR>   (setq jd (angle q2 q1))<BR>   (setq p2 (polar p1 (+ jd (/ pi 2)) pzjl))    (setq p3 (polar p1 (- jd (/ pi 2)) pzjl))<BR>   (setq jdzb (inters q1 q2 p2 p3))<BR>   (setq i (+ i 1))<BR>  )<BR>  (setq i (- i 1))     <BR>) </P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部