明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1591|回复: 3

[提问] 请教,还是关于子程序编写的问题。

[复制链接]
发表于 2014-4-11 16:14 | 显示全部楼层 |阅读模式
下面的程序中,我把fid这个子程序写成了(defun fid (a b) (cdr (assoc a b))),现在程序只能运行到(= s 3)(= s 4)这个地方,请教是哪里的问题?
(Defun ima (a b / x y)
  (setq        x (dimx_tile a)
        y (dimy_tile a)
  )
  (start_image a)
  (fill_image 0 0 x y 0)
  (slide_image 0 0 x y b)
  (end_image)
)

(defun fid (a b) (cdr (assoc a b)))

(Defun set1 ()
  (if (not (new_dialog "GH1" id))
    (exit)
  )
  (mapcar '(lambda (x y) (ima x y))
          (list "i1" "i2" "i3" "i4" "i5" "i6")
          (list        "DX(GH1)" "DX(GH2)" "DX(GH3)" "DX(GH4)"        "DX(GH5)"
                "DX(GH6)")
  )
  (action_tile "i1" "(done_dialog 1)")
  (action_tile "i2" "(done_dialog 2)")
  (action_tile "i3" "(done_dialog 3)")
  (action_tile "i4" "(done_dialog 4)")
  (action_tile "i5" "(done_dialog 5)")
  (action_tile "i6" "(done_dialog 6)")
  (setq s1 (start_dialog))
)



(Defun C:GHD (/ id s sc p1 p2 e le ht)
  (setvar "cmdecho" 0)
  (setvar "blipmode" 0)
  (setvar "plinewid" 0)
  (setvar "orthomode" 0)
  (setq        sc (getvar "USERR1")
        ht (getvar "userr2")
  )
  (command "LAYER" "m" "$GH" "c" "3" "" "")
  (setq        id (load_dialog "DL.DCL")
        s  1
  )
  (while (/= s 0)
    (if        (not (new_dialog "GH" id))
      (exit)
    )
    (ima "I" "DX(GH0)")
    (action_tile "k1"  "(setq a (get_tile \"a\")) (done_dialog 1)")
    (action_tile "k2" "(done_dialog 2)")
    (action_tile "k3" "(done_dialog 3)")
    (action_tile "k4" "(done_dialog 4)")
    (action_tile "k5" "(done_dialog 5)")
    (action_tile "cancel" "(done_dialog 0)")
    (setq s (start_dialog))
    (cond
      ((= s 1)
       (princ "\n插入点:")
       (command        "INSERT" "GHWX" "X" (atof a) "Y" (atof a) "Z" (atof a)        pause)
       (princ "\n旋转角:")
       (command pause "explode" (entlast) "CHANGE"        (entlast) "" "P" "la" "$GH" ""  )
      )
      ((= s 2)
       (princ "\n请直接使用光标夹点方式调整图形外轮廓!!")
       (setq s 0)
      )
      ((= s 3)
       (while
         (not
           (and        (setq e (car (entsel "\n点取计算面积的图形轮廓.")))
                (= (fid 0 (entget e)) "POLYLINE")
           )
         )
       )
       (command "AREA" "E" E)
       (princ
         (strcat "\n面积: "
                 (rtos (* (/ 1 sc) (/ 1 sc) (getvar "area")) 2 1)
                 " 平方米 ."
         )
       )
      )
      ((= s 4)
       (set1)
       (while (not (and        (setq e (car (entsel "\n点取定义的图形轮廓.")))
                        (= (fid 0 (setq le (entget e))) "POLYLINE")
                   )
              )
       )
       (cond
         ((= s1 1)
          (setq        p1 (fid 10 (entget (setq e (entnext e))))
                kk 1
                p0 p1
          )
          (while
            (= (fid 0 (setq le (entget (setq e (entnext e))))) "VERTEX")
             (setq p2 (fid 10 le)
                   a  (angle p1 p2)
                   p1 p2
             )
             (if (> (distance p0 p2) 1.3)
               (setq kk        1
                     p0        p2
               )
               (setq kk nil)
             )
             (if kk
               (command "LINE" p2 (polar p2 (- a (* pi 0.5)) 1) "")
             )
          )
         )
         ((= s1 2)
          (setq        p1 (fid 10 (entget (setq e (entnext e))))
                kk 1
                p0 p1
          )
          (while
            (= (fid 0 (setq le (entget (setq e (entnext e))))) "VERTEX")
             (setq p2 (fid 10 le)
                   a  (angle p1 p2)
                   p1 p2
             )
             (if (> (distance p0 p2) 1.3)
               (setq kk        1
                     p0        p2
               )
               (setq kk nil)
             )
             (if kk
               (command "LINE" p2 (polar p2 (+ a (* pi 0.5)) 1) "")
             )
          )
         )
         ((or (= s1 3) (= s1 4))
          (setq        p1 (fid 10 (entget (setq e (entnext e))))
                kk 1
                p0 p1
          )
          (while
            (= (fid 0 (setq le (entget (setq e (entnext e))))) "VERTEX")
             (setq p2 (fid 10 le)
                   a  (angle p1 p2)
                   p1 p2
             )
             (if kk
               (progn (command "TEXT"
                               (polar p2 (+ a (* pi 0.5)) 2)
                               ht
                               0
                               (if (= s1 3)
                                 "湖泊"
                                 "塘"
                               )
                      )
                      (setq kk nil)
               )
             )
          )
         )
         ((= s1 5) (dHATCH "gt9" 5 0 e T))
         ((= s1 6) (dHATCH "gt8" 5 0 e T))
         (T 1)
       )
      )
      ((= s 5)
       (while
         (not (and (setq e (car (entsel "\n点取待放缩的图形轮廓.")))
                   (= (fid 0 (setq le (entget e))) "POLYLINE")
              )
         )
       )
       (princ "\n点取放缩参考点:")
       (command "SCALE" E "" PAUSE)
       (princ "\n输入放缩比例:")
       (command pause)
       (command "AREA" "E" E)
       (princ
         (strcat "\n当前图形面积: "
                 (rtos (* (/ 1 sc) (/ 1 sc) (getvar "area")) 2 1)
                 " 平方米 ."
         )
       )
      )
    )
  )
  (unload_dialog id)
  (setvar "clayer" "0")
  (princ)
)

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2014-4-11 21:15 | 显示全部楼层
如果图中的PLINE线是LWPOLYLINE时程序后面无法执行。
建议将(= (fid 0 (setq le (entget e))) "POLYLINE")
改成(wcmatch (fid 0 (setq le (entget e))) "*POLYLINE")
 楼主| 发表于 2014-4-11 22:13 | 显示全部楼层
修改后,(= s1 5)(= s1 6)可以用了,(= s1 3)----(= s1 4)还是无法使用。
计算面积提示:错误,除数为零。
发表于 2014-4-12 08:26 | 显示全部楼层
lxdz443 发表于 2014-4-11 22:13
修改后,(= s1 5)(= s1 6)可以用了,(= s1 3)----(= s1 4)还是无法使用。
计算面积提示:错误,除数为零。

s=4后面的代码只是针对POLYLINE的,前面的判断不能改。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-7 07:33 , Processed in 0.240592 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表