复制实体时如何更新实体的xdata信息 [英] How to update xdata information of an entity when it is copied

查看:128
本文介绍了复制实体时如何更新实体的xdata信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条文本与一行相关.因为文本代表该行的某些数据,所以它们始终被视为该行的子级,并且在该行旁边可见.通过一些lisp例程,如果行的数据发生更改,则文本实体将通过更改其文本来反映该更改.为此,我将每个文本的行句柄存储为xdata,反之亦然,例如文本的句柄.

I have two texts associated to a line. Because the texts represent some data of the line they are always considered children of the line and visible next to it. Through some lisp routines, if the data of the line change, the text entities reflect the change by changing their text. For that I have stored the handle of the line to each text as xdata and vice versa, e.g. the handles of the texts into the line.

当我用文本复制行时会出现问题,每个文本都有一个新的句柄,但是存储的xdata提供了旧的句柄,这会导致进一步的问题.我以为vlr-copied反应堆可以解决我的问题,但是由于我对反应堆不是很熟练,所以我似乎无法使其工作.

The problem arises when I copy the line with the texts where each one gets a new handle but the stored xdata are giving the old handles which leads to further problems. I thought the vlr-copied reactor could solve my problem but since I am not very proficient with reactors I cant seem to make it work.

有人可以指出我正确的方向吗?我找到了

Could someone point me to the right direction? I found this

http://www.theswamp.org/index.php?topic=42654.0

但是我无法理解选择行集时(包括不相关的其他实体)如何将正确的选择集传递到反应堆并更新手柄.

but I cannot understand when I make a selection set of lines but also including non relevant other entities, how to pass the correct selection set to the reactor and get the handles updated.

任何建议表示赞赏.谢谢你.

Any suggestion appreciated. Thank you.

推荐答案

首先,您需要确定对象要表现出的行为,并假设对象(文本或行)中的任何一个都独立于另一个被复制.由于两个对象已链接,因此您可能需要确定哪个对象是'master'和哪个对象是'slave'.

Firstly, you need to decide on the behaviour that you want the objects to exhibit assuming that either object (text or line) is copied independently of the other. Since the two objects are linked, you may need to decide which object is the 'master' and which is the 'slave'.

例如,如果文本对象被复制到空白区域,则由于没有可引用的行,因此您可能决定删除结果副本.而如果将行复制到空白区域,则可以决定复制关联的文本对象,并将其相对于新行放置.

For example, if the text object is copied into empty space, you might decide that the resulting copy should be deleted, since there is no line to which it could refer. Whereas, if the line is copied into empty space, you might decide to replicate the associated text object and position it relative to the new line.

这是我在开发关联文本框应用程序(实质上是解决了将图形中的两个对象(在我的情况下为文本对象和边界框架)关联的相同问题.

This is the approach that I followed when developing my Associative Textbox application (which is essentially solving the same problem of associating two objects in a drawing - in my case, a text object and a bounding frame).

在我的应用程序中,我使用一个单独的对象反应器分别处理文本对象和文本框的修改事件:

In my application, I use a separate Object Reactor to handle the modification events for the text object and textbox respectively:

(vlr-object-reactor txt "tbox-textreactor"
   '(
        (:vlr-modified . tbox:textcallback)
        (:vlr-copied   . tbox:textcopied)
    )
)

(vlr-object-reactor box "tbox-tboxreactor"
   '(
        (:vlr-modified . tbox:tboxcallback)
        (:vlr-copied   . tbox:tboxcopied)
    )
)

类似于您的设置,它们是内置的&使用附加到文本和文本框的扩展实体数据(xData)在程序加载时进行配置.

Similar to your setup, these are built & configured on program load using Extended Entity Data (xData) attached to both the text and textbox.

当触发texbox的Copy事件(评估tbox:tboxcopied回调函数)时,我认为没有文本框,文本框就无法生存,因此我从图形中删除了孤立的文本框.

When the Copy event for the texbox is fired (evaluating the tbox:tboxcopied callback function), I decide that a textbox cannot live without the text it encloses, and so I delete the orphan textbox from the drawing.

但是,使用对象反应器时必须记住的最重要一点是您不能在其自身的回调函数中修改对象反应器的所有者.

However, the most important point that you have to remember when working with object reactors is that you cannot modify the owner of an object reactor within its own callback function.

这样,对于所有需要修改事件所有者的修改事件,我都会生成一个临时的Command Reactor,它将在对象被修改后触发 ,以确保该对象未锁定修改.

As such, for all modification events in which I need to modify the owner of the event, I generate a temporary Command Reactor which will fire after the object has been modified, so as to ensure that the object is not locked for modification.

例如,对于文本框复制事件,我使用以下内容:

For example, for the textbox copy event, I use the following:

(defun tbox:tboxcopied ( owner reactor params )
    (if (/= 0 (car params))
        (progn
            (setq tbox:owner (append tbox:owner (list (car params))))
            (vlr-command-reactor "tbox-tboxcopiedcommreactor"
               '(
                    (:vlr-commandended     . tbox:tboxcopiedcommandended)
                    (:vlr-commandcancelled . tbox:tboxcopiedcommandcancelled)
                    (:vlr-commandfailed    . tbox:tboxcopiedcommandcancelled)
                )
            )            
        )
    )
    (princ)
)

然后我在其自己的任何回调函数中删除此临时Command Reactor,以防止冗余反应堆在图形中传播:

I then remove this temporary Command Reactor within any of its own callback functions so as to prevent the propagation of redundant reactors in the drawing:

(defun tbox:tboxcopiedcommandended ( reactor params / ent )
    (vlr-remove reactor) ;; <----- Remove temporary Command Reactor
    (if
        (and
            (setq ent (car tbox:owner))
            (member (cdr (assoc 0 (entget ent))) '("CIRCLE" "LWPOLYLINE"))
        )
        (entdel ent) ;; <----- Delete orphan textbox
    )
    (setq tbox:owner (cdr tbox:owner))
    (princ)
)


在复制文本时,我将重新创建周围的文本框并建立新的关联(同样,生成临时Command Reactor以便于修改文本对象本身):


Whereas, when the text is copied, I recreate the surrounding textbox and build the new association (again, generating a temporary Command Reactor to facilitate modification of the text object itself):

(defun tbox:textcopied ( owner reactor params )
    (if (/= 0 (car params))
        (progn
            (setq tbox:owner (append tbox:owner (list (car params))))
            (vlr-command-reactor "tbox-textcopiedcommreactor"
               '(
                    (:vlr-commandended     . tbox:textcopiedcommandended)
                    (:vlr-commandcancelled . tbox:textcopiedcommandcancelled)
                    (:vlr-commandfailed    . tbox:textcopiedcommandcancelled)
                )
            )
        )
    )
    (princ)
)

...并重新创建适当的文本框,作为临时Command Reactor的回调函数的一部分:

...and recreate the appropriate textbox as part of the callback function for the temporary Command Reactor:

(defun tbox:textcopiedcommandended ( reactor params / box ent enx val )
    (vlr-remove reactor) ;; <----- Remove temporary Command Reactor
    (if
        (and
            (setq ent (car tbox:owner))
            (setq enx (entget ent (list tbox:app)))
            (member (cdr (assoc 0 enx)) '("TEXT" "MTEXT"))
            (setq val (cdadr (assoc -3 enx)))
            (setq box (tbox:createbox enx (cdr (assoc 1000 val)) (cdr (assoc 1040 val))))
        )
        (progn
            (entmod
                (append (vl-remove (assoc 40 enx) (entget ent))
                    (list
                        (list -3
                            (list tbox:app
                               '(1002 . "{")
                                (cons  1005 (cdr (assoc 5 (entget box))))
                                (assoc 1000 val)
                                (assoc 1040 val)
                               '(1002 . "}")
                            )
                        )
                    )
                )
            )
            (if (= 'vlr-object-reactor (type tbox:textreactor))
                (vlr-owner-add tbox:textreactor (vlax-ename->vla-object ent))
            )
            (if (= 'vlr-object-reactor (type tbox:tboxreactor))
                (vlr-owner-add tbox:tboxreactor (vlax-ename->vla-object box))
            )                    
        )            
    )
    (setq tbox:owner (cdr tbox:owner))
    (princ)
)


上面介绍的方法是我为您的情况推荐的方法:


And the methods I have described above is the approach that I would recommend for your scenario:

复制文本后,删除结果的孤立文本对象;复制时,创建相应的文本对象,并在复制的行和行之间建立关联.新的文字对象.

这篇关于复制实体时如何更新实体的xdata信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆