AB4D Forum

Full Version: Associate data with Visual3d objects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any way to associate data with your Visual3d objects? For example, imagine a drawing of a 3d truss made out of cylindrical steel tubes created with your TubeVisual3D class. I want to be able to click on one of the truss elements, access the data object, and access information about the truss element such as material name, manufacturer, cost, length, etc.

In other words, I'm looking for simple BIM functionality. Is that something you support now or is it something you would consider adding? Thanks!
In WPF most of the objects are derived from DependencyObject (ModelVisual3D and other Visual3D objects from Ab3d.PowerToys are also derived from that class). This means that you can add any DependencyProperty to the object.

For example if you want to add your own class, for example ModelDetails, to a TubeVisual3D, you will first need to define a new DependencyProperty that will hold the ModelDetails:

Code:
class ModelDetails
{
// ... some other code

public static readonly DependencyProperty ModelDetailsProperty = DependencyProperty.Register("ModelDetails", typeof(ModelDetails), typeof(ModelDetails));

// ... some other code
}

This will define the ModelDetailsProperty inside the ModelDetails class. Note that in Register method the first typeof defines the type of the DependencyProperty and the second typeof defines the owner type.

After that you can assign the ModelDetails to an instance of TubeVisual3D (or any other DependencyObject) with using SetValue:

Code:
myTubeVisual.SetValue(ModelDetails.ModelDetailsProperty, myTubeVisualModelDetails);

Then in your click event handler you can read the data with GetValue method:

Code:
var clickedModelDetails = clickedVisual3D.GetValue(ModelDetails.ModelDetailsProperty) as ModelDetails;
I just tried that out and it works great! Thanks so much for your quick reply!