AB4D Forum

Full Version: Hierarchy of NamedObjects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have just purchased reader3ds and power tools, so far really impressed but I am a bit lost on how i get the named objects in a model.

This is the code i am using to load in the model (In vb)
Dim file As String = "some location"

Dim modelgroup As New Model3DGroup

Dim Ab4dReader As New Ab3d.Reader3ds
modelGroup = Ab4dReader.ReadFile(file)
Dim ModelVisual3d As New ModelVisual3D
ModelVisual3d.Content = modelGroup
MainViewport.Children.Add(ModelVisual3d)
Dim myreader3ds As New Ab3d.Reader3ds

How can i now see the Hierarchy as a set of strings or lists? Ive looked at the robot arm demo and that is what i am after but i am not quite getting it.

any help would be great

Thanks

Fred
After reading the 3ds file with Reader3ds you can get the names of read objects from NamedObjects dictionary - it is a dictionary where key is the name of the object and value is the 3D object (Model3DGroup, GeometryModel3D, et.)

NamedObjects is very useful if you want to access the read objects by its name - for example:

((GeometryModel3D)myReader3ds.NamedObjects["headObject"]).Material = new DiffuseMaterial(Brushes.Red);

But if you want to iterate though read objects and get their names I would recommend you to convert the NamedObjects dictionary to ObjectNames dictionary - for example:

var namedObjects = myReader3ds.NamedObjects;
var objectNames = new Dictionary<object, string>();
foreach (KeyValuePair<string, object> namedObject in namedObjects)
{
if (namedObject.Value != null)
objectNames[namedObject.Value] = namedObject.Key;
}
Perfect that has solved it :) :)