Working with Model-Level Data
Model-level data applies to the entire exchange rather than individual elements. This includes model parameters, model geometries, geometry counts, and viewable coordinates.
Overview
While most exchange data is associated with specific elements, some information applies to the model as a whole:
| Data Type | Description | Use Case |
|---|---|---|
| Model Parameters | Properties that apply to the entire model | Project info, units, coordinate system |
| Model Geometries | Geometry not tied to specific elements | Site context, reference geometry |
| Geometry Counts | Statistics about geometry in the exchange | Performance optimization, validation |
| Viewable Coordinates | Camera and view settings | Default viewing position |
Model Parameters
Model parameters store metadata about the entire exchange:
Set Model Parameters
// Set project-level parameters
elementDataModel.SetModelParameter("ProjectName", "Building A");
elementDataModel.SetModelParameter("ProjectNumber", "PRJ-2024-001");
elementDataModel.SetModelParameter("Units", "Metric");
elementDataModel.SetModelParameter("CoordinateSystem", "WGS84");
elementDataModel.SetModelParameter("Author", "Engineering Team");
elementDataModel.SetModelParameter("CreatedDate", DateTime.UtcNow.ToString("O"));
Get Model Parameters
// Retrieve a specific model parameter
var projectName = elementDataModel.GetModelParameter("ProjectName");
Console.WriteLine($"Project: {projectName}");
// Get all model parameters
var allParams = elementDataModel.GetModelParameters();
foreach (var param in allParams)
{
Console.WriteLine($"{param.Key}: {param.Value}");
}
Show More
Update Model Parameters
// Update existing parameter
elementDataModel.SetModelParameter("LastModified", DateTime.UtcNow.ToString("O"));
elementDataModel.SetModelParameter("RevisionNumber", "3");
Model Geometries
Model geometries represent geometry that isn’t associated with a specific element:
Add Model Geometry
// Add site context geometry
var siteGeometry = ElementDataModel.CreateFileGeometry(
@"C:\models\site-context.stp",
GeometryFormat.Step
);
elementDataModel.AddModelGeometry(siteGeometry, "SiteContext");
// Add reference grid
var gridGeometry = ElementDataModel.CreateFileGeometry(
@"C:\models\reference-grid.obj",
GeometryFormat.Obj
);
elementDataModel.AddModelGeometry(gridGeometry, "ReferenceGrid");
Show More
Retrieve Model Geometries
// Get all model geometries
var modelGeometries = await elementDataModel.GetModelGeometriesAsync();
foreach (var geometry in modelGeometries)
{
Console.WriteLine($"Model geometry: {geometry.Name}");
Console.WriteLine($" Format: {geometry.Format}");
Console.WriteLine($" Size: {geometry.SizeInBytes} bytes");
}
Show More
Geometry Counts
Geometry counts provide statistics about the exchange’s geometric content:
Get Geometry Statistics
// Get geometry count summary
var geometryCounts = elementDataModel.GetGeometryCounts();
Console.WriteLine($"Total elements: {geometryCounts.TotalElements}");
Console.WriteLine($"Elements with geometry: {geometryCounts.ElementsWithGeometry}");
Console.WriteLine($"Total geometries: {geometryCounts.TotalGeometries}");
Console.WriteLine($"STEP geometries: {geometryCounts.StepCount}");
Console.WriteLine($"OBJ geometries: {geometryCounts.ObjCount}");
Console.WriteLine($"Primitive geometries: {geometryCounts.PrimitiveCount}");
Console.WriteLine($"Total size: {geometryCounts.TotalSizeBytes / 1024.0 / 1024.0:F2} MB");
Show More
Use Counts for Validation
// Validate exchange before publishing
var counts = elementDataModel.GetGeometryCounts();
if (counts.ElementsWithGeometry == 0)
{
Console.WriteLine("Warning: No elements have geometry attached");
}
if (counts.TotalSizeBytes > 500 * 1024 * 1024) // 500 MB
{
Console.WriteLine("Warning: Exchange size exceeds recommended limit");
}
Show More
Viewable Coordinates
Viewable coordinates define the default camera position and view settings:
Set Viewable Coordinates
// Set default view for the exchange
elementDataModel.SetViewableCoordinates(new ViewableCoordinates
{
// Camera position
EyePosition = new Point3d(100, 100, 50),
// Point the camera is looking at
TargetPosition = new Point3d(0, 0, 0),
// Up direction
UpVector = new Vector3d(0, 0, 1),
// Field of view (degrees)
FieldOfView = 45,
// Near and far clipping planes
NearClip = 0.1,
FarClip = 10000
});
Show More
Get Viewable Coordinates
// Retrieve current view settings
var viewCoords = elementDataModel.GetViewableCoordinates();
if (viewCoords != null)
{
Console.WriteLine($"Camera at: {viewCoords.EyePosition}");
Console.WriteLine($"Looking at: {viewCoords.TargetPosition}");
Console.WriteLine($"FOV: {viewCoords.FieldOfView}°");
}
Show More
Calculate View from Model Bounds
// Auto-calculate a good default view based on model extents
var bounds = elementDataModel.GetModelBounds();
if (bounds != null)
{
var center = bounds.Center;
var diagonal = bounds.Diagonal;
var distance = diagonal * 1.5; // Camera distance
elementDataModel.SetViewableCoordinates(new ViewableCoordinates
{
EyePosition = new Point3d(
center.X + distance,
center.Y + distance,
center.Z + distance * 0.5
),
TargetPosition = center,
UpVector = new Vector3d(0, 0, 1),
FieldOfView = 45
});
}
Show More
Complete Example
public async Task SetupModelLevelData(IElementDataModel elementDataModel)
{
// 1. Set model parameters
elementDataModel.SetModelParameter("ProjectName", "Office Building");
elementDataModel.SetModelParameter("ProjectNumber", "OB-2024-001");
elementDataModel.SetModelParameter("Units", "Meters");
elementDataModel.SetModelParameter("Author", "Design Team");
elementDataModel.SetModelParameter("CreatedDate", DateTime.UtcNow.ToString("O"));
// 2. Add site context geometry
var siteGeometry = ElementDataModel.CreateFileGeometry(
@"C:\models\site.stp",
GeometryFormat.Step
);
elementDataModel.AddModelGeometry(siteGeometry, "SiteContext");
// 3. Set default view
var bounds = elementDataModel.GetModelBounds();
if (bounds != null)
{
var center = bounds.Center;
var size = Math.Max(bounds.Width, Math.Max(bounds.Height, bounds.Depth));
elementDataModel.SetViewableCoordinates(new ViewableCoordinates
{
EyePosition = new Point3d(center.X + size, center.Y + size, center.Z + size * 0.5),
TargetPosition = center,
UpVector = new Vector3d(0, 0, 1),
FieldOfView = 45
});
}
// 4. Log geometry statistics
var counts = elementDataModel.GetGeometryCounts();
Console.WriteLine($"Exchange contains {counts.TotalElements} elements");
Console.WriteLine($" with {counts.TotalGeometries} geometries");
Console.WriteLine($" total size: {counts.TotalSizeBytes / 1024.0:F1} KB");
// 5. Sync changes
await client.SyncExchangeDataAsync(exchangeIdentifier, elementDataModel.ExchangeData);
}
Show More
Best Practices
- Set model parameters early: Configure project metadata when creating the exchange
- Use meaningful parameter names: Follow a consistent naming convention
- Calculate views automatically: Use model bounds to set sensible default views
- Monitor geometry counts: Check statistics before publishing large exchanges
- Include site context: Add model-level geometry for reference information