乐筑天下

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

[编程交流] 使用Autolisp绘制pline。

[复制链接]

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 17:33:25 | 显示全部楼层 |阅读模式
嗨,谁能帮我检查一下我的代码出了什么问题,我无法得到数字。
 
  1. (defun c:huatu()
  2. (setq n (getint "Input number of points: "))
  3. (while(> n 0)
  4.    (setq n (- n 1))
  5.    (progn
  6.      (setq p (getpoint "Input x and y: "))
  7.      (command "pline" p "")
  8.      )
  9.    )
  10. )

 
我试图在AUTOCAD中绘制6点pline。谢谢
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 17:40:32 | 显示全部楼层

 
  1. (defun c:test  (/ n a b i l)
  2. (if (and (setq n (getint "\nInput number of points: "))
  3.           (setq a (getpoint "\nSpecify first point: "))
  4.           (setq l (cons a l))
  5.           )
  6.    (progn
  7.      (while (and (/= n 0)
  8.                  (setq b (getpoint "\nNext point: " a))
  9.                  )
  10.        (setq l (cons b l)
  11.              i (car l)
  12.              n (1- n)
  13.              )
  14.        (mapcar '(lambda (p) (grdraw i p 1 7) (setq i p)) (cdr l))
  15.        (setq a b)
  16.        )
  17.      (if l (progn
  18.              (command "_.pline")
  19.              (foreach x l
  20.                 (command "_non" x)
  21.                )
  22.              (command "")
  23.              (redraw)
  24.              )
  25.        )
  26.      )
  27.    )
  28. (princ)
  29. )
回复

使用道具 举报

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 17:44:28 | 显示全部楼层
代码中“l”的初始值是多少?它用作什么?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 17:52:11 | 显示全部楼层
 
变量“l”包含函数grdraw使用的坐标点,以在通过命令pline绘制多段线之前,在表示多段线的点之间绘制向量
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:58:04 | 显示全部楼层
下面是一个简单的示例,并附上一些注释:
  1. (defun C:test ( / lst p1 p2 )
  2. (setq lst (list)) ; construct a empty list to store the points
  3. (initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
  4. (setq n (getint "\nInput number of points"))
  5. (repeat n
  6.         (setq p1 (getpoint "\nSpecify point"))
  7.         (setq lst (cons p1 lst)) ; add the point to the list
  8. ); end of repeat, all points are stored in the list
  9. (command "_.pline"
  10.         (foreach pt lst (command "_non" pt)) ; draw each point from the list
  11. ) ; draw the polyline
  12. (princ) ; exit silently
  13. );defun

编辑1:这里有一点更复杂(因此例程将更加用户友好):
  1. (defun C:test ( / lst p1 )
  2. (setq lst (list)) ; construct a empty list to store the points
  3. (initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
  4. (setq n (getint "\nInput number of points"))
  5. (repeat n
  6.         (if (not p1) ; check if there p1 does not exist
  7.                 (setq p1 (getpoint "\nSpecify first point")) ; ask for p1 if it does not exist
  8.                 (setq p1 (getpoint "\nSpecify next point" (last (reverse lst)))) ; to display the vector from previous point
  9.         )
  10.         (setq lst (cons p1 lst)) ; add the point to the list
  11. ); end of repeat, all points are stored in the list
  12. (command "_.pline"
  13.         (foreach pt lst (command "_non" pt)) ; draw each point from the list
  14. ) ; draw the polyline
  15. (princ) ; exit silently
  16. );defun

编辑2:根据我从塔瓦的代码中学到的,这里甚至更复杂:
  1. (defun C:test ( / oldcmd lst p1 p2 col )
  2. (setq oldcmd (getvar 'cmdecho)) ; store this variable
  3. (setq lst (list)) ; construct a empty list to store the points
  4. (initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
  5. (if
  6.         (setq n (getint "\nInput number of points: ")) ; ask for the number of points
  7.         (progn ; if we get the number of points, do all the stuff within the progn function
  8.                 (setvar 'cmdecho 0) ; set this variable to 0, to avoid any useless prompts
  9.                 (repeat n
  10.                         (if (not p1) ; check if there p1 does not exist
  11.                                 (setq p1 (getpoint "\nSpecify first point")) ; ask for p1 if it does not exist
  12.                                 (progn
  13.                                         (setq p1 (getpoint "\nSpecify next point" (setq p2 (last (reverse lst))))) ; to display the vector from previous point
  14.                                         (grdraw p1 p2 (if (not col) (setq col 1) (setq col (+ col 1))) 0) ; visualize the segments, with some colors
  15.                                 )
  16.                         )
  17.                         (setq lst (cons p1 lst)) ; add the point to the list
  18.                 ); end of repeat, all points are stored in the list
  19.                 (command "_.pline"
  20.                         (foreach pt lst (command "_non" pt)) ; draw each point from the list
  21.                 ) ; draw the polyline
  22.                 (redraw) ; this is used as "regen" for the grdraw function
  23.                 (setvar 'cmdecho oldcmd) ; reset the variable
  24.         ); end of progn
  25. );if
  26. (princ) ; exit silently
  27. );defun

这是我第一次使用grdraw函数,所以我发现他的代码是一个很好的例子。
回复

使用道具 举报

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 18:00:18 | 显示全部楼层
 
谢谢,哈哈,我想我最好从你的第一个代码中学习,在我理解了所有的东西都是这个代码之后,我会检查你的edit1和edit2。非常感谢!!
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:04:09 | 显示全部楼层
 
嗯,那是我的意图!
回复

使用道具 举报

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 18:11:57 | 显示全部楼层
 
那么l的初始值是多少??
  1. setq l (cons a l)

这里的“And”用于保证“n”、“a”和“l”是有效值?
回复

使用道具 举报

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 18:14:36 | 显示全部楼层
 
嗨,我还有一个问题,在你的代码1和代码2中,
这里的“非”是什么意思?我知道这一步是为了画出每一个点,对吗?
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:20:13 | 显示全部楼层
 
引自LM网站:
从此处开始:http://lee-mac.com/scriptwriting.html
我希望他能在这里描述更多像“暂停”这样的东西。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 05:03 , Processed in 0.582183 second(s), 72 queries .

© 2020-2025 乐筑天下

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