When I add an element to an ifc file, I have always a newer ifcownerhistory, person and organization created. I open my file ifc file with .Net xbim xplorer like this, and I save the default ownerhistory for reuse it when I create a new element:
private ObjectDataProvider ModelProvider
{
get
{
return MainFrame.DataContext as ObjectDataProvider;
}
}
public IfcStore Model
{
get
{
var op = MainFrame.DataContext as ObjectDataProvider;
return op == null ? null : op.ObjectInstance as IfcStore;
}
}
public bool LoadIFC()
{
var model = IfcStore.Open(currentFileName);
SetContext(model);
if (Model != null)
{
owner = Model.Instances.OfType<IIfcOwnerHistory>().First();
version = Model.SchemaVersion;
}
}
private void SetContext(IfcStore model)
{
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
ModelProvider.Refresh();
}
Here is my code to add a task which work with ifcstore but not with memorymodel:
private void AddTask()
{
if (_currentProduct == null) return;
using (var txn = Model.BeginTransaction("Ajout IfcTask a un produit"))
{
try
{
IfcTask newIfcTask = Model.Instances.New<IfcTask>();
newIfcTask.Name = "Test";
newIfcTask.Description = "TaskDescription";
newIfcTask.OwnerHistory = (IfcOwnerHistory)owner;
IfcTaskTime taskTime = Model.Instances.New<IfcTaskTime>();
taskTime.EarlyStart = new IfcDateTime(StartDate.ToString());
taskTime.EarlyFinish = new IfcDateTime(EndDate.ToString());
newIfcTask.TaskTime = taskTime;
IfcRelAssignsToProduct relAssignsToProduct = Model.Instances.New<IfcRelAssignsToProduct>();
relAssignsToProduct.RelatingProduct = _currentProduct;
relAssignsToProduct.RelatedObjects.Add(newIfcTask);
txn.Commit();
}
catch (Exception ex)
{
Debug.WriteLine("Erreur lors de la création de l'IfcTask : " + ex.Message);
txn.RollBack();
}
}
}`
I want to reuse the default ownerhistory, thanks for help
If you're editing an IFC model with xbim you should always perform edits in a transaction, and commit the transaction before saving the model. Otherwise your edits will not be persisted.
So for example
If you're using
IfcStore
for your IModel implementation then all edits will automatically be linked with a new IfcOwnerHistoryIf that's not what you want there are a couple of options:
MemoryModel
orEsentModel
- neither of which add this convenience mechanism to assign edits to an OwnerHistory