Is there a preferred way to replace a TxSolid Object in PS API?
if i perform the following
// Gives me object to replace
var child = GetChild();
var create = new TxSphereCreationData("test",transformation,radius);
var obj = parentObject.CreateSolidSphere(create);
child = obj;
The problem here is that at times, all of the info for the object is unavailable.
The only thing i need to do is modify the Geometry for the object but in order to do so, i need to create a new object. therefore, i need to replace the old object with the new one.
In order to change the geometry, you need to create a new solid and delete the old one. You can change the location or the color of existing solid, but not the geometry.
When you say "The problem here is that at times, all of the info for the object is unavailable." - what is the problem that you face, can you elaborate on that?
I think that problem lies within my own faults and the tracking of objects.
Its similar to the following
TxSolid content; this.DataContext = content; var create = new TxSphereCreationData(); var newContent= content.Collection.CreateSolidSphere(create); // The data context needs to be changed to the new data this.DataContext= newContent.
This ends up doing several things.. One is that the old object (Lets call it sphere1) gets deleted in PS and replaced with the new. Now if Sphere1 was at the top of the collection, its visual index is now at the bottom because it was the last item entered. My treeview now is visually different from the object viewer in PS.
The second and bigger issue, is that somewhere within my code, I now have the old data attached to my application where it needs to be attached to the new data. I just need to find out where and why its not getting replaced with the new.
Maybe you can create a ViewModel that will interact with the TxSolid, so you will not change the DataContext, but update it.
The last object you create within a TXComponent will always be on the bottom of the visual tree in Process Simulate when using one of its ".Create" methods.
You may want to look into writing an extension that will sort the Component's children the way you want it to appear.
As to your data context issues I would need a bigger sample than the below shows. If you are creating a MVVM based WPF application I try to avoid setting data contexts like you are doing. I favor binding a main view model once to the control when it instantiates, for it solves so many of the data binding issues like this.
What Diana said above is the perfect solution. Create a list of the view models created to build out the tree. Use a ListCollection to sort the list, or just add a .Sort Extenstion to Observable Collection's