BIM VILLAGE

Version 2.5.1

SampleCreateIfcSlab

Overview

This programming manual in C# offers a practical demonstration of how to create an instance of the IfcSlab class within a model.

Sample code

For example:

Name Value
Name New Slab
Description Description
Tag Tag
Globalid 5844bb5f-e68e-4d23-9687-31b46b2117de
ObjectType
Ownerhistory
ContextOfItems
Storey
Origin 0.000000,0.000000,0.000000
Points 0.000000,0.000000,0.000000, 5000.000000,0.000000,0.000000, 5000.000000,5000.000000,0.000000, 0.000000,5000.000000,0.000000, 0.000000,0.000000,0.000000
Depth 150
var app = new Beaver.BcadApplication();
var doc = app.ActiveDocument;
if (doc == null)
    doc = app.Documents.Add();
var stp = doc.STEPDocument;
var IfcBuildingStorey  = stp.Instnaces.FindInstance(-1);
var IfcSlab = stp.Instnaces.CreateInstance("IfcSlab"); {
	var ObjectPlacement = stp.Instnaces.CreateInstance("IfcLocalPlacement"); {
		var Relativeplacement = stp.Instnaces.CreateInstance("IfcAxis2Placement3D"); {
			var location = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
				double []values={0,0,0};
				location.Attributes.AttributeAsAggregate("coordinates").values = values;
			}
			var refdirection = stp.Instnaces.CreateInstance("IfcDirection"); {
				double []values={1.0, 0.0, 0.0};
				refdirection.Attributes.AttributeAsAggregate("directionratios").values = values;
			}
			var axis = stp.Instnaces.CreateInstance("IfcDirection"); {
				double []values={0.0, 0.0, 1.0};
				axis.Attributes.AttributeAsAggregate("directionratios").values = values;
			}
			Relativeplacement.Attributes.AttributeAsInst("location").Value = location;
			Relativeplacement.Attributes.AttributeAsInst("refdirection").Value = refdirection;
			Relativeplacement.Attributes.AttributeAsInst("axis").Value = axis;
		}
		STEPInstance placementRelTo = null; {
			var objectplacement = IfcBuildingStorey.Attributes.AttributeAsInst("objectplacement");
			placementRelTo = objectplacement.Value;
		}
		ObjectPlacement.Attributes.AttributeAsInst("PlacementRelTo").Value = placementRelTo;
		ObjectPlacement.Attributes.AttributeAsSelect("Relativeplacement").SetValueAsInst(Relativeplacement);
	}
	var Representation = stp.Instnaces.CreateInstance("IfcProductDefinitionShape"); {
		Representation.Attributes.AttributeAsStr("Name").Value = "";
		Representation.Attributes.AttributeAsStr("Description").Value = "";
		var IfcShapeRepresentation = stp.Instnaces.CreateInstance("IfcShapeRepresentation"); {
			IfcShapeRepresentation.Attributes.AttributeAsInst("ContextOfItems").Value  = stp.Instnaces.FindInstance(-1);
			IfcShapeRepresentation.Attributes.AttributeAsStr("RepresentationIdentifier").Value = "Body";
			IfcShapeRepresentation.Attributes.AttributeAsStr("RepresentationType").Value = "SweptSolid";
			var IfcExtrudedAreaSolid = stp.Instnaces.CreateInstance("IfcExtrudedAreaSolid"); {
				var IfcArbitraryClosedProfileDef = stp.Instnaces.CreateInstance("IfcArbitraryClosedProfileDef"); {
					var IfcCompositeCurve = stp.Instnaces.CreateInstance("IfcCompositeCurve"); {
						var segments = new List<STEPInstance>(); {
							for (int i = 0; i < Points.Count-1;i++) {
								var IfcCompositeCurveSegment = stp.Instnaces.CreateInstance("IfcCompositeCurveSegment"); {
									var IfcPolyline = stp.Instnaces.CreateInstance("IfcPolyline"); {
										var startPt = Points[i];
										var endPt = Points[i+1];
										var start = AddInstance("IfcCartesianPoint"); { 
											double []values={startPt.X, startPt.Y, startPt.Z};
											start.Attributes.AttributeAsAggregate("coordinates").values = values;
										}
										var end = AddInstance("IfcCartesianPoint"); { 
											double []values={endPt.X, endPt.Y, endPt.Z};
											end.Attributes.AttributeAsAggregate("coordinates").values = values;
										}
										STEPInstance []pts={start, end};
										IfcPolyline.Attributes.AttributeAsAggregate("Points").values = pts;
									}
									IfcCompositeCurveSegment.Attributes.AttributeAsBool("SameSense").Value = true;
									IfcCompositeCurveSegment.Attributes.AttributeAsInst("ParentCurve").Value = IfcPolyline;
									IfcCompositeCurveSegment.Attributes.AttributeAsEnum("TRANSITION").SetValue("continuous");
								}
								segments.Add(IfcCompositeCurveSegment);
							}
						}
						IfcCompositeCurve.Attributes.AttributeAsLogical("SelfIntersect").Value = LOGICAL.LOGICAL_FALSE;
						IfcCompositeCurve.Attributes.AttributeAsAggregate("Segments").values = segments.ToArray();
					}
					IfcArbitraryClosedProfileDef.Attributes.AttributeAsStr("ProfileName").Value = "A1";
					IfcArbitraryClosedProfileDef.Attributes.AttributeAsEnum("ProfileType").SetValue("AREA");
					IfcArbitraryClosedProfileDef.Attributes.AttributeAsInst("OuterCurve").Value  = IfcCompositeCurve;
				}
				IfcExtrudedAreaSolid.Attributes.AttributeAsInst("SweptArea").Value = IfcArbitraryClosedProfileDef;
				var Position = stp.Instnaces.CreateInstance("IfcAxis2Placement3D"); {
					var location = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
						double []values={0, 0, 0};
						location.Attributes.AttributeAsAggregate("coordinates").values = values;
					}
					var refdirection = stp.Instnaces.CreateInstance("IfcDirection"); {
						double []values={1.0, 0.0, 0.0};
						refdirection.Attributes.AttributeAsAggregate("directionratios").values = values;
					}
					var axis = stp.Instnaces.CreateInstance("IfcDirection"); {
						double []values={0.0, 0.0, 1.0};
						axis.Attributes.AttributeAsAggregate("directionratios").values = values;
					}
					Position.Attributes.AttributeAsInst("location").Value = location;
					Position.Attributes.AttributeAsInst("refdirection").Value = refdirection;
					Position.Attributes.AttributeAsInst("axis").Value = axis;
				}
				IfcExtrudedAreaSolid.Attributes.AttributeAsInst("Position").Value = Position;
				var extrudeddirection = stp.Instnaces.CreateInstance("IfcDirection"); {
					double []values={0, 0, 1};
					extrudeddirection.Attributes.AttributeAsAggregate("directionratios").values = values;
				}
				IfcExtrudedAreaSolid.Attributes.AttributeAsInst("extrudeddirection").Value = extrudeddirection;
				IfcExtrudedAreaSolid.Attributes.AttributeAsReal("Depth").Value = 150;
			}
			STEPInstance []items={IfcExtrudedAreaSolid};
			IfcShapeRepresentation.Attributes.AttributeAsAggregate("Items").values = items;
		} 
		STEPInstance []Representations={IfcShapeRepresentation};
		Representation.Attributes.AttributeAsAggregate("Representations").values = Representations;
	}
	IfcSlab.Attributes.AttributeAsStr("Name").Value = "New Slab";
	IfcSlab.Attributes.AttributeAsStr("Description").Value ="Description";
	IfcSlab.Attributes.AttributeAsStr("Tag").Value = "Tag";
	IfcSlab.Attributes.AttributeAsStr("Globalid").Value = "5844bb5f-e68e-4d23-9687-31b46b2117de";
	IfcSlab.Attributes.AttributeAsStr("ObjectType").Value = "";
	IfcSlab.Attributes.AttributeAsInst("Ownerhistory").Value  = stp.Instnaces.FindInstance(-1);
	IfcSlab.Attributes.AttributeAsInst("Representation").Value = Representation;
	IfcSlab.Attributes.AttributeAsInst("ObjectPlacement").Value = ObjectPlacement;
}
{
	STEPInstance IfcRelContainedInSpatialStructure = null; {
		var insts =  FindInstances("IfcRelContainedInSpatialStructure", true);
		foreach (var inst in insts) {
			if (inst.Attributes.AttributeAsInst("relatingstructure").Value == IfcBuildingStorey) {
				IfcRelContainedInSpatialStructure = inst;
				break;
			}
		}
	}
	if (IfcRelContainedInSpatialStructure == null) {
		IfcRelContainedInSpatialStructure = stp.Instnaces.CreateInstance("IfcRelContainedInSpatialStructure");
		IfcRelContainedInSpatialStructure.Attributes.AttributeAsInst("relatingstructure").Value = IfcBuildingStorey;
	}
	var relatedelements = new List<STEPInstance>(); {
		var objs = IfcRelContainedInSpatialStructure.Attributes.AttributeAsAggregate("relatedelements").values;
		if (objs!= null) {
			foreach (STEPInstance obj in objs)
				relatedelements.Add(obj);
		}
		relatedelements.Add(IfcSlab);
	}
	IfcRelContainedInSpatialStructure.Attributes.AttributeAsAggregate("relatedelements").values = relatedelements.ToArray();
}

© 2019 - 2022 BIM VILLAGE.