xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
477 stars 171 forks source link

PredefinedType in IIfcBuildingElementProxy not updatable #539

Closed RolandoTonin closed 8 months ago

RolandoTonin commented 8 months ago

I use EssentialLibrary version 5.1.341 in my code I want to update some IfcBuildingElementProxy element properties in IFC file (3x2) such as PredefinedType enum value, name, objecttype and Tag. I use below code:

using (var txn = model.BeginTransaction(element.GlobalId.ToString()))
{
    if (!string.IsNullOrEmpty(itm.AssignedPropertyName))
        element.Name = itm.AssignedPropertyName;
    if (!string.IsNullOrEmpty(itm.AssignedObjectTypeName))
    {
        element.PredefinedType = IfcBuildingElementProxyTypeEnum.USERDEFINED;
        element.ObjectType = itm.AssignedObjectTypeName;
        element.Tag = itm.AssignedTagName;
    }
    txn.Commit();
}

element is Xbim.Ifc4.Interfaces.IfcBuildingElementProxy. At the end of my code i save in a new file: model.SaveAs(destFileName, StorageType.Ifc);

I have no problem with Name, Tag, and objectType but predefinedType does not appear in new output file.

I debug above code in Visual Studio. Before update element.Name, element value is:

element = 
{#28=IFCBUILDINGELEMENTPROXY('0zFd09smjmJxrRMIF9fuJW',#6,'Stabilizzato_Piastra','[CivilDesignerProductsDynamic].[Mesh\\Pr_20_31_16_12]',$,#13036,#13031,'3517',$);}

and PredefinedType should be #6. After update element.Name I get:

element = {#28=IFCBUILDINGELEMENTPROXY('0zFd09smjmJxrRMIF9fuJW',#2021598,'EF-S-VI-ROD-fondazione','[CivilDesignerProductsDynamic].[Mesh\\Pr_20_31_16_12]',$,#13036,#13031,'3517',$);}

PredefinedType was disapeared and element.PredefinedType is null. After when I assigna USERDEFINED to element.predefinedtype the value change but above string was not updated and conseguently when I save the file.

What can I do? Best Regards, Rolando

andyward commented 8 months ago

Assuming it's IFC2x3. There is no PredefinedType on a Proxy in that version of the schema. It was only introduced in IFC4 (by replacing CompositionType See https://standards.buildingsmart.org/IFC/DEV/IFC4_2/FINAL/HTML/schema/ifcsharedbldgelements/lexical/ifcbuildingelementproxy.htm

Because you're using the IFC4 interfaces which map through to the IFC2x3 implementation (where appropriate) I suspect it's not mapping the IfcBuildingElementProxyTypeEnum to the legacy IfcElementCompositionEnum.

A few options:

  1. Don't both setting Predefined Type at all in Ifc2x3 - it's irrelevant / not supported. ObjectType contains all you need?
  2. Use the Ifc2x3 specific type and set CompositionType (Won't help you here. See point 3)
  3. We could introduce some smarter mapping between old and new Enums - but IfcElementCompositionEnum does not have USERDEFINED/UNDEFINED as an option - so seems pointless

I'd go with 1)

Side note: your point about #6 in the 2nd parameter is a red herring. That's the OwnerHistory field, which updates after you edit the element.

RolandoTonin commented 8 months ago

thank Andy, I've checked above code on a IFC 4 file and it works fine. I didn't know tha predefinedtype was introduced only in IFC 4 and above.

thanks a lot, Rolando

RolandoTonin commented 8 months ago

Anyway I resolve with below code:

if(element is Xbim.Ifc2x3.Interfaces.IIfcBuildingElementProxy element2x3) { element2x3.CompositionType = Xbim.Ifc2x3.ProductExtension.IfcElementCompositionEnum.COMPLEX; } else { element.PredefinedType = IfcBuildingElementProxyTypeEnum.USERDEFINED; } an it work fine bothh IFC 4 and IFC 2x 3 file versions.