【问题标题】:AutoLISP - Change multiply layers by selecting multiply objectsAutoLISP - 通过选择多个对象来更改多个图层
【发布时间】:2018-12-12 12:27:54
【问题描述】:

我正在尝试创建一个 AutoLISP 函数,该函数采用选择集图层并将其存储在变量中。 我想选择multiple objects,它总是在同一层,然后用一些命令改变层。

我已经尝试了以下,基于(setq currentlayer (assoc 8 (entget (car (entsel)) )))

我的代码是:

(defun c:objectslayer()
    (setq objects (car (ssget)))                    ; Need to select multiply objects
    (setq currentlayer (entget objects))            ; Need the layer of the objects, in my case, it will allways be in the same layer
    (setq cl (assoc 8 currentlayer))                ; Need the layer, for commands to change the layer later
    (prompt (strcat "\nThe layer of the objects is: " cl))
(princ)
)

感谢所有的帮助和指导

提前致谢

【问题讨论】:

    标签: autolisp


    【解决方案1】:

    如果不向 ssget 函数提供过滤器列表参数,则无法保证选择中的所有对象都位于同一层上。

    如果您的程序针对特定层,那么我建议使用过滤器列表来仅允许选择驻留在该层上的对象,例如:

    (ssget '((8 . "YourLayerHere")))
    

    或者,您可以提示选择单个对象来设置目标层(使用entsel),然后使用ssget 提示选择驻留在该层上的多个对象,并使用使用构建的过滤器列表从entsel 获取的实体层例如:

    (if
        (and
            (setq ent (car (entsel "\nSelect object on target layer: ")))
            (setq sel (ssget (list (assoc 8 (entget ent)))))
        )
        (progn
            ;; Do some operations ...
        )
    )
    

    如果您真的想允许用户选择任何层上的对象,那么要获得所选层的列表,您可以使用类似:

    (defun c:test ( / idx lay lst sel )
        (if (setq sel (ssget))
            (progn
                (repeat (setq idx (sslength sel))
                    (setq idx (1- idx)
                          lay (cdr (assoc 8 (entget (ssname sel idx))))
                    )
                    (if (not (member lay lst)) (setq lst (cons lay lst)))
                )
                (print lst)
            )
        )
        (princ)
    )
    

    有关如何迭代选择集中的对象的更多信息,您可能希望参考我在Selection Set Processing 上的教程。

    【讨论】:

    • 很好的解释...您使用(setq lst (cons lay lst)) 瞬间append 的方式令人印象深刻。
    • @DineshVilasPawar 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-09-21
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 2013-10-12
    • 2012-11-12
    相关资源
    最近更新 更多