SampleCreateIfcWindow
Overview
This programming manual in C# offers a practical demonstration of how to create an instance of the IfcWindow class within a model.
Sample code
For example:
Name | Value |
---|---|
Name | New Window |
Description | Description |
Tag | Tag |
Globalid | ecd0f337-850f-4e5e-becc-49f09455f644 |
ObjectType | |
Ownerhistory | |
ContextOfItems | |
Storey | |
XDim | 3000 |
YDim | 3000 |
Thickness | 100 |
OpeningElement | |
PosX | 800 |
PosY | 900 |
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 IfcBuildingStorey = stp.Instnaces.FindInstance(-1);
var IfcWindow = stp.Instnaces.CreateInstance("IfcWindow"); {
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 storey = stp.Instnaces.FindInstance(-1);
var objectplacement = storey.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 = 3000;
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, 0.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={800+3000*0.5, -100*0.5, 900+3000*0.5};
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, 1.0, 0.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 = 100;
}
STEPInstance []items={IfcExtrudedAreaSolid};
IfcShapeRepresentation.Attributes.AttributeAsAggregate("Items").values = items;
}
STEPInstance []Representations={IfcShapeRepresentation};
Representation.Attributes.AttributeAsAggregate("Representations").values = Representations;
}
IfcWindow.Attributes.AttributeAsStr("Name").Value = "New Window";
IfcWindow.Attributes.AttributeAsStr("Description").Value = "Description";
IfcWindow.Attributes.AttributeAsStr("Tag").Value = "Tag";
IfcWindow.Attributes.AttributeAsStr("Globalid").Value = "ecd0f337-850f-4e5e-becc-49f09455f644";
IfcWindow.Attributes.AttributeAsStr("ObjectType").Value = "";
IfcWindow.Attributes.AttributeAsInst("Ownerhistory").Value = stp.Instnaces.FindInstance(-1);
IfcWindow.Attributes.AttributeAsInst("Representation").Value = Representation;
IfcWindow.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(IfcWindow);
}
IfcRelContainedInSpatialStructure.Attributes.AttributeAsAggregate("relatedelements").values = relatedelements.ToArray();
}
{
var IfcRelVoidsElement = stp.Instnaces.CreateInstance("IfcRelFillsElement");
IfcRelVoidsElement.Attributes.AttributeAsInst("RelatingOpeningElement").Value = stp.Instnaces.FindInstance(-1);
IfcRelVoidsElement.Attributes.AttributeAsInst("RelatedBuildingElement").Value = IfcWindow;
}