BIM VILLAGE

Version 2.5.1

SampleCreateIfcBuilding

Overview

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

Sample code

For example:

Name Value
Name New Building
LongName ABC building
Description description
Site
Ownerhistory
ElevationOfRefHeight 0
CompositionType
PositionX 0
PositionY 0
PositionZ 0
var app = new Beaver.BcadApplication();
var doc = app.ActiveDocument;
if (doc == null)
    doc = app.Documents.Add();
var stp = doc.STEPDocument;
var IfcSite  = stp.Instnaces.FindInstance(-1);
var IfcBuilding = stp.Instnaces.CreateInstance("IfcBuilding"); {
	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};
				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);
	}
	IfcBuilding.Attributes.AttributeAsInst("Ownerhistory").Value  = stp.Instnaces.FindInstance(-1);
	IfcBuilding.Attributes.AttributeAsStr("Description").Value = "description";
	IfcBuilding.Attributes.AttributeAsStr("Name").Value = "New Building";
	IfcBuilding.Attributes.AttributeAsStr("LongName").Value = "ABC building";
	IfcBuilding.Attributes.AttributeAsReal("ElevationOfRefHeight").Value = 0;
	IfcBuilding.Attributes.AttributeAsEnum("CompositionType").SetValue("");
	IfcBuilding.Attributes.AttributeAsInst("ObjectPlacement").Value = IfcLocalPlacement;
}
{
	STEPInstance IfcRelAggregates = null; {
		var insts =  FindInstances("IfcRelAggregates", true);
		foreach (var inst in insts) {
			if (inst.Attributes.AttributeAsInst("RelatingObject").Value == IfcSite) {
				IfcRelAggregates = inst;
				break;
			}
		}
	}
	if (IfcRelAggregates == null) {
		IfcRelAggregates = stp.Instnaces.CreateInstance("IfcRelAggregates");
		IfcRelAggregates.Attributes.AttributeAsInst("RelatingObject").Value = IfcSite;
	}
	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(IfcBuilding);
	}
	IfcRelAggregates.Attributes.AttributeAsAggregate("RelatedObjects").values = newObjs.ToArray();
}

© 2019 - 2022 BIM VILLAGE.