Lukepeanuts 发表于 2022-7-5 17:03:21

Lisp-圆

Hy,
 
我是论坛的新手,也是Lisp程序的新手。我试图创建一个lisp,但它不工作。如果有人能帮我,我会非常感激的。
 
我需要一个带条件的lisp,如果我写一个关键字,lisp会将一个数字与关键字相关联。我写了这样的东西:
 
(DEFUN c:HM (CNT DIAM)
(SETQ CNT (GETPOINT "\nselect circle center"))
;click the center of the circle

(INITGET 1 "1Pul 2Pul")
(SETQ PUL (GETKWORD "\n1Pul, 2Pul:"))
;To do not write the real diameter number

        (cond
        ((= PUL "1Pul") (SETQ DIAM 0.033401))
        ((= PUL "2Pul") (SETQ DIAM 0.060325))
) ;End conditional

                        (command "circle" cnt "D" DIAM)
                        ;draw the circle

(PRINC)
)

Grrr 发表于 2022-7-5 17:07:27

你的代码很好,只是参数错了,
更改此项:
(DEFUN c:HM (CNT DIAM)
收件人:
(DEFUN c:HM ( / CNT DIAM)
塔瓦给了我一些提示:
(command "_.circle" "_non" cnt "D" DIAM)

Lukepeanuts 发表于 2022-7-5 17:12:49

现在可以了,非常感谢。

David Bethel 发表于 2022-7-5 17:14:27

作为新手,现在是养成良好编程习惯的好时机:
 

(defun c:hm (/ cnt pul diam)

(initget 1)
(setq cnt (getpoint "\nSelect circle center:   "))

(initget 1 "1Pul 2Pul")
(setq pul (getkword"\nDiameter : 1Pul/2Pul:   "))

(setq diam (cond ((= pul "1Pul") 0.033401)
                  ((= pul "2Pul") 0.060325)))

(command "_.CIRCLE" "_non" cnt "_D" diam)

(prin1))

 
 
尽量在使用的格式上保持一致。这使得以后搜索短语或测试更加容易。
 
由于这和许多点对点论坛都有国际语言成员访问,因此使用下划线作为命令和参数很有帮助。此外,命令之前的时间段确保重新定义的命令被覆盖。
 
AutoLisp是一种可读性很强的语言,如果考虑到代码的总体布局,它对您来说非常容易。
 
祝你好运,玩得开心-大卫
 
PS查看
在线程中发布代码时,标记

Lukepeanuts 发表于 2022-7-5 17:18:19

 
你用什么来画圆?这是什么意思?

Lukepeanuts 发表于 2022-7-5 17:21:56

非常感谢David抽出时间!我会尽量听从你的建议。
 
我有一个问题:
 
 
它是什么(prin1)?与(prin)的区别是什么?抱歉,如果问题是。。。很愚蠢,但我学习autolisp语言已经两周了。

Grrr 发表于 2022-7-5 17:24:36

 
有时,当代码必须计算新创建对象的点或位置时,它会失败,用户最终会在错误的位置上绘制对象。
例如,代码会随机捕捉到一些您不想捕捉的点。以下是最近出现此类问题的帖子:
http://www.cadtutor.net/forum/showthread.php?98541-尝试创建2行,但autolisp随机重叠-为什么?
然后您有2个选项:
-存储osmode变量,将其设置为0,完成后将其重置。
-只需在命令调用中的每个点参数之前包含“_non”。在您的例子中,该变量是“cnt”。有关“非”的更多信息:http://www.lee-mac.com/scriptwriting.html
 
以下是存储和重置osmode系统变量的示例:
(defun C:test ( / *error* osm ) ; always localise our variables (unless we know what we are doing)

(defun *error* ; define the error-handler function
        (alert (strcat "\nError occured, now you are inside the *error* function \nand reseting the osmode variable!"))
        (if osm (setvar 'osmode osm)) ; when your code crashes, it will check and reset the osmode value
        (princ)
); defun *error*
(setq osm (getvar 'osmode)) ; store our osmode value into a variable
(setvar 'osmode 0) ; set osmode to 0

; < here the code creates/draws its stuff >
(initget 1) (getstring "\nPress ESC to force an error: ")
(alert (strcat "\nThe code is done, exiting without errors \nand reseting the osmode variable!"))
(setvar 'osmode osm) ; reset the osmode variable
(princ)
); defun
运行代码,键入一些内容并按“ENTER”,然后再次运行代码,然后按“ESC”。

David Bethel 发表于 2022-7-5 17:27:42

 
不客气。
 
在这种情况下,不会太多。这里的目的是尽可能地在命令行的视觉上退出加载并干净地运行程序。
 
http://forums.augi.com/showthread.php?111705-差异-Between-PRINT-PRINC-amp-PRIN1
 
IRNEB在第6篇文章中有非常简单的解释。
 
-大卫

David Bethel 发表于 2022-7-5 17:34:22

 
从没听说过。但我很肯定我不会喜欢的。
 
我关闭了所有工具栏/图标/浮动内容。带有滚轮和键盘的2键鼠标。而鼠标在99.9%的时间里只拾取点。我的0.02美元
 
在这里的人们的帮助下,我终于在2012年看起来不错了。

tombu 发表于 2022-7-5 17:37:45

 
您仍然可以键入与以前相同的选项,并且它不使用工具栏或图标,它只是使命令行上显示的选项更容易查看,并且可以使用鼠标或右键快捷菜单作为选项进行选择。就像标准AutoCAD命令一样,如FILLET。为了使键入选项更容易,每个选项所需的文本部分都显示为蓝色,因此实际上更容易按您的方式执行。
 
过来看!
页: [1] 2
查看完整版本: Lisp-圆