6 xyz#039;s、 5个STRCAT,4个tra
好的,没有5个STRCAT,但我觉得标题很吸引人。因此,我一直在制作这个新的autolisp,它是基于上周我用其他人的代码拼凑而成并个性化的代码。
除了我放进去的那个小等式外,一切都正常。以下是我更新之前的工作代码:
(defun c:ptdif (/ p p1 p2 p3 x y z x1 y1 z1 x2 y2 z2 mdl pdiff ptcoord textloc cs_from cs_to)
(while ;start while
(setq cs_from 1)
(setq cs_to 0)
(setq p (getpoint "\nCHOOSE MODEL"))
(setq p2 (getpoint "\nCHOOSE SHOT"))
(setq textloc (getpoint p "\nPLACE TEXT"))
(setq p1 (trans p cs_from cs_to 0))
(setq p3 (trans p2 cs_from cs_to 0))
(setq x (rtos (car p1)))
(setq y (rtos (cadr p1)))
(setq z (rtos (caddr P1)))
(setq x2 (rtos (car p3)))
(setq y2 (rtos (cadr p3)))
(setq z2 (rtos (caddr p3)))
(setq ptcoord (strcat "Model: X = "x" Y = "y" Z = " z))
(setq mdl (strcat "Sokkia: X = "x2" Y = "y" Z = " z2))
(command p2)
(command "_leader" p textloc "" ptcoord mdl "")
(princ)
) ;end while
)
现在它工作得很好很整洁。我试着推它,只是为了在文本框中再添加一个字符串,其中包含“x和x2”以及y和z之间的差异。我会告诉你我尝试了什么,但没有成功。我想我已经很接近了。
(defun c:ptdif ( / p p1 p2 p3 p4 x y z x1 y1 z1 x2 y2 z2 x3 y3 z3 mdl ptd ptcoord textloc cs_from cs_to)
(while ;start while
(setq cs_from 1) ; these two keep it in world coords
(setq cs_to 0)
(setq p (getpoint "\nCHOOSE MODEL")) ; all my get points and prompts
(setq p2 (getpoint "\nCHOOSE SHOT"))
(setq textloc (getpoint p "\nPLACE TEXT"))
(setq p1 (trans p cs_from cs_to 0)) ; the compliment to keeping it in world coords
(setq p3 (trans p2 cs_from cs_to 0))
(setq x (rtos (car p1))) ; breaks up x, y, and z from 1st getpoint
(setq y (rtos (cadr p1)))
(setq z (rtos (caddr P1)))
(setq x2 (rtos (car p3))) ; breaks up x, y, and z from 2nd getpoint
(setq y2 (rtos (cadr p3)))
(setq z2 (rtos (caddr p3)))
(setq x3 (- x x2))
(setq y3 (- y y2))
(setq z3 (- z z2))
(setq ptcoord (strcat "Model: X = "x" Y = "y" Z = " z))
(setq mdl (strcat "Sokkia: X = "x2" Y = "y2" Z = "z2))
(setq ptd (strcat x3 y3 z3))
(command p2)
(command "_leader" p textloc "" ptcoord mdl ptd "")
(princ)
) ;end while
)
我一直在用谷歌搜索我的屁股,我所有的研究都表明我的“等式”是正确的,但我不断得到“错误:糟糕的参数类型:numberp:”20.0212“”
现在如果我得到“nil”,我会修正,但这告诉我它停在等式上,对吗?
对不起,我的无知,我上周才开始这么做。
任何帮助都会非常棒。至少感谢您阅读本文。 欢迎来到CADTutor
考虑以下示例:
出现错误的原因是(使用rtos)将坐标值转换为字符串,然后尝试减去两个字符串而不是数值,结果是“错误的参数类型:numberp:”error,string“-”函数需要一个数值参数,而您已向其传递了一个字符串。有关错误消息的更多信息,请参阅此处的疑难解答。 哦,所以在我“rtos”他们之后,它失去了他们在哪里的定义。
谢谢李。你是最棒的。
不完全是;您正在将坐标值从实数数据类型转换为字符串数据类型。
例如。:
_$ (setq x 123.456)
123.456
_$ (type x)
REAL
_$ (setq x (rtos x))
"123.456000"
_$ (type x)
STR
非常感谢。 李!我只是想再次表示感谢,并想向你们展示我补充的一些东西。
它完全有效,我不需要任何帮助,但我确实遇到了这个问题:
http://www.cadtutor.net/forum/showthread.php?45355-lisp将数字四舍五入
我不喜欢那个代码。(自命不凡,我知道)似乎我没有足够的控制它实际上是什么。
4
我知道我的代码确实是阻塞的、简单的和冗余的,但它在一个主体中,我可以轻松阅读。我更像是一个“记事本”程序员。
你们网站上的visual lisp教程真的很棒,但它很快就进入了超级高级。
TL;博士
再次感谢,伟大的网站李。
你的“错误信息”页面已经成为我最喜欢的书签。
我很抱歉听到你发现我的教程太复杂了-我真诚地试图写得尽可能清晰易懂,然而,从新手的角度衡量技术水平和阅读教程是非常困难的-同时努力保持读者的兴趣,避免信息过载。。。
不过,我强烈建议您使用代码编辑器来编写代码,而不是使用标准记事本。我总是推荐专门用于编写AutoLISP的Visual LISP IDE(如果您觉得我的学习很难,AfraLISP有一些关于VLIDE的教程);但是如果你想避免使用VLIDE,网上还有很多其他的免费代码编辑器——我个人使用Notepad++来编写我所有的非AutoLISP编程,因为它是一个很棒的“全能者”。
其他代码编辑器包括:UltraEdit/Eclipse/Vim/Emacs/MSVS。。。
干杯
页:
[1]