我想用AutoLisp创建一个简单的“旋转”命令,下面是我编写的代码:
(defun C:myfunc()
(setq p1 (getpoint "\nPick first POINT on the screen:\n"))
(setq p2 (getpoint "\nPick second POINT on the screen:\n"))
(command "line" p1 p2 "")
(setq ss1 (ssget p2))
(command "rotate" ss1 p2 "90" "")
(princ )
)我插入两个点,p1和p2,并创建一条连接它们的线。之后,我创建了ss1对象,它是p1-p2行。最后,我尝试将基线从p2旋转90度。
我在AutoCad中插入了代码,但是它没有创建旋转行,而是要求手动插入基点和角度,所以我猜command "rotate" ...行有问题。
如有任何建议,将不胜感激。
发布于 2016-12-03 17:10:53
据我在网上看到的,你有两个问题。
ROTATE不采用选择集,而是采用实体名称。
在旋转点之前缺少一个额外的""。
(defun C:myfunc()
(setq p1 (getpoint "\nPick first POINT on the screen:\n"))
(setq p2 (getpoint "\nPick second POINT on the screen:\n"))
(command "line" p1 p2 "")
(setq ss1 (ssget p2))
(command "rotate" (entlast) "" p2 "90")
(princ )
)参考资料:AutoLISP:围绕基准点旋转多个对象
另外,它通常帮助我手动尝试这个命令,以确保您使用正确的数据/值响应所有正确的提示。
发布于 2017-02-07 23:52:46
我建议采用以下简化代码:
(defun c:myfunc ( / p1 p2 )
(if
(and
(setq p1 (getpoint "\nPick first POINT on the screen:"))
(setq p2 (getpoint "\nPick second POINT on the screen:" p1))
)
(command "_.line" "_non" p1 "_non" p2 "" "_.rotate" (entlast) "" "_non" p2 90)
)
(princ)
)这说明了用户在提示下输入空值,在第二个点提示符中使用橡皮筋,在向命令提供点参数时(通过使用"_non")允许活动对象快照模式,还允许使用非英语版本的AutoCAD (通过使用下划线),以及可能重新定义的命令(通过使用“”)。命令前缀)。
可以通过将CMDECHO系统变量临时设置为0以抑制命令行回波来进一步改进。
https://stackoverflow.com/questions/40950151
复制相似问题