RhinoCommon - Removing User Data


#21

I save user data on PointGeometry.

there is no method to replace the point geometry.

help please…


#22

Hi @dale,

I am unable to get the sample to work successfully by using the userdata to store a list of guids

the undo does not revert the list in the userdata back to the previous list.
the string is reverted.

Kindly check and let me know how to handle this.


(Dale Fugier) #23

In the project, review these sample files:

SampleCsAddUserData.cs
SampleCsModifyUserData.cs
SampleCsRemoveUserData.cs

– Dale


#24

Kindly identify what’s wrong.
SampleCsUserDataObject.cs (2.4 KB)
SampleCsAddUserData.cs (2.0 KB)
SampleCsModifyUserData.cs (2.0 KB)

Its the same files from the sample project but included a list.

steps:

  • call sample add
  • call sample modify
  • undo

the object still has 2 ids.

I have used the dictionary so that i can have multiple guid list.


#25

Hi @dale,

did you manage to reproduce this issue using the files?

any solution?


(Dale Fugier) #26

Make sure your user data’s OnDuplicate actucally copies the data, not just the reference to the data.

SampleCsUserDataObject.cs (2.1 KB)

– Dale


#27

Hi @dale,

Your samples have helped a lot. Thank you.

You have used the UserData in the attributes and used the following line to override it,
doc.Objects.ModifyAttributes(obj, new_attributes, true);

If I intend to use the UserData in the geometry to save data, I assume it has to be
doc.Objects.Replace(obj.Id, new_geometry);

But this returns false.

How can the userdata in geometry be used successfully?

Also, I save user data on PointGeometry.
there is no method to replace the point geometry.


(Dale Fugier) #28

Hi @HepChan,

Can you provide the source code that is not working for you?

Yes, this is true. This has been resolved in the Rhino WIP.

– Dale


#29

I figured that this line in the code before the replacement makes it to return false.

        ObjectAttributes oa = new ObjectAttributes();
        oa.Mode = ObjectMode.Hidden;
        obj.Attributes = oa;
        obj.CommitChanges();

SampleCsModifyUserData.cs (3.1 KB)

Why cant the geometry be replaced on a hidden object?

is there any other way to achieve the hiding before the replacement.


#30

Hi @dale

Any help on this?


(Dale Fugier) #31

Hi @HepChan,

If I understand correctly, you want to attached a piece of user data to selected object and then hide the object. Is this correct?

Why do you need to attach user data to geometry and not to the object’s attributes?

– Dale


#32

The real requirement is, I want to modify the user data of a hidden object (which fails).

is there specific criteria which user data to be used??

I chose geometry as i use the commands on the geometry of the objects.


(Dale Fugier) #33

In general, we try to encourage developers to attach user data to an object’s attributes, rather than it’s geometry, as it tends to survive “better”.

But if you want to attached user data and hide the object too, then replace the object’s geometry first and then modify the attributes to hide it (rather than the opposite order you are trying now).

– Dale