体
圆台(锥)元素 (ConeElement)
圆台(锥)元素通过设置圆台的 顶部及底部 的圆心坐标,半径,及旋转矩阵后创建出相应的元素
public static void CmdCreateCone(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
DPoint3d topCenter = new DPoint3d(0,0, 100000);//创建顶部圆锥(台)圆心坐标
DPoint3d bottomCenter = DPoint3d.Zero;//创建底部圆锥(台)圆心坐标
ConeElement cone = new ConeElement(dgnModel,null,50000,100000,topCenter,bottomCenter,DMatrix3d.Identity,true);
/*
* 创建圆锥(台)元素
* dgnModel:创建圆锥(台)元素的模型空间
* templateElement:元素模板
* topRadius:顶部圆锥(台)半径
* bottomRadius:底部圆锥(台)半径
* topCenter:顶部圆锥(台)圆心坐标
* bottomCenter:底部圆锥(台)圆心坐标
* rotation:应用于顶圆/底圆的旋转矩阵
* isCapped:对于实体圆锥(台)来说为真
*/
cone.AddToModel();//将圆锥(台)写入模型
}
拉伸面实体(Surface OrSolidElement)
创建拉伸面实体是需要首先对拉伸轮廓进行定义,然后 使用方向向量对拉伸体的拉伸方向,拉伸长度进行定义,最后使用这些定义的参数生成拉伸面。注意:在创建拉伸实体时,若preferSolid参数为真,则生成拉伸 体,否则生成拉伸面实体
public static void CmdCreateSurface1(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
#region Create profile
DPoint3d p1 = new DPoint3d(-10000, 10000, 0);//创建面元素端点
DPoint3d p2 = new DPoint3d(10000, 10000, 0);
DPoint3d p3 = new DPoint3d(10000, -10000, 0);
DPoint3d p4 = new DPoint3d(-10000, -10000, 0);
DPoint3d[] pos = { p1, p2, p3, p4 };//将面元素端点添加到面元素端点数组中
ShapeElement shape = new ShapeElement(dgnModel, null, pos);//创建形元素
#endregion
DPoint3d origin = DPoint3d.Zero;//创建拉伸基点
DVector3d extrudeVector = new DVector3d(10000, 10000, 100000);//创建拉伸向量
SurfaceOrSolidElement surface = SurfaceOrSolidElement.CreateProjectionElement(dgnModel, null, shape, origin, extrudeVector, DTransform3d.Identity, false);
/*
* 使用投影的方式创建拉伸面元素
* dgnModel:创建拉伸面元素的模型空间
* templateElement:元素模板
* profile:投影轮廓面(截面)
* origin:拉伸起点
* extrudeVector:拉伸向量
* transform:元素变换矩阵
* preferSolid:生成拉伸体还是拉伸面(若为拉伸体则为true)
*/
surface.AddToModel();//将拉伸面写入模型
}
旋转面实体
创建 旋转面实体时需要首先对旋转轮廓进行定义,然后定义旋转面实体的中心点与旋转轴,最后使用这些参数创建旋转面实体。注意:在创建旋转实体时,若preferSolid参数为真,则生成旋转体,否则生成旋转面实体
public static void CmdCreateSurface2(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
#region Create profile
DPoint3d p1 = new DPoint3d(0, 0, 0);//创建面元素端点
DPoint3d p2 = new DPoint3d(0, 0, 10000);
DPoint3d p3 = new DPoint3d(10000, 0, 10000);
DPoint3d p4 = new DPoint3d(10000, 0, 0);
DPoint3d[] pos = { p1, p2, p3, p4 };//将面元素端点添加到面元素端点数组中
ShapeElement shape = new ShapeElement(dgnModel, null, pos);//创建形元素
#endregion
DPoint3d centerPo = new DPoint3d(-10000, 0, 0);//创建旋转面元素的中心点
DVector3d axis = new DVector3d(0, 0, 1);//创建旋转面元素的旋转轴
SurfaceOrSolidElement surface = SurfaceOrSolidElement.CreateRevolutionElement(dgnModel, null, shape, centerPo, axis, Angle.PI.Radians / 2, false);
/*
* 创建旋转面元素
* dgnModel:创建旋转面元素的模型空间
* templateElement:元素模板
* profile:旋转截面
* center:旋转面元素的中心点
* axis:旋转轴线
* sweepAngle:旋转扫掠角
* preferSolid:生成旋转体还是旋转面(若为旋转体则为true)
*/
surface.AddToModel();//将旋转面元素写入模型
}
网格元素(MeshHeaderElement)
网格元素的创建方式有些复杂,首选需要创建多面体几何,若使用编程的方式创建多面体几何,需要首先确定多面体几何的端点坐标,然后根据网格的分布情况按照端点坐标的索引值连线形成局部网格并将信息添加到多面体几何中,最后使用多面体几何创建网格元素
public static void CmdCreateMesh(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
#region create polyface
DPoint3d p1 = DPoint3d.Zero;//创建多面体端点坐标
DPoint3d p2 = new DPoint3d(10000,0,0);
DPoint3d p3 = new DPoint3d(0,10000,0);
DPoint3d p4 = new DPoint3d(0,0,10000);
IList<DPoint3d> pos = new List<DPoint3d>();//创建储存多面体坐标的列表
pos.Add(p1);//将多面体端点坐标添加到列表中
pos.Add(p2);
pos.Add(p3);
pos.Add(p4);
PolyfaceHeader polyface = new PolyfaceHeader();//创建多面体几何
polyface.Point= pos;//设置该多面体几何的端点集
polyface.ActivateVectorsForIndexing(polyface);//激活多面体几何中的数据与索引
List<int> indices = new List<int>();//创建索引列表
indices.Add(1); indices.Add(2); indices.Add(3); //将索引号添加到列表中
polyface.AddIndexedFacet(indices, null, null, indices);//添加索引信息到多面体几何中
indices.Clear();//清空索引列表
indices.Add(1); indices.Add(2); indices.Add(4);//继续将索引号添加到列表中
polyface.AddIndexedFacet(indices, null, null, indices);
indices.Clear();
indices.Add(2); indices.Add(3); indices.Add(4);
polyface.AddIndexedFacet(indices, null, null, indices);
indices.Clear();
indices.Add(1); indices.Add(3); indices.Add(4);
polyface.AddIndexedFacet(indices, null, null, indices);
#endregion
MeshHeaderElement mesh = new MeshHeaderElement(dgnModel,null,polyface);//创建使用多面体几何网格元素
mesh.AddToModel();//将网格元素添加到模型空间中
}
智能实体(SolidKernelEntity)-拉伸
与普通拉伸实体不同的是,智能拉伸实体是一个拉伸体到指定平面后生成的结果。首先需要创建一个拉伸体,然后再创建一个拉伸终点的平面,最后将参数输入后即生成实体拉伸到另一个平面的新实体,需要注意的是,平面必须完全将实体截断,否则无法生产最终的结果
public static void CmdCreateSmartSolid1(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
DPoint3d profilePo1 = new DPoint3d(-50000, 50000, 0);//创建拉伸体拉伸平面端点
DPoint3d profilePo2 = new DPoint3d(50000, 50000, 0);
DPoint3d profilePo3 = new DPoint3d(50000, -50000, 0);
DPoint3d profilePo4 = new DPoint3d(-50000, -50000, 0);
IList<DPoint3d> profilePos = new List<DPoint3d>() {profilePo1,profilePo2,profilePo3,profilePo4, profilePo1 };//创建拉伸体拉伸平面的端点列表
CurveVector profileCurve = CurveVector.CreateLinear(profilePos,CurveVector.BoundaryType.Outer,false);//创建拉伸体拉伸平面轮廓线
Create.BodyFromCurveVector(out SolidKernelEntity profileEntity,profileCurve,dgnModel);//将拉伸平面轮廓线转化为SolidKernelEntity
DPoint3d extrudePo1 = new DPoint3d(-50000, 50000, -100000);//创建拉伸体截面端点
DPoint3d extrudePo2 = new DPoint3d(50000, 50000, -200000);
DPoint3d extrudePo3 = new DPoint3d(50000, -50000, -300000);
DPoint3d extrudePo4 = new DPoint3d(-50000, -50000, -200000);
IList<DPoint3d> extrudePos = new List<DPoint3d>() { extrudePo1, extrudePo2, extrudePo3, extrudePo4, extrudePo1 };//创建拉伸体截面端点列表
CurveVector extrudeCurve = CurveVector.CreateLinear(extrudePos, CurveVector.BoundaryType.Outer, true);//创建拉伸体截面轮廓线
Create.BodyFromCurveVector(out SolidKernelEntity extrudeEntity, extrudeCurve, dgnModel);//将截面轮廓线转化为SolidKernelEntity
Create.BodyFromExtrusionToBody(out SolidKernelEntity solid,extrudeEntity,profileEntity,false);
/*
* 通过将平面实体拉伸到另一个平面实体来创建新实体
* entityOut:新实体
* extrudeToIn:修剪拉伸实体的平面实体
* profileIn:要拉伸的平面实体。
* reverseDirectionIn:拉伸方向是否与拉伸的平面实体法线方向相同或相反
*/
Convert1.BodyToElement(out Element solidElem,solid,null,dgnModel);//将实体转换为元素
solidElem.AddToModel();//将元素写入模型空间
}
智能实体(SolidKernelEntity)-轮廓放样
轮廓放样,即我们可以通过输入拉伸体的不同轮廓进行放样融合,形成一个新的实体。在智能实体的轮廓放样中,我们需要首先定义实体的多个轮廓,他们之间会根据计算进行融合过渡,同时,也可以通过定义轮廓线的方式硬性设置轮廓的放样轨迹,最终生产实体。需要注意的是 ,在轮廓放样中,若不规定轮廓轨迹,依然需要在轨迹线输入参中填入数据,一般可以将轮廓线列表填入,但不可不填,否则会造成程序崩溃
public static void CmdCreateSmartSolid2(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
CurveVector[] profilesIn = new CurveVector[3];//创建截面曲线数组
DPoint3d[] ptArr_Section0 = new DPoint3d[4];//创建截面端点数组
ptArr_Section0[0] = new DPoint3d(-500, 500, 0);//创建截面端点
ptArr_Section0[1] = new DPoint3d(500, 500, 0);
ptArr_Section0[2] = new DPoint3d(500, -500, 0);
ptArr_Section0[3] = new DPoint3d(-500, -500, 0);
ShapeElement shp0 = new ShapeElement(dgnModel, null, ptArr_Section0);//创建形元素
profilesIn[0] = CurvePathQuery.ElementToCurveVector(shp0);//将面转换为曲线
DPoint3d[] ptArr_Section1 = new DPoint3d[4];
ptArr_Section1[0] = new DPoint3d(0, 1000, 5000);
ptArr_Section1[1] = new DPoint3d(1000, 0, 5000);
ptArr_Section1[2] = new DPoint3d(0, -1000, 5000);
ptArr_Section1[3] = new DPoint3d(-1000, 0, 5000);
ShapeElement shp1 = new ShapeElement(dgnModel, null, ptArr_Section1);
profilesIn[1] = CurvePathQuery.ElementToCurveVector(shp1);
DPoint3d[] ptArr_Section2 = new DPoint3d[4];
ptArr_Section2[0] = new DPoint3d(-500, 500, 10000);
ptArr_Section2[1] = new DPoint3d(500, 500, 10000);
ptArr_Section2[2] = new DPoint3d(500, -500, 10000);
ptArr_Section2[3] = new DPoint3d(-500, -500, 10000);
ShapeElement shp2 = new ShapeElement(dgnModel, null, ptArr_Section2);
profilesIn[2] = CurvePathQuery.ElementToCurveVector(shp2);
BentleyStatus result = Create.BodyFromLoft(out SolidKernelEntity entityOut, profilesIn, 3, profilesIn, 0, dgnModel, false, false);
/*
* 创建一组轮廓线放样创建实体
* bool segmentIn
* entityOut:创建的放样实体
* profilesIn:横截面轮廓集
* nProfilesIn:横截面数量
* guidesIn:(可选)用于控制放样曲线轨迹的曲线集 注意:若不使用控制曲线,该位置可将横截面轮廓集填到此处,不可为空,否则会报错
* nGuidesIn:控制放样曲线轨迹的曲线数量
* modelRefIn:获取当前模型的比例单位
* periodicIn:若为真,则会构造一个闭合曲面,其中第一条截面将作为最后一条截面
* segmentIn:若为真,每个截面间将创建线性曲线而不做平滑
*/
result = Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素
eeh.AddToModel();//将元素写入模型
}
智能实体-拉伸
智能拉伸实体的创建方法与普通拉伸实体的创建方式类似。首先创建一个智能拉伸实体的外轮廓线和拉伸向量,记录拉伸长度及拉伸方向,然后使用该模型创建普通实体,最后将普通实体转化为智能实体。
public static void CmdCreateSmartSolid3(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
DPoint3d p1 = new DPoint3d(10000,10000);//创建截面轮廓线端点
DPoint3d p2 = new DPoint3d(10000,-10000);
DPoint3d p3 = new DPoint3d(-10000,-10000);
DPoint3d p4 = new DPoint3d(-10000,10000);
IList<DPoint3d> pos = new List<DPoint3d>() { p1,p2,p3,p4};//创建轮廓线端点数组
CurveVector curve = CurveVector.CreateLinear(pos,CurveVector.BoundaryType.Outer,true);//创建轮廓线
DVector3d vector = new DVector3d(0,0,10000);//创建拉伸向量(包含拉伸长度及方向信息)
DgnExtrusionDetail detail = new DgnExtrusionDetail(curve, vector,true);
/*
* 创建拉伸信息
* baseCurve:截面轮廓曲线
* extrusionVector:拉伸信息
* capped:若启用端盖则为真
*/
SolidPrimitive solid = SolidPrimitive.CreateDgnExtrusion(detail);//使用拉伸信息创建实体
BentleyStatus result = Create.BodyFromSolidPrimitive(out SolidKernelEntity entityOut, solid,dgnModel);//使用拉伸实体创建SolidKernelEntity
result = Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素
eeh.AddToModel();//将元素写入模型
}
智能实体(SolidKernelEntity) 扫掠
创建智能扫掠实体时需要首先使用曲线定义扫掠的轮廓线,然后定义扫掠的轨迹线,最后使用轮廓线及轨迹线,结合扫掠属性,比如说是否修复扫掠自交,否在扫掠过程中旋转轮廓截面,沿路径扫掠截面是
否需要变化等属性生成最终的智能掠实体。
public static void CmdCreateSmartSolid4(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
DPoint3d profilePo1 = new DPoint3d(1000, 1000,-10000);//创建截面轮廓线端点
DPoint3d profilePo2 = new DPoint3d(1000, -1000, -10000);
DPoint3d profilePo3 = new DPoint3d(-1000, -1000, -10000);
DPoint3d profilePo4 = new DPoint3d(-1000, 1000, -10000);
DPoint3d[] profilePos = { profilePo1 , profilePo2, profilePo3, profilePo4};//创建截面轮廓线端点集
ShapeElement shape = new ShapeElement(dgnModel,null, profilePos);//创建形元素
CurveVector curve= CurvePathQuery.ElementToCurveVector(shape);//使用图形元素获得轮廓线
DPoint3d pathPo1 = new DPoint3d(0, 0, -10000);//创建扫掠轨迹线端点
DPoint3d pathPo2 =new DPoint3d(0, 0,0);
DPoint3d pathPo3 = new DPoint3d(10000,10000,10000);
DPoint3d pathPo4 = new DPoint3d(-10000, -10000, 20000);
DPoint3d pathPo5 = new DPoint3d(0, 0, 30000);
DPoint3d pathPo6 = new DPoint3d(0, 0, 40000);
DPoint3d[] pathPos = { pathPo1, pathPo2, pathPo3, pathPo4 , pathPo5, pathPo6};//创建扫掠轨迹端点集
LineStringElement lineString = new LineStringElement(dgnModel,null, pathPos);//创建线串元素
CurveVector pathCurve = lineString.GetCurveVector();//使用线串元素获得扫掠轨迹点
Create.BodyFromSweep(out SolidKernelEntity entityOut, curve, pathCurve, dgnModel, false, true, false,
null, null,null , null);
/*
* 使用横截面扫掠路径创建实体
* entityOut:生成的新实体
* profileIn:横断面轮廓(开放,闭合或带孔区域)
* pathIn:扫掠轨迹线
* modelRefIn:获取当前模型的比例单位
* alignParallelIn:若为真,则轮廓与全局轴线保持固定角度,而不是与路径相切并锁定方向
* selfRepairIn:若为真,则会尝试修复扫掠自交
* createSheetIn:若为真,则会强制生成闭合的扫掠实体
* lockDirectionIn:(可选)使截面轮廓与垂直于方向向量同时切线保持固定角度,仅当alignParallelIn为真时有效
* twistAngleIn:(可选)在轮廓沿路径移动时旋转轮廓角度
* scaleIn:(可选)在轮廓沿路径扫掠时缩放比例
* scalePointIn:应用缩放需要缩放的轮廓端点
*/
BentleyStatus result = Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素
eeh.AddToModel();//将元素写入模型
}
智能实体(SolidKernelEntity) -缝合
该访法的思路与创建网格元素有些类似,简单来说就是首先创建构成智能实体的子实体,然后将这些子实体缝合为-一个整体的智能实体。首先创建组成智能实体的形元素,然后将形元素转换为实核实体,后使用实核实体缝合成为智能实体。
public static void CmdCreateSmartSolid5(string unparsed)
{
List<DPoint3d> points = new List<DPoint3d>();//创建坐标列表
points.Add(new DPoint3d(0, 0, 0));//给列表添加坐标
points.Add(new DPoint3d(10, 0, 0));
points.Add(new DPoint3d(10, 10, 0));
points.Add(new DPoint3d(0, 10, 0));
ShapeElement shape1 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());//创建形元素
points.Clear();//清空列表元素
points.Add(new DPoint3d(0, 0, 0));
points.Add(new DPoint3d(10, 0, 0));
points.Add(new DPoint3d(10, 0, 10));
points.Add(new DPoint3d(0, 0, 10));
ShapeElement shape2 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());
points.Clear();
points.Add(new DPoint3d(0, 10, 0));
points.Add(new DPoint3d(10, 10, 0));
points.Add(new DPoint3d(10, 10, 10));
points.Add(new DPoint3d(0, 10, 10));
ShapeElement shape3 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());
points.Clear();
points.Add(new DPoint3d(10, 0, 0));
points.Add(new DPoint3d(10, 10, 0));
points.Add(new DPoint3d(10, 10, 10));
points.Add(new DPoint3d(10, 0, 10));
ShapeElement shape4 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());
points.Clear();
points.Add(new DPoint3d(0, 0, 0));
points.Add(new DPoint3d(0, 10, 0));
points.Add(new DPoint3d(0, 10, 10));
points.Add(new DPoint3d(0, 0, 10));
ShapeElement shape5 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());
points.Clear();
points.Add(new DPoint3d(0, 0, 10));
points.Add(new DPoint3d(0, 10, 10));
points.Add(new DPoint3d(10, 10, 10));
points.Add(new DPoint3d(10, 0, 10));
ShapeElement shape6 = new ShapeElement(Session.Instance.GetActiveDgnModel(), null, points.ToArray());
SolidKernelEntity[] tools1 = new SolidKernelEntity[6];//创建实核实体列表
Convert1.ElementToBody(out tools1[0], shape1, false, true, false);//将Shape元素转换为实核实体
Convert1.ElementToBody(out tools1[1], shape2, false, true, false);
Convert1.ElementToBody(out tools1[2], shape3, false, true, false);
Convert1.ElementToBody(out tools1[3], shape4, false, true, false);
Convert1.ElementToBody(out tools1[4], shape5, false, true, false);
Convert1.ElementToBody(out tools1[5], shape6, false, true, false);
BrepCellHeaderElement brepCellHeader = null;//初始化智能实体
if (BentleyStatus.Success == Modify.SewBodies(out SolidKernelEntity[] sewn1, out SolidKernelEntity[] unsewn1, ref tools1, 6, 0, 1))//缝合实核实体
{
for (int i = 0; i < sewn1.Length; i++)//遍历缝合结果
{
brepCellHeader = new BrepCellHeaderElement(Session.Instance.GetActiveDgnModel(), null, sewn1[i]);//创建智能实体
brepCellHeader.AddToModel();//将智能实体写入模型
}
}
}