找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 565|回复: 0

[求助]:请大家指点一段程序

[复制链接]
发表于 2008-2-18 13:04:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
这是一段绘制双线管道的程序,如下:

(defun c:gd ()
  (defun zgd (bpoint epooint / bp1 bp2 ep1 ep2)

    (if    (= (cadr bpoint) (cadr epoint))
      ;;固定bp1和ep1的位置,水平在其上侧,垂直在其左侧
      (progn
    (setq bp1 (polar bpoint (/ pi 2) gdr))
    (princ bp1)
    (setq bp2 (polar bpoint (- (/ pi 2)) gdr))
    (princ bp2)
    (setq ep1 (polar epoint (/ pi 2) gdr))
    (princ ep1)
    (setq ep2 (polar epoint (- (/ pi 2)) gdr))
    (princ ep2)
      )
    )
    (if    (= (car bpoint) (car epoint))
      (progn
    (setq bp1 (polar bpoint pi gdr))
    (princ bp1)
    (setq bp2 (polar bpoint 0 gdr))
    (princ bp2)
    (setq ep1 (polar epoint pi gdr))
    (princ ep1)
    (setq ep2 (polar epoint 0 gdr))
    (princ ep2)
      )
    )

    (command "-linetype" "s" "center" "")
    (command "line" bpoint epoint "")

    (command "-linetype" "s" "continuous" "")

    (command "pline" bp1 ep1 "")
    (command "pline" bp2 ep2 "")
    (command "line" bp1 bp2 "")
    (command "line" ep1 ep2 "")
  )

  (print "双线管道绘制程序:α版")
  (print
    "目前此程序只绘制垂直或水平带90度弯头的管道,第一段管道必须为直管段"
  )
  (print "二个弯头不能直接相连,必须有一段直管段")

  (setq mysnap (getvar "osmode"))
  (princ mysnap)
  (setq myortho (getvar "orthomode"))
  (setq xk (getvar "plinewid"))
  (setvar "osmode" 0)
  (setq sc (getint "请输入图形比例: 1: "))

  (setq gdd (getint "请输入管道直径: "))

  (setq gdr (/ (* 0.5 gdd) sc))

  ;;管道图中真实径
  (setq gdxk (getreal "输入双线线宽"))
  (setq wtd(getreal "输入弯头大小,几倍D"))
  (setvar "plinewid" gdxk)
  (setq bpoint (getpoint "请输入起始点: "))
  (setvar "orthomode" 1)
  (setq epoint (getpoint bpoint "输入下一点:"))
  (princ epoint)
  (zgd bpoint epoint)
  (setq lsd bpoint)            ;临时点储存原始端点      
  (setq bpoint epoint)

  (setq n 1.0)


  (while (> n 0.0)
    (setq zl (getint "选择绘制种类:1、直管段;2、弯头:"))
    (princ zl)
    (if    (= zl 1)
      (setvar "orthomode" 1)
    )
    (if    (= zl 2)
      (setvar "orthomode" 0)
    )
    (setq epoint (getpoint bpoint "输入下一点:"))
    (setq emang (angle bpoint epoint))    ;直线度
    (princ emang)
    (while (= zl 1)
      (zgd bpoint epoint)
      (setq zl 0)
    )
    (while (= zl 2)
               
      (if (and (= (cadr bpoint) (cadr lsd)) (> emang 0) (< emang pi))
    (progn
      (if (> (car bpoint) (car lsd))
        (progn
          (setq emang (/ pi 4))
          (setq emang2 (/ pi 8))
        )
      )
      (if (< (car bpoint) (car lsd))
        (progn
          (setq emang (* pi 0.75))
          (setq emang2 (* pi 0.875))
        )
      )
      (setq epoint (polar bpoint emang (* gdr (sqrt(* 8 wtd  wtd )))))

      (setq mpoint (polar bpoint emang2 (* gdr 4 wtd (sin (/ pi 8)))))


    )
      )
      (if (and (= (cadr bpoint) (cadr lsd)) (> emang pi))
    (progn
      (if (> (car bpoint) (car lsd))
        (progn
          (setq emang (- (/ pi 4)))
          (setq emang2 (- (/ pi 8)))
        )
      )
      (if (< (car bpoint) (car lsd))
        (progn
          (setq emang (- (* pi 0.75)))
          (setq emang2 (- (* pi 0.875)))
        )
      )

      (setq epoint (polar bpoint emang (* gdr (sqrt(* 8 wtd wtd)))))

      (setq mpoint (polar bpoint emang2 (* gdr 4 wtd (sin (/ pi 8)))))

    )
      )
               
      (if (and (= (car bpoint) (car lsd))
           (> (car epoint) (car bpoint))
      )                ;管道为垂直,弯头在右侧
    (progn
      (if (< (cadr lsd) (cadr bpoint)) ;管道向上
        (progn
          (setq emang (/ pi 4))
          (setq emang2 (* pi 0.375))
        )
      )
      (if (> (cadr lsd) (cadr bpoint)) ;管道向下
        (progn
          (setq emang (- (/ pi 4)))
          (setq emang2 (- (* pi 0.375)))
        )
      )
      (princ emang)
      (setq epoint (polar bpoint emang (* gdr (sqrt (* 8 wtd wtd)))))

      (setq mpoint (polar bpoint emang2 (* gdr 4 wtd (sin (/ pi 8)))))

    )
      )
      (if (and (= (car bpoint) (car lsd))
           (< (car epoint) (car bpoint))
      )
    (progn
      (if (< (cadr lsd) (cadr bpoint)) ;管道向上
        (progn
          (setq emang (* pi 0.75))
          (setq emang2 (* pi 0.625))
        )
      )
      (if (< (cadr bpoint) (cadr lsd))
        (progn
          (setq emang (- (* pi 0.75)))
          (setq emang2 (- (* pi 0.625)))
        )
      )

      (setq epoint (polar bpoint emang (* gdr (sqrt (* 8 wtd wtd)))))

      (setq mpoint (polar bpoint emang2 (* gdr 4  wtd (sin (/ pi 8)))))
    )
      )

                    ; (princ "YYYY YYYY")

      (command "-linetype" "s" "center" "")
      (command "arc" bpoint mpoint epoint "")
      (command "-linetype" "s" "continuous" "")
      (command "pline" bpoint "a" "s" mpoint epoint "")
      (setq ss (ssget "L"))
      (setq lsda (list (car bpoint) (cadr epoint) 0))
      (command "offset" gdr ss lsda "")
      (setq lsdb (list (car epoint) (cadr bpoint) 0))
      (command "offset" gdr ss lsdb "")
      (command "erase" ss "")
      (command "-linetype" "s" "continuous" "")
      (command "line" ep1 ep2 "")
      (setq zl 0)
    )

    (setq lsd bpoint)            ;临时点储存原始端点      

    (setq bpoint epoint)        ;转换始点,点

    (setq x (getint "是否结束绘制:1、继续;2、结束"))
    (princ x)
    (if    (= x 2)
      (setq n 0.0)
    )

  )
  (setvar "PLINEWID" xk)
  (setvar "OSMODE" mysnap)
  (setvar "orthomode" myortho)

)

当提示输入管道直径时,输入直径就提示错误,请高手修改,不胜感激!!!谢谢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-6-6 19:05 , Processed in 0.172759 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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