乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 15|回复: 15

[编程交流] ABC's of Autolisp by Geor

[复制链接]

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-6 06:48:13 | 显示全部楼层 |阅读模式
hi
its my first day in  "ABC's of Autolisp by George Omura" class. i tried to use this code but its not working. im sure its data type mismatch.
 
i simply want to program to draw a line from pt1 to pt2
 
  1. (defun C:test() (setq pt1 (list (getpoint))) (setq pt2 (list (getpoint))) (command "Line" pt1 pt2)    );end defun
 
Thanks
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-6 06:53:55 | 显示全部楼层
why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?
回复

使用道具 举报

GP_

8

主题

248

帖子

245

银币

初来乍到

Rank: 1

铜币
42
发表于 2022-7-6 06:56:49 | 显示全部楼层
  1. (defun C:test() (setq pt1 (getpoint)) (setq pt2 (getpoint)) (command "Line" pt1 pt2 ""));end defun
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-6 07:00:22 | 显示全部楼层
thanks GP
 
hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:04:36 | 显示全部楼层
You could just incorporate the pause function:
 
  1. (defun c:TEST () (command "._line" pause pause "") (princ))
 
... But this may cause undesired behavior following a right click being entered in lieu of a point specification. This adaptation is a bit less prone to this undesired behavior:
 
  1. (defun c:TEST () (command "._line") (princ))
 
... If the requirement is to use two variables, then consider using local in lieu of global variables, and avoid potential errors in the Command call by using an If statement:
 
  1. (defun c:TEST (/ point1 point2) (if (and (setq point1 (getpoint "\nSpecify start point: "))          (not (initget 32))          (setq point2 (getpoint point1 "\nSpecify end point: "))     )   (command "._line" point1 point2 "")   (prompt "\n** Invalid point ** ") ) (princ))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:08:40 | 显示全部楼层
 
Here is an example to consider:
  1. (defun c:getpt ( / pt )   (if (setq pt (getpoint "\nPick a point, any point: "))       (princ           (strcat               "\nX = " (rtos (car pt))               "\nY = " (rtos (cadr pt))               "\nZ = " (rtos (caddr pt))           )       )   )   (princ))
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-6 07:15:30 | 显示全部楼层
i saw some using command "LINE","._LINE" what is the difference? when you say "IF" and "AND" ,logically is like making nested IF expressions. right?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:16:45 | 显示全部楼层
 
See here:
http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:22:06 | 显示全部楼层
 
In your original code in the OP, were you to right click instead of select the second point (for example), you would experience undesired behavior.
 
In this circumstance, the If statement is testing for the two valid points needed to supply the following Command call the arguments need to complete the command successfully.
 
The And statement simply allows for more than one non-Nil returned value to be required, in this case being point1, and point2 local variables, in order for the If statement's test expression to pass.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:25:29 | 显示全部楼层
In addition to BlackBox's explanation:
 
 
Correct, the following expression...
  1. ([color=blue]if[/color]   ([color=blue]and[/color][color=green]                      [/color]   )[color=red]    [/color][color=purple]    [/color])
...could alternatively be written:
  1. ([color=blue]if[/color] [color=green][/color]   ([color=blue]if[/color] [color=green][/color]       ([color=blue]if[/color] [color=green][/color][color=green][color=red]            [/color][color=purple]            [/color][/color]       )[color=green] [color=purple]       [/color][/color]   )[color=green] [color=purple]   [/color][/color])
Here, each nested if statement forms the then-expression for the previous if statment.
 
Though, where additional else-expressions are not required, I'm sure that most would agree that the use of an and statement is far more readable and concise than multiple nested if statements.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 14:50 , Processed in 0.424402 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表