Update an Exchange Container
The Data Exchange SDK facilitates the updating of the exchange container through modifications to the element’s parameters, transformations, and geometry. It also has the ability to delete existing parameters and update their values.
Update Parameters
The Element class features an UpdateInstanceParameter method designed for parameter updates. This method requires “SchemaId” and updated “Value”.
var response = Element.UpdateParameter("SchemaId", "Value"); if (response.IsFailed)
{
// Handle error
}
Delete Parameters
To delete a parameter you can call the DeleteInstanceParameter method on the Element class. This method requires the SchemaId to facilitate the deletion of a parameter.
var response = Element.DeleteParameter("SchemaId"); if (response.IsFailed)
{
// Handle error
}
Update Geometry Parameters
Change parameter values on individual geometry objects while preserving element-level parameters. Use single updates for quick changes or batch updates for better performance when modifying multiple parameters.
Update Single Geometry Parameter
// Get the geometry
var geometries = await ElementDataModel.GetElementGeometriesByElementsAsync(
new[] { element }
);
var geometry = geometries[element].FirstOrDefault();
if (geometry != null)
{
// Find the parameter to update
var materialParam = geometry.Parameters
.FirstOrDefault(p => p.Name == "Material");
if (materialParam != null)
{
// Update the parameter value
var updatedParam = geometry.UpdateParameter(
materialParam.SchemaId,
new ParameterDataType("Aluminum")
);
Console.WriteLine($"Updated material to: {updatedParam.Value}");
}
}
Batch Update Geometry Parameters
Use UpdateParameters for efficient batch updates:
var geometry = geometries[element].FirstOrDefault();
if (geometry != null)
{
// Prepare updates dictionary
var updates = new Dictionary<string, ParameterDataType>();
var materialParam = geometry.Parameters.FirstOrDefault(p => p.Name == "Material");
var thicknessParam = geometry.Parameters.FirstOrDefault(p => p.Name == "Thickness");
var finishParam = geometry.Parameters.FirstOrDefault(p => p.Name == "Finish");
if (materialParam != null)
updates[materialParam.SchemaId] = new ParameterDataType("Steel");
if (thicknessParam != null)
updates[thicknessParam.SchemaId] = new ParameterDataType(5.5);
if (finishParam != null)
updates[finishParam.SchemaId] = new ParameterDataType("Galvanized");
// Apply all updates at once
var updatedParams = geometry.UpdateParameters(updates);
foreach (var param in updatedParams)
{
Console.WriteLine($"Updated {param.Name} to {param.Value}");
}
}
Delete Geometry Parameters
Remove parameters from individual geometry objects without affecting element-level parameters or other geometries. Deletion is permanent once the exchange is saved.
Delete Single Geometry Parameter
var geometry = geometries[element].FirstOrDefault();
if (geometry != null)
{
// Find the parameter to delete
var obsoleteParam = geometry.Parameters
.FirstOrDefault(p => p.Name == "TemporaryMark");
if (obsoleteParam != null)
{
bool deleted = geometry.DeleteParameter(obsoleteParam.SchemaId);
if (deleted)
{
Console.WriteLine($"Deleted parameter: {obsoleteParam.Name}");
}
}
}
Delete Multiple Geometry Parameters
var geometry = geometries[element].FirstOrDefault();
if (geometry != null)
{
// Delete all custom parameters
var customParams = geometry.Parameters
.Where(p => p.SchemaId.StartsWith("exchange.parameter.custom:"))
.ToList();
foreach (var param in customParams)
{
bool deleted = geometry.DeleteParameter(param.SchemaId);
Console.WriteLine($"Deleted {param.Name}: {deleted}");
}
}
For comprehensive information on working with geometry parameters, including creation and retrieval, see Working with Geometry Parameters.
Related operations:
- Add Parameters to Geometry - Create geometry parameters
- Retrieve Parameters from Geometry - Read geometry parameters
Update Transformation
To modify the transformation of an element, set the Transformation property directly on the element:
// Get the element to update
var element = ElementDataModel.Elements.FirstOrDefault(e => e.Id == "ElementId");
if (element != null)
{
// Set transformation directly on the element
element.Transformation = new Transformation
{
Matrix = new Matrix4d(new double[]
{
0.525321989, -0.8509035245341184, 0, 2,
0.8509035245341184, 0.525321989, 0, 2,
0, 0, 1, 2,
0, 0, 0, 1
})
};
}
Note: The
UpdateElement()method has been removed. Use direct property assignment instead. See the Migration Guide for details.
Update Element Category and Type
Change an element’s category or type after creation using SetElementCategory and SetElementType:
// Get an existing element by ID or name
var element = elementDataModel.Elements.FirstOrDefault(e => e.Id == "wall-001");
if (element != null)
{
// Change the element's category
elementDataModel.SetElementCategory(element, "Fire-Rated Walls");
// Change the element's type
elementDataModel.SetElementType(element, "2-Hour Fire Wall");
}
Use cases:
- Reclassifying elements based on updated design requirements
- Correcting category/type assignments after initial creation
- Updating elements to match changed building codes or specifications
Update Geometry
Primitive, Brep/Mesh: We have seen how to use the method ElementDataModel.SetElementGeometry to associate geometry with an element. This same function can also be used to update the geometry associated with the element.
var response = ElementDataModel.SetElementGeometry(OldElement, NewElementGeometry); if (response.IsFailed)
{
// Handle error
}
This function will substitute the existing geometry with the new one.
Publish
After data has been updated in the ElementDataModel wrapper, these updates will need to be published/synced to the Data Exchange, as at this point all the updates are done on the local ElementDataModel wrapper only.
To sync the updates to the DataExchange call the SyncExchangeDataAsync on the IClient interface.
var ExchangeIdentifier = new DataExchangeIdentifier
{
CollectionId = CollectionID,
ExchangeId = ExchangeID,
HubId = hubId
};
var UpdatedExchangeData = ElementDataModel.ExchangeData;
var response = await IClient.SyncExchangeDataAsync(ExchangeIdentifier, UpdatedExchangeData);
if (response.IsFailed)
{
// Handle error
}
Viewable generation
The viewable (visual representation of the exchange model) is generated automatically as part of the publish/sync process. You no longer call a method to start it. To set the orientation of the generated viewable, call SetViewableWorldCoordinates before the SyncExchangeDataAsync call shown above. For a usage example, see Creating an Exchange Container.
Delete Data Exchange
To remove an exchange, you can make use of the function/API offered by the hosting provider. The IClient does not possess any capabilities for deleting exchanges. We are entirely dependent on the functionality/API provided by the hosting provider.