AB4D Forum

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

I have been struggling with getting the name of a clicked object,

using the following code i can grasp the 3d model hit and change its color but i am struggling to get its name.

................
If rayMeshResult IsNot Nothing Then
Dim hitgeo As GeometryModel3D = TryCast(rayMeshResult.ModelHit, GeometryModel3D)

Dim mo As Model3D = (rayMeshResult.ModelHit)

end if

How can i now get the "GetNamedObjectsText"

any help much appreciated

fred
If you have read the 3D models with Ab3d.Reader3ds, than Reader3ds fills NamedObjects dictionary (Dictionary<string, object>) that have names as keys and objects as values. This dictionary can be used to get the object from its name.

But if you need to get name from the object, I would recommend to convert the NamedObjects dictionary into objectNames dictionary where object is set as key and name as value.

The following code in csharp (sorry I am not very familiar with VB):

// create a new dictionary with objects as values
objectNames = new Dictionary<object, string>();
foreach (KeyValuePair<string, object> namedObject in namedObjects)
{
if (namedObject.Value != null)
objectNames[namedObject.Value] = namedObject.Key;
}

Than you can get the name of your object simply with:

string objectsName = objectNames[hitModel];
Perfect that has saved me a load of time thanks.

fred