SampleCreateIfcGrid
Overview
This programming manual in C# offers a practical demonstration of how to create an instance of the IfcGrid class within a model.
Sample code
For example:
Name | Value |
---|---|
Name | New Grid |
Site | |
Ownerhistory | |
ObjectPlacement | 0.000000,0.000000,0.000000 |
UAxes | 0.000000, 5000.000000, 10000.000000, 15000.000000, 20000.000000, 25000.000000, 30000.000000 |
VAxes | 0.000000, 5000.000000, 10000.000000, 15000.000000, 20000.000000, 25000.000000, 30000.000000 |
Stretch | 1000 |
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 IfcGrid = stp.Instnaces.CreateInstance("IfcGrid"); {
var IfcLocalPlacement = AddInstance("IfcLocalPlacement"); {
var ObjectPlacement = IfcSite.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);
}
List<double> UAxes = new List<double>();
UAxes.Add(0.0);
UAxes.Add(5000.0);
UAxes.Add(10000.0);
UAxes.Add(15000.0);
UAxes.Add(20000.0);
UAxes.Add(25000.0);
UAxes.Add(30000.0);
List<double> VAxes = new List<double>();
VAxes.Add(0.0);
VAxes.Add(5000.0);
VAxes.Add(10000.0);
VAxes.Add(15000.0);
VAxes.Add(20000.0);
VAxes.Add(25000.0);
VAxes.Add(30000.0);
var uAxes = new List<STEPInstance>(); {
double minV = double.MaxValue; double maxV = -double.MaxValue; {
foreach (var vAxis in VAxes) {
if (minV > vAxis)
minV = vAxis;
if (maxV < vAxis)
maxV = vAxis;
}
minV -= 1000;
maxV += 1000;
}
char tag = 'A';
foreach (var uAxis in UAxes) {
var IfcGridAxis = stp.Instnaces.CreateInstance("IfcGridAxis"); {
var IfcPolyline = stp.Instnaces.CreateInstance("IfcPolyline"); {
var start = AddInstance("IfcCartesianPoint"); {
double []values={uAxis, minV};
start.Attributes.AttributeAsAggregate("coordinates").values = values;
}
var end = AddInstance("IfcCartesianPoint"); {
double []values={uAxis, maxV};
end.Attributes.AttributeAsAggregate("coordinates").values = values;
}
STEPInstance []Points={start, end};
IfcPolyline.Attributes.AttributeAsAggregate("Points").values = Points;
}
IfcGridAxis.Attributes.AttributeAsStr("AxisTag").Value = (tag++).ToString();
IfcGridAxis.Attributes.AttributeAsBool("SameSense").Value = true;
IfcGridAxis.Attributes.AttributeAsInst("AxisCurve").Value = IfcPolyline;
}
uAxes.Add(IfcGridAxis);
}
}
var vAxes = new List<STEPInstance>(); {
double minU = double.MaxValue; double maxU = -double.MaxValue; {
foreach (var vAxis in VAxes) {
if (minU > vAxis)
minU = vAxis;
if (maxU < vAxis)
maxU = vAxis;
}
minU -= 1000;
maxU += 1000;
}
int tag = 1;
foreach (var vAxis in VAxes) {
var IfcGridAxis = stp.Instnaces.CreateInstance("IfcGridAxis"); {
var IfcPolyline = stp.Instnaces.CreateInstance("IfcPolyline"); {
var start = AddInstance("IfcCartesianPoint"); {
double []values={minU, vAxis};
start.Attributes.AttributeAsAggregate("coordinates").values = values;
}
var end = AddInstance("IfcCartesianPoint"); {
double []values={maxU, vAxis};
end.Attributes.AttributeAsAggregate("coordinates").values = values;
}
STEPInstance []Points={start, end};
IfcPolyline.Attributes.AttributeAsAggregate("Points").values = Points;
}
IfcGridAxis.Attributes.AttributeAsStr("AxisTag").Value = (tag++).ToString();
IfcGridAxis.Attributes.AttributeAsBool("SameSense").Value = true;
IfcGridAxis.Attributes.AttributeAsInst("AxisCurve").Value = IfcPolyline;
}
vAxes.Add(IfcGridAxis);
}
}
IfcGrid.Attributes.AttributeAsInst("Ownerhistory").Value = stp.Instnaces.FindInstance(-1);
IfcGrid.Attributes.AttributeAsStr("Name").Value = "New Grid";
IfcGrid.Attributes.AttributeAsInst("Ownerhistory").Value = stp.Instnaces.FindInstance(-1);
IfcGrid.Attributes.AttributeAsAggregate("UAxes").values = uAxes.ToArray();
IfcGrid.Attributes.AttributeAsAggregate("VAxes").values = vAxes.ToArray();
}