lisp - 一个实体中的对象 react 器 "copied"和 "modified"出错了 - 需要帮助

标签 lisp autocad autocad-plugin autolisp

我的意图是创建一些包含两个文本的行,每个文本都有简短的信息(作为一个组制作),并让 react 器分配给该行确保:

  1. 复制时,每个实体的句柄将更新为其他实体的信息,并且
  2. 如果我使用末端夹点拉伸(stretch)线条,线条 react 器会将线条的长度更新为存储的扩展数据,并更新与长度对应的文本值。

到目前为止,在这个论坛的宝贵帮助下,我能够复制故事的一部分。当我尝试将“已修改”选项合并到 react 器中时,它不起作用。下面是我使用的代码。

第一个函数在创建过程中通过另一个函数将 react 器分配给线路,此处未显示。剩下的就是回调等等。任何建议表示赞赏。

继续这个问题:

How to update xdata information of an entity when it is copied

(defun assign_LLreactor (LL_ename LL_Length LL_Size / LL_ename LL_hLength LL_hSize)
    (if (= 'vlr-object-reactor (type lineReactor))      
        (vlr-owner-add lineReactor (vlax-ename->vla-object LL_ename))
        (vlr-set-notification
            (setq lineReactor
                (vlr-object-reactor (list (vlax-ename->vla-object LL_ename)) "Line Reactor"
                    '(
                        (:vlr-modified . LL_callback_mod)
                        (:vlr-copied . LL_callback)
                    )
                )
            )
            'active-document-only
        )
    )

    (makeagroup (ssadd (handent LL_Length) (ssadd (handent LL_Size) (ssadd LL_ename (ssadd)))))
)

(defun LL_callback (notifierobj reactorobj paramls)
    (if (/= 0 (car paramls))
        (progn
            (setq LL_owner (append LL_owner (list (car paramls))))
            (vlr-command-reactor "LL_copied_re"
               '(
                    (:vlr-commandended     . LL_copyended)
                    (:vlr-commandcancelled . LL_copycancelled)
                    (:vlr-commandfailed    . LL_copycancelled)
                )
            )
        )
    )
)

(defun LL_callback_mod (owner reactorobj paramls)
    (setq LL_owner (append LL_owner (list owner)))
    (vlr-command-reactor "LL_modified_re"
       '(
            (:vlr-commandended     . LL_modifiedended)
            (:vlr-commandcancelled . LL_modifiedcancelled)
            (:vlr-commandfailed    . LL_modifiedcancelled)
        )
    )
)

(defun LL_copyended ( reactor params / enametxt txt1 txt2 hSize hLength groupedentities txthandles grtxtdata)
    (vlr-remove reactor)

    (if
        (and
            (setq LL_ent (car LL_owner))
            (setq LL_enx (entget LL_ent '("LL_U")))
            (= (cdr (assoc 0 LL_enx)) "LINE")
            (setq LL_3data (assoc -3 LL_enx))
        )
        (progn
            (foreach n (setq groupedentities (_groupedenames LL_ent))
                (if (= (cdr (assoc 0 (setq grtxtdata (entget n '("LL_U"))))) "TEXT")
                    (progn
                        (setq txthandles (append txthandles (list (cdr (assoc 5 grtxtdata)))))
                        (entmod (subst (list -3 (list "LL_U" (cons 1005 (cdr (assoc 5 LL_enx))))) (assoc -3 grtxtdata) grtxtdata))
                    )
                )
            )
            (setq txthandles (vl-sort txthandles (function (lambda (a b) (< a b)))))
            (entmod (subst (list -3 (list "LL_U" (cons 1005 (cadr txthandles)) (cons 1005 (car txthandles)))) (assoc -3 LL_enx) LL_enx))
        )
    )

    (if (and LL_enx (= 'vlr-object-reactor (type lineReactor)))
        (vlr-owner-add lineReactor (vlax-ename->vla-object LL_ent))
    )

    (setq LL_owner (cdr LL_owner))
    (princ)
)

(defun LL_modifiedended ( reactor params / LL_ent LL_enx llpt10 llpt11 LL_3data LL_3data_n)
    (if
        (and
            (setq LL_ent (car LL_owner))
            (setq LL_enx (entget LL_ent '("Pdata")))
            (= (cdr (assoc 0 LL_enx)) "LINE")
            (setq LL_3data (assoc -3 LL_enx))
        )
        (progn
            (if (= 'vlr-object-reactor (type lineReactor))
                (vlr-remove lineReactor)
            )
            (setq llpt10 (cdr (assoc 10 LL_enx)))
            (setq llpt11 (cdr (assoc 11 LL_enx)))
            (setq LL_3data_n (list -3 (subst (cons 1000 (rtos (distance llpt10 llpt11) 2 3)) (nth 2 (cadr LL_3data)) (cadr LL_3data))))
            (ht_ss (ssadd (cdr (assoc -1 (entmod (subst LL_3data_n (assoc -3 LL_enx) LL_enx)))) (ssadd)))

            (if (= 'vlr-object-reactor (type lineReactor))
                (vlr-add lineReactor)
            )
        )
    )
    (princ)
)

(defun LL_copycancelled ( reactor params )
    (vlr-remove reactor)
    (setq LL_owner nil)
    (princ)
)

(defun LL_modifiedcancelled ( reactor params )
    (vlr-remove reactor)
    (setq LL_owner nil)
    (princ)
)

我希望对象 react 器适用于“修改”和“复制”操作,用于拉伸(stretch)或复制更新的 xdata 和文本的行。

最佳答案

因此,我设法通过为特定 react 器类型(例如“复制”或“修改”)的所有者使用单独的列表来解决问题。所以“LL_owner”列表变成了两个,“LL_copy_owner”和“LL_mod_owner”。现在它工作正常(直到另行通知:)。

关于lisp - 一个实体中的对象 react 器 "copied"和 "modified"出错了 - 需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57170631/

相关文章:

vim - 设置负载噪音时出错?并在 MIT-Scheme 中自动退出

algorithm - 逆向算法LISP的实现

lisp - 来自 "Realm of Racket"的奇怪代码示例

VBA循环遍历集合

excel - Autocad 2017 提取 Xdata excel lisp

vba - VBA 是否保留过去代码更改的缓存?

sorting - Lisp - 检查列表是否已排序

c# - 在 AutoCAD 中限制另一个形状内的形状移动

autocad - .net中有一种方法可以获取折线的质心吗?

autocad - 在 Lisp 退出时执行代码