XbimEssentials
XbimEssentials copied to clipboard
Assigning items at IfcPresentationLayerWithStyle doesn't work for IfcCurveBoundedPlane
Here's the code:
static void Main(string[] args)
{
var projectName = "Virtual Element Test";
var fileName = @"VEElement.ifc";
var credentials = new XbimEditorCredentials();
using (var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4x1, XbimStoreType.InMemoryModel))
{
//Begin a transaction as all changes to a model are ACID
using (var txn = model.BeginTransaction("Initialise Model"))
{
//create a project
var project = model.Instances.New<IfcProject>();
//set the units to SI (mm and metres)
project.Initialize(ProjectUnits.SIUnitsUK);
project.Name = projectName;
//now commit the changes, else they will be rolled back at the end of the scope of the using statement
txn.Commit();
}
var ifcSite = CreateSite(model, projectName);
using (var txn = model.BeginTransaction())
{
var structure = model.Instances.New<IfcVirtualElement>(ve =>
{
ve.Name = "MyTest";
ve.Representation = model.Instances.New<IfcProductDefinitionShape>(rep =>
{
rep.Representations.Add(Create2DElements(model));
});
});
ifcSite.AddElement(structure);
txn.Commit();
}
model.SaveAs(fileName, StorageType.Ifc);
}
}
private static IfcShapeRepresentation Create2DElements(IfcStore model)
{
var shape = model.Instances.New<IfcShapeRepresentation>(sr =>
{
sr.ContextOfItems = model.Instances.OfType<IfcGeometricRepresentationContext>()
.SingleOrDefault(context => context.CoordinateSpaceDimension == 3);
sr.RepresentationIdentifier = "Body";
sr.RepresentationType = "SweptSolid";
IfcCurveBoundedPlane ifcCurveBoundedPlane = BoundedPlane(model, 5,5, 0,0);
sr.Items.Add(ifcCurveBoundedPlane);
var colorSet = Color.Red;
var surfaceStyle = CreateSurfaceStyle(model, colorSet);
var newStyleAssignment = model.Instances.New<IfcPresentationStyleAssignment>();
newStyleAssignment.Styles.Add(surfaceStyle);
//var newStyledItem = model.Instances.New<IfcStyledItem>(); //this works for setting the color
//newStyledItem.Item = ifcCurveBoundedPlane;
//newStyledItem.Styles.Add(newStyleAssignment);
var layerAssignment = model.Instances.New<IfcPresentationLayerWithStyle>(layer =>
{
layer.LayerStyles.Add(surfaceStyle); //this doesn't work
layer.AssignedItems.Add(ifcCurveBoundedPlane);
});
});
return shape;
}
private static IfcSurfaceStyle CreateSurfaceStyle(IfcStore model, Color coolllor)
{
return model.Instances.New<IfcSurfaceStyle>(style =>
{
style.Name = "Circle Style";
style.Side = IfcSurfaceSide.BOTH;
var surfaceRendering = model.Instances.New<IfcSurfaceStyleRendering>(rendering =>
{
rendering.SurfaceColour = SetColor(model, coolllor);
});
style.Styles.Add(surfaceRendering);
});
}
private static IfcColourRgb SetColor(IfcStore model, Color blue)
{
var divider = 255.0;
return model.Instances.New<IfcColourRgb>(color =>
{
color.Blue = blue.B/ divider;
color.Red = blue.R/ divider;
color.Green = blue.G/ divider;
});
}
If you open the IFC files generated in IFC viewers ( like XBim Explorer, or rdf IFC viewer), you will find that the color is not set properly.
You will need to use IfcStyledItem in order to set the color. Is this intended? To me this seems like a bug because both ways are legitimate way of setting the layers.