SampleCreateIfcBuildingStorey
Overview
This programming manual in C# offers a practical demonstration of how to create an instance of the IfcBuildingStorey class within a model.
Sample code
For example:
Name | Value |
---|---|
Name | New Floor |
Building | |
Level | 0 |
var app = new Beaver.BcadApplication();
var doc = app.ActiveDocument;
if (doc == null)
doc = app.Documents.Add();
var stp = doc.STEPDocument;
var IfcBuilding = stp.Instnaces.FindInstance(-1);
var IfcBuildingStorey = stp.Instnaces.CreateInstance("IfcBuildingStorey");{
var IfcLocalPlacement = AddInstance("IfcLocalPlacement"); {
var ObjectPlacement = IfcBuilding.Attributes.AttributeAsInst("ObjectPlacement");
IfcLocalPlacement.Attributes.AttributeAsInst("PlacementRelTo").Value = ObjectPlacement.Value;
var IfcAxis2Placement3D = stp.Instnaces.CreateInstance("IfcAxis2Placement3D");{
var Location = stp.Instnaces.CreateInstance("IfcCartesianPoint");{
double []values={0.0, 0.0, 0};
Location.Attributes.AttributeAsAggregate("Coordinates").values = values;
}
var Axis = stp.Instnaces.CreateInstance("IfcDirection");{
double []values={0.0, 0.0, 1.0};
Axis.Attributes.AttributeAsAggregate("DirectionRatios").values = values;
}
var Refdirection = stp.Instnaces.CreateInstance("IfcDirection");{
double []values={1.0, 0.0, 0.0};
Refdirection.Attributes.AttributeAsAggregate("DirectionRatios").values = values;
}
IfcAxis2Placement3D.Attributes.AttributeAsInst("Location").Value = Location;
IfcAxis2Placement3D.Attributes.AttributeAsInst("Axis").Value = Axis;
IfcAxis2Placement3D.Attributes.AttributeAsInst("RefDirection").Value = Refdirection;
}
IfcLocalPlacement.Attributes.AttributeAsSelect("RelativePlacement").SetValueAsInst(IfcAxis2Placement3D);
}
IfcBuildingStorey.Attributes.AttributeAsStr("Name").Value = "New Floor";
IfcBuildingStorey.Attributes.AttributeAsInst("ObjectPlacement").Value = IfcLocalPlacement;
}
{
STEPInstance IfcRelAggregates = null; {
var insts = FindInstances("IfcRelAggregates", true);
foreach (var inst in insts) {
if (inst.Attributes.AttributeAsInst("RelatingObject").Value == IfcBuilding) {
IfcRelAggregates = inst;
break;
}
}
}
if (IfcRelAggregates == null) {
IfcRelAggregates = stp.Instnaces.CreateInstance("IfcRelAggregates");
IfcRelAggregates.Attributes.AttributeAsInst("RelatingObject").Value = IfcBuilding;
}
var objs = IfcRelAggregates.Attributes.AttributeAsAggregate("RelatedObjects").values;
var newObjs = new List<STEPInstance>(); {
if (objs!= null) {
foreach (STEPInstance obj in objs)
newObjs.Add(obj);
}
newObjs.Add(IfcBuildingStorey);
}
IfcRelAggregates.Attributes.AttributeAsAggregate("RelatedObjects").values = newObjs.ToArray();
}