明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: fawn_lgc

lisp如何实现实时动态显示

  [复制链接]
 楼主| 发表于 2002-11-11 10:47 | 显示全部楼层

帮我啊!使用(grread)实时拖动画圆程序,特棒!遗憾的是不能使用命令行输入半径

本帖最后由 作者 于 2002-11-11 10:47:12 编辑

使用(grread)实时拖动画圆的程序已做成,特棒!遗憾的是不能使用命令行输入半径,仅能使用鼠标点取,对象捕捉也不能用,有什么办法可以解决吗?请各位高人出谋划策.
  另外,程序中不少LISP函数我是第一次使用,用法是否合理妥当还请各位大虾批评指正.
  再另外,惊悉alin大人的电脑不能使用中文,不得不使用english,你的帖子我费了九牛二虎力还是一知半解,不知我是否真正领悟您了的教诲.
  最后补充一句,为了更好的说明问题,还是以一个"简单"的画圆程序吧(说心里话即使这样这程序还是很难写),它也应当也必能适用于绘制其他自定义的图形.


;;;使用实时拖动绘制一个圆的程序如下:

(defun c:CIRC (/ centre motion pt radius ename1 ename2 circle line boolean code)
  (defun *error* (msg)
    (if        (and (/= msg "Function cancelled")(/= msg "函数被取消"))
      (princ (strcat "天方夜谭!" msg "\n"))
      (if motion(progn(entdel ename1)(entdel ename2)))
      )
    (princ)
  )

  
  ;;***主程序***
  (setq centre (getpoint "\n圆心: "))
  (if (/= centre nil)
    (progn
      (princ "\n半径: ")
      (setq motion(grread t 15 0))
      (setq pt (car(cdr motion)))
      (setq radius(distance centre pt))
      (entmakex (list '(0 . "CIRCLE")(cons 10 centre)(cons 40 radius)));;初始圆
      (setq ename1 (entlast))
      (setq circle (entget ename1))
      (entmakex (list '(0 . "line")(cons 10 centre)(cons 11 pt)))  ;;初始引线
      (setq ename2 (entlast))
      (setq line (entget ename2))
      (setq boolean T)
      (while boolean                  
        (setq motion(grread t 15 0))      ;;动态绘图
        (setq code(car motion))
        (if (or(= code 3)(= code 5))
          (progn
            (setq pt (car(cdr motion)))
            (setq radius(distance centre pt))
            (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))   
            (setq line (subst (cons '11 pt)(assoc 11 line)line))            
            (entmod circle)                    ;;动态显示圆
            (entmod line)                      ;;动态显示引线
            )
          (entdel ename1)
          )
        (if (/= code 5)(setq boolean nil))  ;;选定点为真则退出
        )
      (entdel ename2)   ;;;删除引线
      )
    )
    (princ)
)





没有最好,只有更好!
有条件要上,没条件也上!
别人能做到的,我们一定能做到,别人做不到的,我们也要做到!
嗨...口干了.
 楼主| 发表于 2002-11-8 09:45 | 显示全部楼层

我不太会使用对话框,不会使用VB,没有VAB的中文资料,"快来帮我啊!!"

发表于 2002-11-8 23:46 | 显示全部楼层

我的型钢绘制程序中提出的槽钢绘制程序,如果你要学习也许对你有用!

本帖子中包含更多资源

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

x
发表于 2002-11-9 17:43 | 显示全部楼层

fawn_lge,我将代码作了些修改,可以键盘输入,具体细节请根据需要自己完成

(defun c:CIRC (/ centre motion pt radius ename1 ename2 circle line boolean code udist char nn)
  (defun *error* (msg)
    (if (and (/= msg "Function cancelled")(/= msg "函数被取消"))
      (princ (strcat "天方夜谭!" msg "\n"))
      (if motion(progn(entdel ename1)(entdel ename2)))
      )
    (princ)
  )

   
  ;;***主程序***
  (setq centre (getpoint "\n圆心: "))
  (if (/= centre nil)
    (progn
      (princ "\n半径: ")
      (setq motion(grread t 15 0))
      (setq pt (car(cdr motion)))
      (setq radius(distance centre pt))
      (entmakex (list '(0 . "CIRCLE")(cons 10 centre)(cons 40 radius)));;初始圆
      (setq ename1 (entlast))
      (setq circle (entget ename1))
      (entmakex (list '(0 . "line")(cons 10 centre)(cons 11 pt)))  ;;初始引线
      (setq ename2 (entlast))
      (setq line (entget ename2))
      (setq boolean T)
      (setq udist "")
      (while boolean                  
        (setq motion(grread t 15 0))      ;;动态绘图         
        (setq code(car motion))
        (if (= code 2)
          (progn
            (setq char (cadr motion))
            (cond
              ( (= char 8) ;当奇数次击键退格键无效,不知道为何?               
                (setq nn (strlen udist))
                (if (> nn 0)
                  (setq udist (substr udist 1 (1- nn)))
                )
              );
              ( (or (and (>= char 48)(<= char 57)) (= char 46))
                (setq udist (strcat udist (chr char)))
              )
            )
            (if (/= udist "")
              (progn
                (setq radius(atof udist))
                (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))
                (entmod circle)  
              )
            )     
            (print udist)
          )
        )
        
        (if (and (or(= code 3)(= code 5))(= udist "")) ;当键盘输入不为空时,以键盘为准
         (progn
            (setq pt (car(cdr motion)))
            (setq radius(distance centre pt))
            (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))   
            (setq line (subst (cons '11 pt)(assoc 11 line)line))            
            (entmod circle)                    ;;动态显示圆
            (entmod line)                      ;;动态显示引线
          )
        )
        ;
        (entupd ename1)
        (entupd ename2)
        (if (or (= code 3)(and (= code 2) (or (= char 13) (= char 32))))
          (setq boolean nil)
        )  ;;选定点为真则退出
      )
      (entdel ename2)   ;;;删除引线
   )
)
(princ)
)
发表于 2002-11-10 07:22 | 显示全部楼层

这样便可以勉强用键盘输入了!

;;;使用实时拖动绘制一个圆的程序如下:
(defun c:CIRC (/ centre motion pt radius ename1 ename2 circle line boolean code
                 keyrad keylist)
  (defun *error* (msg)
    (if (and (/= msg "Function cancelled")(/= msg "函数被取消"))
      (princ (strcat "天方夜谭!" msg "\n"))
      (if motion(progn(entdel ename1)(entdel ename2)))
      )
    (princ)
  )   
  ;;***主程序***
  (setq keylist '(8 46 48 49 50 51 52 53 54 55 56 57))   ;设置输入时允许使用的键盘键
  (setq keyrad "")
  (setq centre (getpoint "\nCIRC指定圆的圆心: "))
  (if (/= centre nil)
    (progn
      (princ "\n指定圆的半径<")
      (if rad (princ rad))(princ ">: ")
      (setq motion(grread t 15 0))
      (setq pt (car(cdr motion)))
      (setq radius(distance centre pt))
      (entmakex (list '(0 . "CIRCLE")(cons 10 centre)(cons 40 radius)));;初始圆
      (setq ename1 (entlast))
      (setq circle (entget ename1))
      (entmakex (list '(0 . "line")(cons 10 centre)(cons 11 pt)))  ;;初始引线
      (setq ename2 (entlast))
      (setq line (entget ename2))
      (setq boolean T)
      (while boolean                  
        (setq motion (grread t 15 0))      ;;动态绘图
        (setq code(car motion))
          (cond ((= code 5) ;鼠标游移
                 (setq pt (car(cdr motion)))
                 (setq radius(distance centre pt))
                 (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))   
                 (setq line (subst (cons '11 pt)(assoc 11 line)line))            
                 (entmod circle)                    ;;动态显示圆
                 (entmod line)                      ;;动态显示引线
                )
                ((= code 3) ;鼠标左键按下
                 (setq pt (car(cdr motion)))
                 (setq radius(distance centre pt))
                 (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))   
                 (setq line (subst (cons '11 pt)(assoc 11 line)line))            
                 (entmod circle)                    ;;显示圆
                 (entmod line)                      ;;显示线
                 (setq boolean nil)
                )
                ((and (= code 2)(member (car (cdr motion)) keylist)) ;允许使用的键盘键按下
                 (if (/= (car (cdr motion)) 8)   ;不是退格键
                     (progn
                             (princ (chr (car (cdr motion))))
                         (setq keyrad (strcat keyrad (chr (car (cdr motion)))))
                     );progn
                     (progn
                         (setq keyrad (substr keyrad 1 (1- (strlen keyrad))))                       
                         (princ "\n指定圆的半径<")(if rad (princ rad))(princ ">: ")(princ keyrad)
                     );progn
                  );endif
                  (if (= keyrad "")
                      (setq keylist '(46 48 49 50 51 52 53 54 55 56 57)) ;如果输入为空,不允许使用退格键
                      (setq keylist '(8 46 48 49 50 51 52 53 54 55 56 57))
                  )
                )
                ((or (and (= code 2)(= 13 (car (cdr motion)))) ;回车键按下 或者
                     (= code 11))            ;鼠标右键按下,有的鼠标设置为code = 25
                 (if (= (vl-string-search "." keyrad) 0)
                   (setq keyrad (strcat "0" keyrad)))
                 (if (= keyrad "")
                     (setq radius rad)
                     (setq radius (read keyrad))
                 )
                 (setq circle (subst (cons '40 radius)(assoc 40 circle)circle))   
                 (setq line (subst (cons '11 pt)(assoc 11 line)line))            
                 (entmod circle)                    ;;显示圆
                 (entmod line)                      ;;显示引线
                 (setq boolean nil)
                )
            )
  );while
      (entdel ename2)   ;;;删除引线
      )
    )
  (setq rad radius)
  (princ)
)
 楼主| 发表于 2002-11-11 12:02 | 显示全部楼层

不能用啊!

输入命令后出现下列窗口显示出错

本帖子中包含更多资源

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

x
发表于 2002-11-11 13:12 | 显示全部楼层

Same problem!

发表于 2002-11-11 22:48 | 显示全部楼层

工具——数据库连接——数据库连接管理器——设置数据源,再试试!

本帖子中包含更多资源

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

x
发表于 2002-11-12 14:40 | 显示全部楼层

配置数据源,然后测试连接,如果连接成功就可以执行程序了


本帖子中包含更多资源

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

x
发表于 2002-11-14 22:56 | 显示全部楼层

是实现这种功能吗?

本帖子中包含更多资源

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

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-2 16:02 , Processed in 0.523445 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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