【问题标题】:AutoCad rotate command with AutoLisp带有 AutoLisp 的 AutoCad 旋转命令
【发布时间】:2017-04-18 10:09:38
【问题描述】:

我想用 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" ... 线有问题。

任何建议将不胜感激。

【问题讨论】:

  • 附带说明,entlast 将返回最后一个对象。如果您在 p2 有多个对象,这可以防止出现问题。
  • 我已经有一段时间没有使用 AutoLisp 了,但是您的 "90" 应该改为 90 吗?
  • @crashmstr 有几个教程使用"90",没有使用90
  • 我找到了一些例子并写了一个应该有帮助的答案。

标签: autocad autolisp


【解决方案1】:

我建议使用以下简化代码:

(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 来抑制命令行回显来进一步改进。

【讨论】:

    【解决方案2】:

    从我在网上看到的,你有两个问题。

    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: Rotate Multiple Objects Around Their Base Point

    附带说明一下,它通常可以帮助我手动尝试该命令,以确保您使用正确的数据/值响应所有正确的提示。

    【讨论】:

      猜你喜欢
      • 2014-06-25
      • 2016-06-25
      • 2010-12-15
      • 2018-06-10
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 2011-09-06
      • 1970-01-01
      相关资源
      最近更新 更多