明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1408|回复: 2

帮我看看这个程序里的标注出了什么问题

[复制链接]
发表于 2003-11-14 11:37:00 | 显示全部楼层 |阅读模式
(defun c:Vd()
    (setq scmdecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    ;;;断面点赋值
    (setq ptlist ((189.886 10.2382)
            (169.886 20.2382)
            (149.886 30.2382)
            (129.886 40.2382)
            (109.886 50.2382)
            (99.8858 60.2382)
            (109.886 70.2382)
            (129.886 70.2382)
            (149.886 60.2382)
            (169.886 40.2382)
            (189.886 10.2382))
    ;;;绘制断面轮廓线
    ((command "spline"
             (nth 0 ptList)
             (nth 1 ptList)
             (nth 2 ptList)
             (nth 3 ptList)
             (nth 4 ptList)
             (nth 5 ptList)
             (nth 6 ptList)
             (nth 7 ptList)
             (nth 8 ptList)
             (nth 9 ptList)
             (nth 10 ptList)
             "Cl" ""
    )
    ;;;进行标注
    (setq n1 (- (length ptlist) 1)
         n2 (- (/ n1 2) 1)
         i  1
    )
    (repeat n2
        (setq j  (- n1 i)
              p1  (nth i ptList)
              p2  (nth j ptList)
              p11 (list (float (car p1)) (float (cadr p1)))
              p21 (list (float (car p2)) (float (cadr p2)))
        )
        (setq
            a  (angle p11 p21)
            p3 (polar p1 a (/ (distance p1 p2) 2))
            p3 (list  (car p3) (cadr p3) (caddr p3))
            i  (1+ i)
        )
        (command "dim1" "Ver" p1 p2 p3 "")
      )
     (setvar "cmdecho" scmdecho)
   
)
上面的程序运行后,标注混乱。但将画断面轮廓线与尺寸标注调换次序后,标注正确。这是为什么?

(defun c:Vd()
    (setq scmdecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    ;;;断面点赋值
    (setq ptlist ((189.886 10.2382)
                  (169.886 20.2382)
                  (149.886 30.2382)
                  (129.886 40.2382)
                  (109.886 50.2382)
                  (99.8858 60.2382)
                  (109.886 70.2382)
                  (129.886 70.2382)
                  (149.886 60.2382)
                  (169.886 40.2382)
                  (189.886 10.2382))
    ;;;进行标注
    (setq n1 (- (length ptlist) 1)
         n2 (- (/ n1 2) 1)
         i  1
    )
    (repeat n2
        (setq j  (- n1 i)
              p1  (nth i ptList)
              p2  (nth j ptList)
              p11 (list (float (car p1)) (float (cadr p1)))
              p21 (list (float (car p2)) (float (cadr p2)))
        )
        (setq
            a  (angle p11 p21)
            p3 (polar p1 a (/ (distance p1 p2) 2))
            p3 (list  (car p3) (cadr p3) (caddr p3))
            i  (1+ i)
        )
        (command "dim1" "Ver" p1 p2 p3 "")
    )
    ;;;绘制断面线
    ((command "spline"
             (nth 0 ptList)
             (nth 1 ptList)
             (nth 2 ptList)
             (nth 3 ptList)
             (nth 4 ptList)
             (nth 5 ptList)
             (nth 6 ptList)
             (nth 7 ptList)
             (nth 8 ptList)
             (nth 9 ptList)
             (nth 10 ptList)
             "Cl" ""
    )
    (setvar "cmdecho" scmdecho)   
)
发表于 2003-11-14 12:10:00 | 显示全部楼层
怎么可能可以?
首先,你的两个程序都肯定不能正确运行,你先调整好了再贴上来。
还有
p3 (list  (car p3) (cadr p3) (caddr p3))
这句是干什么?把p3的三个值取出来,还按原来的顺序组成列表,又赋给p3,不等于什么都没做吗,程序中类似的多余的语句还有一些,你先让程序能够正确执行了,再说吧
 楼主| 发表于 2003-11-15 18:41:00 | 显示全部楼层
meflying你好,不好意思,让你费尽了。上面贴的程序,我贴之前修改了一下,把各个小程序加在了一起,我觉得可以方便你们读,当时没有想到里面出了什么问题。后来我想到了,觉得里面可能有问题。你说得对,给了我一点启发。所以,我前面写得比较混乱。所以,我参照你的意见,把思路理了理,今天,我发现问题解决了。所以, 很感激你那。我修改后的程序如下:将主程序里面的(VD:draw ptList) (VD:ddim ptList)颠倒都能达到同样的效果。以前,不是。我做这个程序的目的,是我下面要做一个程序。比如,我创建了一个扭曲的叶片实体,我想让计算机自动地去绘制各个断面的形状与标注
当然标注比这个可能要复杂。我听我同学说vba比较好学,不知道是真,但学习编写这个短短的程序,确实觉得蛮有体会的。好了,再次感谢!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;二维点转换为三维点   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun VD:2dPoints->3dPoints(2dPt)
    (list (float (car 2dPt)) (float (cadr 2dPt)) 0.0)
)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;  三维点转换为二维点
;;;;;;;;;;;;;;;;;;;;;;;;

(defun VD:3dPoints->2dPoints(3dPt)
    (list (float (car 3dPt))(float (cadr 3dPt)))
)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;    断面数据输入     
;;;;;;;;;;;;;;;;;;;;;;;;

(defun VD:dataInput (filepath / fp data1 temp end)
    (setq fp   (open filepath "r")
          Flag 1
    )
;;;循环读取数据,当文件结束标志等于0时,退出循环;
  (while (= Flag 1)
      (if (setq Data (read-line fp))
          (setq
              temp   (VD:2dPoints->3dPoints (read Data))
              ptList (cons temp ptList)
          )
          (setq Flag 0)
      )
  )
    (close fp)
)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;   断面轮廓线绘制   
;;;;;;;;;;;;;;;;;;;;;;;;

(defun VD:draw (ptList)
    (command "spline"
             (nth 0 ptList)
             (nth 1 ptList)
             (nth 2 ptList)
             (nth 3 ptList)
             (nth 4 ptList)
             (nth 5 ptList)
             (nth 6 ptList)
             (nth 7 ptList)
             (nth 8 ptList)
             (nth 9 ptList)
             (nth 10 ptList)
             "Cl" ""
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;   断面尺寸标注      
;;;;;;;;;;;;;;;;;;;;;;;;

(defun VD:ddim (ptList / p1 p2 p3 n1 n2 n3 i)
   (setq n1 (- (length ptlist) 1)
         n2 (- (/ n1 2) 1)
         i  1
   )
    (repeat n2
        (setq j  (- n1 i)
              p1  (nth i ptList)
              p2  (nth j ptList)
              p11 (VD:3dPoints->2dPoints p1)
              p21 (VD:3dPoints->2dPoints p2)
        )
        (setq
            a  (angle p11 p21)
            p3 (polar p1 a (/ (distance p1 p2) 2))
            i  (1+ i)
        )
        (command "dim1" "Ver" p1 p2 p3 "")

    )
)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;        主程序      
;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:Vd()
    (setq scmdecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq ptlist nil)
    (setq dataFilepath "e:/mylisp/dataIn.txt")
    (VD:dataInput dataFilepath)
    (VD:draw ptList)
    (VD:ddim ptList)
    ;;;    (VD:dataOut )
    (setvar "cmdecho" scmdecho)
)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-2 10:44 , Processed in 0.173877 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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