BIM VILLAGE

Version 2.5.1

SampleCreateIfcOpeningElement

Overview

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

Sample code

For example:

Name Value
Name New Opening
Description Description
Tag Tag
Globalid 13c35f4c-295a-43f5-9351-735547604e0c
ObjectType
Ownerhistory
ContextOfItems
Wall
Width 3000
Height 3000
PosX 800
PosY 900
Start 0.000000,0.000000,0.000000
End 5000.000000,0.000000,0.000000
var app = new Beaver.BcadApplication();
var doc = app.ActiveDocument;
if (doc == null)
    doc = app.Documents.Add();
var stp = doc.STEPDocument;
			var stp  = BeaverHelper.kInstance.stp;
			var IfcWall  = stp.Instnaces.FindInstance(-1);
			double wall_xdim = double.MaxValue; double wall_ydim = double.MaxValue; double wall_depth = double.MaxValue; {
				if (IfcWall!=null) {
					var Ifcproductrepresentation = IfcWall.Attributes.AttributeAsInst("representation").Value;
					if (Ifcproductrepresentation!=null) {
						var representations = Ifcproductrepresentation.Attributes.AttributeAsAggregate("representations").values;
						foreach (STEPInstance representation in representations ) {
							var representationidentifier = representation.Attributes.AttributeAsStr("representationidentifier").Value;
							if (representationidentifier.ToLower()=="body") {
								var items = representation.Attributes.AttributeAsAggregate("items").values;
								foreach (STEPInstance item in items ) {
									if (item.IsDerivedFrom("IfcExtrudedAreaSolid")) {
										var sweptarea = item.Attributes.AttributeAsInst("sweptarea").Value;
										if (sweptarea!=null && sweptarea.IsDerivedFrom("IfcRectangleProfileDef")) {
											wall_xdim = sweptarea.Attributes.AttributeAsReal("xdim").Value;
											wall_ydim = sweptarea.Attributes.AttributeAsReal("ydim").Value;
										}
										wall_depth = item.Attributes.AttributeAsReal("depth").Value;
										break;
									}
								}
								break;
							}
						}
					}
				}
			}
			if (wall_xdim == double.MaxValue || wall_ydim == double.MaxValue || wall_depth == double.MaxValue) {
				throw new Exception("Unable to Retrieve Dimensions from the Specified Wall");
			}
			STEPInstance IfcOpeningElement = null; {
				#if true
				IfcOpeningElement = stp.Instnaces.CreateInstance("IfcOpeningElement");
				#else
				IfcOpeningElement = stp.Instnaces.CreateInstance("IfcBeam"); 
				#endif
				var ObjectPlacement = stp.Instnaces.CreateInstance("IfcLocalPlacement"); {
					var Relativeplacement = stp.Instnaces.CreateInstance("IfcAxis2Placement3D"); {
						var location = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
							double []values={800+3000*0.5, 0, 0};
							location.Attributes.AttributeAsAggregate("coordinates").values = values;
						}
						var refdirection = stp.Instnaces.CreateInstance("IfcDirection"); {
							double []values={1,0,0};
							refdirection.Attributes.AttributeAsAggregate("directionratios").values = values;
						}
						var axis = stp.Instnaces.CreateInstance("IfcDirection"); {
							double []values={0,0,1}; 
							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 = IfcWall.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 SweptArea = stp.Instnaces.CreateInstance("IfcRectangleProfileDef"); {
								SweptArea.Attributes.AttributeAsStr("ProfileName").Value = "";
								SweptArea.Attributes.AttributeAsReal("XDim").Value = 3000;
								SweptArea.Attributes.AttributeAsReal("YDim").Value = wall_xdim;
								SweptArea.Attributes.AttributeAsEnum("ProfileType").SetValue("AREA");
								var position = stp.Instnaces.CreateInstance("IfcAxis2Placement2D");  {
									var IfcCartesianPoint = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
										double []values={0 , 0};
										IfcCartesianPoint.Attributes.AttributeAsAggregate("coordinates").values = values;
									}
									position.Attributes.AttributeAsInst("location").Value = IfcCartesianPoint;
									var IfcDirection = stp.Instnaces.CreateInstance("IfcDirection"); {
										double []values={1, 0};
										IfcDirection.Attributes.AttributeAsAggregate("directionratios").values = values;
									}
									position.Attributes.AttributeAsInst("refdirection").Value = IfcDirection;
								}
								SweptArea.Attributes.AttributeAsInst("position").Value = position;
							}
							var Position = stp.Instnaces.CreateInstance("IfcAxis2Placement3D"); {
								var location = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
									double []values={0, 0, 900};  
									location.Attributes.AttributeAsAggregate("coordinates").values = values;
								}
								var refdirection = stp.Instnaces.CreateInstance("IfcDirection"); {
									double []values={1, 0, 0 };
									refdirection.Attributes.AttributeAsAggregate("directionratios").values = values;
								}
								var axis = stp.Instnaces.CreateInstance("IfcDirection"); {
									double []values={0, 0, 1};
									axis.Attributes.AttributeAsAggregate("directionratios").values = values;
								}
								Position.Attributes.AttributeAsInst("location").Value = location;
								Position.Attributes.AttributeAsInst("refdirection").Value = refdirection;
								Position.Attributes.AttributeAsInst("axis").Value = axis;
							}
							var extrudeddirection = stp.Instnaces.CreateInstance("IfcDirection"); {
								double []values={0, 0, 1}; 
								extrudeddirection.Attributes.AttributeAsAggregate("directionratios").values = values;
							}
							IfcExtrudedAreaSolid.Attributes.AttributeAsInst("SweptArea").Value = SweptArea;
							IfcExtrudedAreaSolid.Attributes.AttributeAsInst("Position").Value = Position;
							IfcExtrudedAreaSolid.Attributes.AttributeAsInst("extrudeddirection").Value = extrudeddirection;
							IfcExtrudedAreaSolid.Attributes.AttributeAsReal("Depth").Value = 3000;
						}
						STEPInstance []items={IfcExtrudedAreaSolid};
						IfcShapeRepresentation.Attributes.AttributeAsAggregate("Items").values = items;
					} 
					STEPInstance []Representations={IfcShapeRepresentation};
					Representation.Attributes.AttributeAsAggregate("Representations").values = Representations;
				}
				IfcOpeningElement.Attributes.AttributeAsStr("Name").Value = "New Opening";
				IfcOpeningElement.Attributes.AttributeAsStr("Description").Value = "Description";
				IfcOpeningElement.Attributes.AttributeAsStr("Tag").Value = "Tag";
				IfcOpeningElement.Attributes.AttributeAsStr("Globalid").Value = "13c35f4c-295a-43f5-9351-735547604e0c";
				IfcOpeningElement.Attributes.AttributeAsStr("ObjectType").Value = "";
				IfcOpeningElement.Attributes.AttributeAsInst("Ownerhistory").Value  = stp.Instnaces.FindInstance(-1);
				IfcOpeningElement.Attributes.AttributeAsInst("Representation").Value = Representation;
				IfcOpeningElement.Attributes.AttributeAsInst("ObjectPlacement").Value = ObjectPlacement;
			}
			{
				var IfcRelVoidsElement = stp.Instnaces.CreateInstance("IfcRelVoidsElement");
				IfcRelVoidsElement.Attributes.AttributeAsInst("RelatingBuildingElement").Value = IfcWall;
				IfcRelVoidsElement.Attributes.AttributeAsInst("RelatedOpeningElement").Value = IfcOpeningElement;
			}

© 2019 - 2022 BIM VILLAGE.