.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

XData with Copy Command

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Keith.Brown
1920 Views, 6 Replies

XData with Copy Command

I am storing xdata on objects to create links between the objects.  In particular, I am storing a point at which the link occurs and a handle to the object.  I am storing the point as a 3D World Position (DXF Code 1011) and the Handle as a Database Handle (DXF Code 1005).  If i copy/paste using ctrl-c and ctrl-v the handles will update to the newly pasted handle if it exists.  What i mean is that if the linked object is copied also then it will get updated otherwise it will be changed to a new handle value (0).  All of this is expected and wanted behavior.  However, if i use the copy command then the Handles will not update.  Is it possible to get it to work in the same manner as when using the windows copy/past functions?

6 REPLIES 6
Message 2 of 7
FRFR1426
in reply to: Keith.Brown

The COPY command uses deepClone() whereas COPYCLIP uses wblockCloneObjects(). deepClone() does not translate ids, wblockCloneObjects() can if its last argument (deferXlation) is false (the default).

 

In order to make it works with COPY and other commands like ARRAY and MIRROR, you have to handle the database events related to deep cloning: BeginDeepCloneTranslation, DeepCloneAborted and DeepCloneEnded. 

 

I think you can also use a CopyOverrule. See this post from Kean: https://www.keanw.com/2009/05/using-an-autocad-2010-overrule-to-control-the-copying-of-xdata-using-n...

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 7
gphanauer
in reply to: FRFR1426

I am really confused.
I always found that when an object is copied it follows shallow clone and that means XData are copied too.
In my view depending on the situation handles stored in XData using the dxf 1005 code are sometimes copied and sometimes not copied.
As there is no guarantee that handles stored in XData are copied and it is necessary to handle this via code would it not be better to store as SoftPointerIds in an Xrecord once they are automatically translated?

Message 4 of 7
FRFR1426
in reply to: gphanauer

The ObjectARX docs says:

 

Note When drawings are combined by means of INSERT, INSERT *, XREF Bind (XBIND), or partial DXFIN, handles are translated so that they become valid in the current drawing. (If the incoming drawing did not employ handles, new ones are assigned.) Extended entity handles that refer to incoming entities are also translated when these commands are invoked.

and

 

Utilize the object ownership/pointer reference fields (330–369) to maintain internal database object references. Arbitrary handle values are completely exempt from the object ID translation mechanics. This is opposed to 1005 xdata groups, which are translated in some cases but not in others.

and

Database handle 1005. Handles of entities in the drawing database. Under certain conditions, AutoCAD translates these.

Not very useful...

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 5 of 7
FRFR1426
in reply to: FRFR1426

And there is also the BLOCK/EXPLODE case:

 

When an entity is placed in a block definition (by means of the BLOCK command), the entity within the block is assigned new handles. (If the original entity is restored with OOPS, it retains its original handles.) The value of any extended data handles remains unchanged. When a block is exploded (with EXPLODE), extended data handles are translated, in a manner similar to the way they are translated when drawings are combined. If the extended data handle refers to an entity not within the block, it is unchanged; but if the extended data handle refers to an entity within the block, it is assigned the value of the new (exploded) entity's handle.
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 6 of 7
gphanauer
in reply to: FRFR1426

I am still learning and not a professional programmer.
ObjectARX Guide content is one of the few sources of information available, but its teaching is terrible and does not help much in this case. Only theory is found, there are no examples on this subject or in ObjectARX: Managed .NET Developer's Guide. Incidentally, poorly designed manuals have become something of everyday life.
Good .NET content is in Autodesk University 2010, CP230-1V - AutoCAD® .NET - Practical Examples of Customizing AutoCAD Entity Behavior. XData can be found in CustomLeader example and XRecords in Network example.
From the literature:

  • Shallow Cloning: make a copy of an object which already exists in a database.
  • Deep Clone: ​​clones an object and its hard / soft ownership references, hard / soft pointer references are not cloned.
  • Wblock Clone: ​​clones hard owners and hard pointers and ignores any soft references.

If anyone can confirm and / or explain further:

XData:

  • CopyClip (ctrl-c) uses WblockClone. References are translated (right).
  • PasteClip (ctrl-v) uses Insert (DeepClone). References are translated (right).
  • Copy, mirror, array, ..., uses DeepClone. References are not translated (manage via code).

So the solution is to use XRecord with soft / hard ownership / pointer reference group code in extension dictionary, since AutoCAD correctly translates references with copy, mirror, array and so on. And don't forget to set DBDictionary.TreatElementsAsHard to true.

XRecord:

  • Copy, mirror, array, ..., uses DeepClone. References are translated (right).
  • CopyClip uses WblockClone, so it follows HardPointerIds (right) and ignore softPointerIds (manage via code).
  • PasteClip uses Insert (DeepClone), so it doesn't follow Hard / SoftPointerIds references (manage via code).

Everything is fine when your .NET plugin is loaded and the code you have written manages what to do when objects are cloned but when the plugin is not loaded ....
Another thing, the documentation says that handles of objects in the drawing do not change. Does it really not change? If you use break, trim, audit? Oh, I suppose a new object has been generated, and of course it will have another handle!

Message 7 of 7
Keith.Brown
in reply to: Keith.Brown

Thank you for the replies and I apologize for taking so long to get back to this question.  For my particular case, i broke the handles out of the xdata and instead used hardpointers in an xrecord stored in the extension dictionary.  This gave me the functionality that works for me right now.  Object references are handled automatically during copying in the current drawing and point data is automatically updated when the entity is moved/copied.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost