BIM VILLAGE

Version 2.5.1

SampleCreateIfcBeam

Overview

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

Sample code

For example:

Name Value
Name New Beam
Description Description
Tag Tag
Globalid 4cb1fe4d-90bd-40c5-bf98-08d9d2492aff
ObjectType
Ownerhistory
ContextOfItems
Storey
Start 0.000000,0.000000,0.000000
End 5000.000000,0.000000,0.000000
_Length 5000
XDim 250
YDim 250
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 IfcBeam = stp.Instnaces.CreateInstance("IfcBeam"); {
	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};
				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 = 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 SweptArea = stp.Instnaces.CreateInstance("IfcRectangleProfileDef"); {
					SweptArea.Attributes.AttributeAsStr("ProfileName").Value = "";
					SweptArea.Attributes.AttributeAsReal("XDim").Value = 250;
					SweptArea.Attributes.AttributeAsReal("YDim").Value = 250;
					SweptArea.Attributes.AttributeAsEnum("ProfileType").SetValue("AREA");
					var position = stp.Instnaces.CreateInstance("IfcAxis2Placement2D");  {
						var IfcCartesianPoint = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
							double []values={0.0 , 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;
				}
				IfcExtrudedAreaSolid.Attributes.AttributeAsInst("SweptArea").Value = SweptArea;
				var Position = stp.Instnaces.CreateInstance("IfcAxis2Placement3D"); {
					var location = stp.Instnaces.CreateInstance("IfcCartesianPoint"); {
						double []values={0, 0, -125}; // 
						location.Attributes.AttributeAsAggregate("coordinates").values = values;
					}
				        var start = new Vector3d(0,0,0);
				        var end = new Vector3d(5000,0,0);
					var dir = (end-start).normalize();
					var ang = Math.Acos(Vector3d.kXAxis.dotProduct(dir)); {
						if (Vector3d.kXAxis.crossProduct(dir).z < 0.0)
							ang = -ang;
					}
					var refdirection = stp.Instnaces.CreateInstance("IfcDirection"); {
						double []values={Math.Cos(ang+Math.PI/2), Math.Sin(ang+Math.PI/2), 0 };
						refdirection.Attributes.AttributeAsAggregate("directionratios").values = values;
					}
					var axis = stp.Instnaces.CreateInstance("IfcDirection"); {
						double []values={Math.Cos(ang), Math.Sin(ang), 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 = 5000;
			}
			STEPInstance []items={IfcExtrudedAreaSolid};
			IfcShapeRepresentation.Attributes.AttributeAsAggregate("Items").values = items;
		} 
		STEPInstance []Representations={IfcShapeRepresentation};
		Representation.Attributes.AttributeAsAggregate("Representations").values = Representations;
	}
	IfcBeam.Attributes.AttributeAsStr("Name").Value = "New Beam";
	IfcBeam.Attributes.AttributeAsStr("Description").Value = "Description";
	IfcBeam.Attributes.AttributeAsStr("Tag").Value = "Tag";
	IfcBeam.Attributes.AttributeAsStr("Globalid").Value = "4cb1fe4d-90bd-40c5-bf98-08d9d2492aff";
	IfcBeam.Attributes.AttributeAsStr("ObjectType").Value = "";
	IfcBeam.Attributes.AttributeAsInst("Ownerhistory").Value  = stp.Instnaces.FindInstance(-1);
	IfcBeam.Attributes.AttributeAsInst("Representation").Value = Representation;
	IfcBeam.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(IfcBeam);
	}
	IfcRelContainedInSpatialStructure.Attributes.AttributeAsAggregate("relatedelements").values = relatedelements.ToArray();
}

© 2019 - 2022 BIM VILLAGE.