【Xbim+C#】创建拉伸的墙
基础
效果图
简单的工具类
using System.Collections.Generic;
using System.Linq;
using Xbim.Common.Step21;
using Xbim.Ifc;
using Xbim.Ifc4.GeometricConstraintResource;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.GeometryResource;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4.Kernel;
using Xbim.Ifc4.MeasureResource;
using Xbim.Ifc4.PresentationAppearanceResource;
using Xbim.Ifc4.ProductExtension;
using Xbim.Ifc4.ProfileResource;
using Xbim.Ifc4.RepresentationResource;
using Xbim.Ifc4.SharedBldgElements;
namespace TestXbim
{
public class IfcUtil
{
public static IfcStore MakeIfcStore()
{
return IfcStore.Create(IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);
}
public static IfcProject CreateProject(IfcStore model)
{
return model.Instances.New<IfcProject>(p =>
{
p.UnitsInContext = model.Instances.New<IfcUnitAssignment>(a =>
a.SetOrChangeSiUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE, IfcSIPrefix.MILLI));
});
}
public static IfcSite CreateSite(IfcStore model)
{
return model.Instances.New<IfcSite>();
}
public static IfcBuilding CreateBuilding(IfcStore model)
{
return model.Instances.New<IfcBuilding>();
}
public static IfcWall CreateWall(IfcStore model)
{
return model.Instances.New<IfcWall>();
}
public static IfcProductDefinitionShape CreateExtrudedShape(IfcStore model, List<double[]> points, double depth, double elevation)
{
//基于点坐标序列,创建折线
IfcPolyline polyline = model.Instances.New<IfcPolyline>(L =>
{
foreach (var point in points)
{
IfcCartesianPoint p = model.Instances.New<IfcCartesianPoint>(cp => cp.SetXY(point[0], point[1]));
L.Points.Add(p);
}
});
//基于折线创建切面
var profileDef = model.Instances.New<IfcArbitraryClosedProfileDef>(p =>
{
p.ProfileType = IfcProfileTypeEnum.AREA;
p.OuterCurve = polyline;
});
//基于切面创建拉伸体
var solid = model.Instances.New<IfcExtrudedAreaSolid>(s =>
{
s.Position = model.Instances.New<IfcAxis2Placement3D>(p =>
p.Location = model.Instances.New<IfcCartesianPoint>(c => c.SetXYZ(0, 0, elevation)));
s.Depth = depth;
s.ExtrudedDirection = model.Instances.New<IfcDirection>(d => d.SetXYZ(0, 0, 1));
s.SweptArea = profileDef;
});
//基于拉伸体,创建形状
var rep = model.Instances.New<IfcShapeRepresentation>(r =>
{
r.Items.Add(solid);
});
//基于形状,创建产品形状
var shape = model.Instances.New<IfcProductDefinitionShape>(s => s.Representations.Add(rep));
return shape;
}
}
}
示例代码
public void TestMethod1()
{
var pts = new List<double[]>()
{
new double[]{0,0},
new double[]{0,1000},
new double[]{2000,1000},
new double[]{2000,0},
};
var pts2 = new List<double[]>()
{
new double[]{0,1500},
new double[]{0,2500},
new double[]{1000,2500},
new double[]{1000,1500},
};
var model = IfcUtil.MakeIfcStore();
using (var tran = model.BeginTransaction())
{
var color = new double[] { 0.5, 0, 0, 2 };
var wallShape = IfcUtil.CreateExtrudedShape(model, pts, 500, 0);
var wall = IfcUtil.CreateWall(model);
wall.Representation = wallShape;
var wallShape2 = IfcUtil.CreateExtrudedShape(model, pts2, 500, 0);
var wall2 = IfcUtil.CreateWall(model);
wall2.Representation = wallShape2;
var building = IfcUtil.CreateBuilding(model);
building.AddElement(wall);
building.AddElement(wall2);
var site = IfcUtil.CreateSite(model);
site.AddBuilding(building);
var project = IfcUtil.CreateProject(model);
project.AddSite(site);
tran.Commit();
}
model.SaveAs("./wall.ifc");
}
原文地址:https://blog.csdn.net/liqian_ken/article/details/143867404
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!