明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1367|回复: 7

来看看啊,刚出炉的不能运行的程序!

[复制链接]
发表于 2004-12-10 13:50:00 | 显示全部楼层 |阅读模式
大家帮我看看,错在哪里了呀?? (setvar "osmode" 0)
(defun c:canal () ;;定义主函数名称
(setq base (getpoint "路线起点")) ;;获取起点坐标
(setq center (getpoint base "路线终点")) ;;获取终点坐标
(setq end (list (car center) (cadr base))) ;;固定纵坐标
(command "line" base end "") ;;做直线
(setq lenth (distance base center));;获取路线长度
(setq off (fix (/ (- lenth 50) 50)));;获取要排列的个数
(setq base1 base) ;;保存起点坐标给base1变量
(setq mark (getstring "输入第一个设备的桩号"));;获得第一个设备桩号如 K00+000形式
(setq oo atoi (substr (mark 2 1))) ;;00位转整
(setq ooo atoi (substr (mark 5 2))) ;;000位转整
(repeat off ;;开始循环,重复off次
(setq lenth1 (polar base1 0 50)) ;;极坐标方式寻找圆心,并存入变量lenth1中
(command "circle" lenth1 5 "") ;;画圆
(if (>= ooo 1000) (setq ooo (- ooo 1000))
(setq oo (+ oo 1))
(command "text" (polar lenth1 (/ 2 PI) 10) 3 strcat ("k" oo "+" ooo ))
(setq base1 lenth1) ;;循环因子
(setq ooo (+ ooo 50))
(princ)
)
发表于 2004-12-10 14:38:00 | 显示全部楼层
(setq oo atoi (substr (mark 2 1))) ;;00位转整
(setq ooo atoi (substr (mark 5 2))) ;;000位转整 (command "text" (polar lenth1 (/ 2 PI) 10) 3 strcat ("k" oo "+" ooo )) 这三句中有些函数未使用括号或括号位置不对,从别的程序转过来,还不太习惯吧!
 楼主| 发表于 2004-12-10 14:55:00 | 显示全部楼层
谢谢老大,这个程序是我自己写的,我想达到这个目的,在一条直线上间隔50放一个半径为5的圆,然后在每个圆上标注 桩号,形式为k00+000每当后面的000超过1000的时候(如1050)则 k00为K01,后三位则为050!好困难啊,我都晕死了!


我碰到的问题:不知道以文本输出时,数字和字符穿能否用strcat连接在一起!


                                                                                                                                                                                                 为什么当我用 polar 命令定义角度为 (/ 2         pi ),应该是垂直的,怎么运行出来就不是那样的,很晕
发表于 2004-12-10 15:07:00 | 显示全部楼层
我知道是你自己写的,我是说你原来会C,现在用LISP写程序,有些习惯上还没完全转过来,如LISP这样写(strcat a b),按C的习惯就会写成strcat (a b)


(/ 2 pi) --->2/pi


你需要的应该是pi/2吧。。。
发表于 2004-12-10 15:17:00 | 显示全部楼层
1、(setq oo atoi (substr (mark 2 1))) ;;00位转整
改成(setq oo (atoi (substr mark 2 1)))
2、(setq ooo atoi (substr (mark 5 2))) ;;000位转整
改成(setq ooo (atoi (substr mark 5 2)))
3、(if (>= ooo 1000) (setq ooo (- ooo 1000))
(setq oo (+ oo 1))
改成(if (>= ooo 1000)
(setq ooo (- ooo 1000))
(setq oo (+ oo 1))
)
4、(command "text" (polar lenth1 (/ 2 PI) 10) 3 strcat ("k" oo "+" ooo ))
改成
(command "text" (polar lenth1 (/ 2 pi) 10) 3 "" (strcat "k" (itoa oo) "+" (itoa ooo)))
 楼主| 发表于 2004-12-10 15:17:00 | 显示全部楼层
说的是啊,就是那种感觉,职业病啊!帮我再修改一下我的程序吧,我想今天把他做出来!
发表于 2004-12-10 15:58:00 | 显示全部楼层
看看是否满足你的要求?
  1. (defun calNum(str n / newStr);一个给字符串增加某一值的子函数
  2.    (setq newStr (itoa (+ (atoi str) n)))
  3.    (repeat (- (strlen str) (strlen newStr))
  4.        (setq newStr (strcat "0" newStr))
  5.    )
  6.    newStr
  7. )
  8. (defun c:canal ()   ;;定义主函数名称
  9.    (setq base (getpoint "\n路线起点:"))   ;;获取起点坐标
  10.    (setq center (getpoint base "\n路线终点:"))   ;;获取终点坐标
  11.    (setq mark (getstring "\n输入第一个设备的桩号:"))   ;;获得第一个设备桩号如 K00+000形式
  12.    (setq end (list (car center) (cadr base)))   ;;固定纵坐标
  13.    (command "line" base end "")   ;;做直线
  14.    (setq lenth (distance base center))   ;;获取路线长度
  15.    (setq off (fix (/ (- lenth 50) 50)))   ;;获取要排列的个数
  16.    (setq base1 base)   ;;保存起点坐标给base1变量
  17.    (setq oo (substr mark 2 2))   ;;00位转整
  18.    (setq ooo (substr mark 5 3))   ;;000位转整
  19.    (setq os (getvar "osmode"))
  20.    (setvar "osmode" 0)
  21.    (setvar "cmdecho" 0)
  22.    (repeat off       ;;开始循环,重复off次
  23.        (setq lenth1 (polar base1 0 50))       ;;极坐标方式寻找圆心,并存入变量lenth1中
  24.        (command "circle" lenth1 5)       ;;画圆
  25.        (if (>= (atoi ooo) 1000)
  26.            (progn
  27.   (setq ooo (calNum ooo -1000))
  28.   (setq oo (calNum oo 1))
  29.            );这里注意if只能带两个参数,也就是两个表达式,如果你某种条件要操作的表达式多于一个,必须使用progn
  30.        )
  31.        (command "text" (polar lenth1 (/ PI 2) 10) 3 "" (strcat "k" oo "+" ooo))
  32.        (setq base1 lenth1)       ;;循环因子
  33.        (setq ooo (calNum ooo 50))
  34.    )
  35.    (setvar "osmode" os);恢复os值
  36.    (princ)
  37. )
 楼主| 发表于 2004-12-10 16:37:00 | 显示全部楼层
运行过,不过还是没有达到效果,那我自己来吧,如果再不行,再请教,该不过被斑竹踢出去吧!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-30 02:23 , Processed in 0.156349 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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