找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1996|回复: 2

[求助] [求助]:帮忙看一下程序

[复制链接]
发表于 2006-12-18 12:29:33 | 显示全部楼层 |阅读模式

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

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

×
我觉得很奇怪 我打开一张新图 运行这个程序就会出现:error: AutoCAD 变量设置被拒绝: "osmode" nil  这个提示 然后我点一下对象捕捉,程序就可以用了,点两下也可以用,为什么会出现这个问题?希望高手能够帮忙


(defun c:lt( / x y x1 y1 pt0 hh cmd)
  (setq cmd (getvar "osmode"))
  (setvar "cmdecho" 0)
  (initget 6 "Right Left")
  (setq word (getkword "\n Left/<Right> "))
  (if (not word) (setq word "Right"))
  (if (= word "Right") (setq k 1) (setq k -1))
  (if (not hf) (setq hf 1500.0))
  (initget 6)
  (setq x (getreal (strcat "\nHight of stair <" (rtos hf 2 0) ">: ")))
  (if (/= x nil) (setq hf x))
  (if (not num) (setq num 10))
  (initget 6)
  (setq x (getint (strcat "\nNumber of stair <" (itoa num) ">: ")))
  (if (/= x nil) (setq num x))
  (if (not bs) (setq bs 250.0))
  (initget 6)
  (setq x (getreal (strcat "\nWidth of stair <" (rtos bs 2 0) ">: ")))
  (if (/= x nil) (setq bs x))
  (if (not ts) (setq ts 100.0))
  (initget 6)
  (setq x (getreal (strcat "\nThickness of stair <" (rtos ts 2 0) ">: ")))
  (if (/= x nil) (setq ts x))
  (initget 7)
  (setq pt0 (getpoint "\nPick the start point of stair: "))
  (setq x (car pt0) y (cadr pt0) x1 x y1 y hh (/ hf num))
;  (setvar "clayer" "S0")
  (repeat num
    (setq x1 (+ x1 (* k bs)) y1 (+ y1 hh))
    (command "line" (list x y) (list x y1) (list x1 y1) "")
    (setq x x1 y y1)
  )
  (setq hh (/ (* (sqrt (+ (* bs bs) (* hh hh))) ts) bs))
  (setq x (car pt0) y (- (cadr pt0) hh) y1 (- y1 hh))
  (command "line" (list x y) (list x1 y1) "")
  )
  (setvar "osmode" cmd)
; end of lout
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2006-12-19 13:06:01 | 显示全部楼层
  1. [FONT=courier new](defun c:test (/ x y x1 y1 pt0 hh)
  2.   (cmdla0)
  3.   (if (null word)
  4.     (setq word "R")
  5.   )
  6.   (if (= word "R")
  7.     (setq k 1)
  8.     (setq k -1)
  9.   )
  10.   (if (not hf)
  11.     (setq hf 1500.0)
  12.   )
  13.   (if (not num)
  14.     (setq num 10)
  15.   )
  16.   (if (not bs)
  17.     (setq bs 250.0)
  18.   )
  19.   (if (not ts)
  20.     (setq ts 100.0)
  21.   )
  22.   (setq        word (UKWORD 1 "L R" "方向: L-左边/R-右边" word)
  23.         hf   (UREAL 7 "" "\n楼梯高" hf)
  24.         num  (UREAL 7 "" "\n楼梯踏步数" num)
  25.         bs   (UREAL 7 "" "\n楼梯踏步宽" bs)
  26.         ts   (UREAL 7 "" "\n楼梯踏步厚" ts)
  27.         pt0  (UPOINT 1 "" "\n起点" pt0 nil)
  28.         x    (car pt0)
  29.         y    (cadr pt0)
  30.         x1   x
  31.         y1   y
  32.         hh   (/ hf num)
  33.   )
  34.   (setvar "osmode" 0)
  35.   (command "pline" pt0)
  36.   (repeat num
  37.     (setq x1  (+ x1 (* k bs))
  38.           y1  (+ y1 hh)
  39.           pt1 (list x y1)
  40.           pt2 (list x1 y1)
  41.     )
  42.     (command pt1)
  43.     (command pt2)
  44.     (setq x x1
  45.           y y1
  46.     )
  47.   )
  48.   (command "")
  49.   (setq        hh (/ (* (sqrt (+ (* bs bs) (* hh hh))) ts) bs)
  50.         x  (car pt0)
  51.         y  (- (cadr pt0) hh)
  52.         y1 (- y1 hh)
  53.   )
  54.   (command "line" (list x y) (list x1 y1) "")
  55.   (cmdla1)
  56. )[/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 2个

财富等级: 恭喜发财

发表于 2006-12-19 13:44:30 | 显示全部楼层
一楼代码的问题出在最后一句(setvar "osmode" cmd)

你的意思应该是:在函数结束时把恢复系统变量设置,这一句放在DEFUN定义以内。

而你上面给出的代码写到了DEFUN定义以外,则在加载的时候就运行了这一句。
但在加载代码时,变量CMD是没有定义的,其值为nil,所以就有了
; 错误: AutoCAD 变量设置被拒绝: "OSMODE" nil[/COLOR]

修改后的代码见下:

  1.   [FONT=courier new]
  2. (defun c:lt (/ x y x1 y1 pt0 hh cmd)
  3.     (setq cmd (getvar "osmode"))
  4.     (setvar "cmdecho" 0)
  5.     (initget 6 "Right Left")
  6.     (setq word (getkword "\n Left/ "))
  7.     (if        (not word)
  8.         (setq word "Right")
  9.     )
  10.     (if        (= word "Right")
  11.         (setq k 1)
  12.         (setq k -1)
  13.     )
  14.     (if        (not hf)
  15.         (setq hf 1500.0)
  16.     )
  17.     (initget 6)
  18.     (setq x (getreal (strcat "\nHight of stair <" (rtos hf 2 0) ">: ")))
  19.     (if        (/= x nil)
  20.         (setq hf x)
  21.     )
  22.     (if        (not num)
  23.         (setq num 10)
  24.     )
  25.     (initget 6)
  26.     (setq x (getint (strcat "\nNumber of stair <" (itoa num) ">: ")))
  27.     (if        (/= x nil)
  28.         (setq num x)
  29.     )
  30.     (if        (not bs)
  31.         (setq bs 250.0)
  32.     )
  33.     (initget 6)
  34.     (setq x (getreal (strcat "\nWidth of stair <" (rtos bs 2 0) ">: ")))
  35.     (if        (/= x nil)
  36.         (setq bs x)
  37.     )
  38.     (if        (not ts)
  39.         (setq ts 100.0)
  40.     )
  41.     (initget 6)
  42.     (setq x (getreal
  43.                 (strcat "\nThickness of stair <" (rtos ts 2 0) ">: ")
  44.             )
  45.     )
  46.     (if        (/= x nil)
  47.         (setq ts x)
  48.     )
  49.     (initget 7)
  50.     (setq pt0 (getpoint "\nPick the start point of stair: "))
  51.     (setq x  (car pt0)
  52.           y  (cadr pt0)
  53.           x1 x
  54.           y1 y
  55.           hh (/ hf num)
  56.     )
  57.                                         ; (setvar "clayer" "S0")
  58.     (repeat num
  59.         (setq x1 (+ x1 (* k bs))
  60.               y1 (+ y1 hh)
  61.         )
  62.         (command "line" (list x y) (list x y1) (list x1 y1) "")
  63.         (setq x        x1
  64.               y        y1
  65.         )
  66.     )
  67.     (setq hh (/ (* (sqrt (+ (* bs bs) (* hh hh))) ts) bs))
  68.     (setq x  (car pt0)
  69.           y  (- (cadr pt0) hh)
  70.           y1 (- y1 hh)
  71.     )
  72.     (command "line" (list x y) (list x1 y1) "")
  73.     (setvar "osmode" cmd)
  74. );;;★请注意此闭括号的位置★。

  75. ;;; end of lout
  76.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-21 04:37 , Processed in 0.392311 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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