【问题标题】:AutoLisp trying to move all polyline RECTANGLE to a specific point. Any thoughts?AutoLisp 试图将所有折线矩形移动到特定点。有什么想法吗?
【发布时间】:2020-08-20 14:49:56
【问题描述】:

所以我有这个代码:

    (setq ss (ssget "X" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1) )))
    ;Selecteaza toate Polyline-urile cu 4 colturi, si care sunt inchise.
    (setq n 0
          var (getpoint "Select where to order rentagles")
          )
    (repeat  (sslength ss) ;Parcurge setul de selectie
      (setq tent (entget (ssname ss n))
        telem (assoc 10 tent)
        listvar(cons 10 var))
      (setq
        tent(subst listvar telem tent)
        )
      (entmod tent)
      (setq n (1+ n))
      )
  (princ)
  )

虽然它的作用是,它只将任何矩形的左上角移动到我指定的点。如何对整个矩形执行相同操作,或者如何使用 dxf 代码更改其他角? 提前致谢!

编辑:我已阅读此“10 个顶点坐标(在 OCS 中),多个条目;每个顶点一个条目 DXF:X值; APP:二维点“ 如何使用顶点的其他条目?

【问题讨论】:

    标签: lisp autocad autocad-plugin autolisp


    【解决方案1】:

    您需要计算要对齐的顶点与目标点之间的向量,然后用同一向量平移所有顶点。

    例如(using code from your other question):

    (defun c:moverect ( / a b c d e i p s v x )
        (cond
            (   (not (setq s (ssget "_X" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1)))))
                (princ "\nNo closed polylines found.")
            )
            (   (setq p (getpoint "\nSpecify target point: "))
                (setq p (trans p 1 (trans '(0 0 1) 1 0 t)))
                (repeat (setq i (sslength s))
                    (setq i (1- i)
                          e (ssname s i)
                          x (entget e)
                    )
                    (mapcar 'set '(a b c d) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) x)))
                    (if
                        (and
                            (equal (distance a b) (distance c d) 1e-8)
                            (equal (distance b c) (distance a d) 1e-8)
                            (equal (distance a c) (distance b d) 1e-8)
                        )
                        (progn
                            (setq v (mapcar '- p a))
                            (entmod
                                (mapcar
                                   '(lambda ( x )
                                        (if (= 10 (car x))
                                            (cons 10 (mapcar '+ (cdr x) v))
                                            x
                                        )
                                    )
                                    x
                                )
                            )
                        )
                    )
                )
            )
        )
        (princ)
    )
    

    但是,请注意,与目标点对齐的顶点将取决于 2D 多段线的方向 - 您可能希望包含一个测试以始终选择要对齐的左下角顶点 - 您将然后需要决定如何处理旋转的矩形。

    【讨论】:

    • 你能给我一个例子吗?我在这个例子中的代码?我仍然是初学者,使用这些功能对我来说似乎违反直觉......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    相关资源
    最近更新 更多