using System; using System.Collections.Generic; using System.Linq; using Bentley.DgnPlatformNET; using Bentley.DgnPlatformNET.Elements; using Bentley.GeometryNET; using Bentley.MstnPlatformNET; namespace Mstn.Toolkit.Helpers { public class ElementCreationHelper { /// /// 在当前模型中创建椭圆 /// /// /// 长轴向量 /// 短轴向量 /// public static ArcElement CreateArc(DPoint3d centerPoint, DVector3d longVector, DVector3d shortVector) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); DEllipse3d ellipse = new(centerPoint, longVector, shortVector); ArcElement arc = new(dgnModel, null, ellipse); arc.AddToModel(); return arc; } /// /// Angle.PI.Radians /// /// 中心点 /// 长轴长 /// 短轴长 /// 起始弧度 /// 扫过的弧度 /// 创建弧度的方法Angle.PI.Radians /// public static ArcElement CreateArc(DPoint3d centerPoint, double longLength, double shortLength, double startRadian, double sweepRadian) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); /* * 创建弧元素 * dgnModel:创建弧元素所在模型空间 * templateElement:元素模板 * center:弧元素的圆心 * axis1:主轴长 * axis2:副轴长 * rotation:圆弧旋转角(平面旋转) * start:圆弧起始旋转角 * sweep:圆弧扫掠角 */ ArcElement arc = new(dgnModel, null, centerPoint, longLength, shortLength, 0, startRadian, sweepRadian); arc.AddToModel(); return arc; } /// /// 折线 /// /// /// public static BSplineCurveElement CreateBSplineCurve(params DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); MSBsplineCurve msBSplineCurve = MSBsplineCurve.CreateFromPoints(points); //用B样条曲线创建B样条曲线元素 BSplineCurveElement bSplineCurve = new(dgnModel, null, msBSplineCurve); bSplineCurve.AddToModel(); return bSplineCurve; } /// /// 创建B样条曲线元素 /// /// 起终点切向 /// /// public static BSplineCurveElement CreateBSplineCurve(List tangents, params DPoint3d[] points) { if (tangents.Count != 2) { throw new ArgumentException("参数有误,起终点切向方向数量有误,必须为2"); } DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); /* *根据节点和起端点切线方向创建插值曲线 * points:插值点 * removeDuplicatePoints:是否需要删除重复点 * endTangents:端点切线方向向量 * closedCurve:是否需要闭合曲线 * colinearTangents:切线是否共线 * chordLenTangents:是否仅相切弦 * naturalTangents:是否为自然切线 */ MSInterpolationCurve interpolationCurve = MSInterpolationCurve.CreateFromPointsAndEndTangents( points, true, 0, tangents, true, false, false, false); BSplineCurveElement bSplineCurve = new(dgnModel, null, interpolationCurve); bSplineCurve.AddToModel(); return bSplineCurve; } /// /// 创建复杂形状 /// /// public static void CreateComplexShape(params Element[] elements) { var dgnModel = Session.Instance.GetActiveDgnModel(); ComplexShapeElement complexShape = new(dgnModel, null);//创建复杂形元素 foreach (var elem in elements) { complexShape.AddComponentElement(elem); } complexShape.AddComponentComplete();//添加子部件完成 complexShape.AddToModel();//将复杂元素写入模型 } public static ComplexStringElement CreateComplexString(params DisplayableElement[] elements) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); ComplexStringElement complexString = new(dgnModel, null); foreach (DisplayableElement element in elements) { complexString.AddComponentElement(element); } complexString.AddToModel(); return complexString; } /// /// 创建圆台 /// /// /// /// /// public static ConeElement CreateCone(double topRadius, double bottomRadius, List points) { var dgnModel = Session.Instance.GetActiveDgnModel(); var cone = new ConeElement(dgnModel, null, topRadius, bottomRadius, points.First(), points .Last(), DMatrix3d.Identity, true); cone.AddToModel(); return cone; } /// /// 在当前模型中创建曲线元素 /// /// 三维点个数需大于等于6 /// public static CurveElement CreateCurve(params DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); CurveElement curve = new(dgnModel, null, points); curve.AddToModel(); return curve; } /// /// 在当前模型中创建曲线元素 /// /// 三维点个数需大于等于6 /// public static CurveElement CreateCurve(List points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); CurveElement curve = new(dgnModel, null, points); curve.AddToModel(); return curve; } /// /// 创建椭圆 /// /// 椭圆圆心 /// 主轴向量 /// 副轴向量 public static EllipseElement CreateEllipse(DPoint3d centerPo, DVector3d vector0In, DVector3d vector90In) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 DEllipse3d ellipse = new(centerPo, vector0In, vector90In);//创建椭圆几何 EllipseElement ellipseElem = new(dgnModel, null, ellipse);//使用椭圆几何创建椭圆元素 ellipseElem.AddToModel(); return ellipseElem; } /// /// 创建椭圆 /// /// 椭圆圆心 /// 主轴长度 /// 主轴长度 /// public static EllipseElement CreateEllipse(DPoint3d centerPo, double longAxis, double shortAxis, double angle) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); EllipseElement ellipseElem = new(dgnModel, null, centerPo, longAxis, shortAxis, angle); ellipseElem.AddToModel(); return ellipseElem; } /// /// 创建椭圆 /// /// 椭圆圆心 /// 主轴长度 /// 主轴长度 /// 变换矩阵 public static EllipseElement CreateEllipse(DPoint3d centerPo, double longAxis, double shortAxis, DMatrix3d matrix) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); EllipseElement ellipseElem = new(dgnModel, null, centerPo, longAxis, shortAxis, matrix); ellipseElem.AddToModel(); return ellipseElem; } /// /// 在当前模型中创建直线元素 /// /// /// /// public static LineElement CreateLine(DPoint3d startPoint, DPoint3d endPoint) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); //创建直线图元 DSegment3d segment = new(startPoint, endPoint); //创建直线元素 var line = new LineElement(dgnModel, null, segment); line.AddToModel(); return line; } /// /// 在当前模型中创建线串元素 /// /// /// public static LineStringElement CreateLineString(params DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); var pointString = new LineStringElement(dgnModel, null, points); pointString.AddToModel(); return pointString; } /// /// /// /// 多面体坐标的列表 public static void CreateMesh(List pos) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 //TODO #region create polyface //DPoint3d p1 = DPoint3d.Zero;//创建多面体端点坐标 //DPoint3d p2 = new(10000, 0, 0); //DPoint3d p3 = new(0, 10000, 0); //DPoint3d p4 = new(0, 0, 10000); //IList pos = //[ // p1,//将多面体端点坐标添加到列表中 // p2, // p3, // p4, //];//创建储存多面体坐标的列表 PolyfaceHeader polyface = new() { Point = pos//设置该多面体几何的端点集 };//创建多面体几何 polyface.ActivateVectorsForIndexing(polyface);//激活多面体几何中的数据与索引 List indices = [ 1, 2, 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(dgnModel, null, polyface);//创建使用多面体几何网格元素 mesh.AddToModel();//将网格元素添加到模型空间中 } /// /// 创建多线 /// public static void CreateMultiLine() { // TODO var dgnModel = Session.Instance.GetActiveDgnModel(); DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//获取当前模型所属文件 MultilineStyle lineStyle = new("testMultiline", dgnFile);//创建多线元素样式 MultilineProfile profile1 = new() { Distance = 0,//设置轮廓偏移基点 UseLinestyle = true,//设置轮廓是否使用线样式 Linestyle = 1//设置轮廓线样式 };//创建多线轮廓 lineStyle.InsertProfile(profile1, 0);//将轮廓信息写入多线样式中 MultilineProfile profile2 = new() { Distance = -10000//设置轮廓偏移基点 };//创建多线轮廓 lineStyle.InsertProfile(profile2, 1);//将轮廓信息写入多线样式中 DVector3d vector = DVector3d.UnitZ;//设置多线法线方向向量 DPoint3d p1 = DPoint3d.Zero;//设置多线轨迹控制点 DPoint3d p2 = new(100000, 0, 0); DPoint3d p3 = new(200000, 200000, 0); DPoint3d[] pos = { p1, p2, p3 };//创建轨迹点数组 MultilineElement multiline = MultilineElement.CreateMultilineElement( dgnModel, null, lineStyle, 1, vector, pos); /* * 创建多线元素 * dgnModel:写入多线元素的模型空间 * templateElement:元素模板 * mlineStyle:多线样式 * styleScale:样式缩放比例 * normal:多线法线方向向量 * points:轨迹点数组 */ multiline.AddToModel();//将多线元素写入模型空间 } /// /// 在当前模型中创建点串元素 /// /// /// public static PointStringElement CreatePointString(params DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); var pointString = new PointStringElement(dgnModel, null, points, true); pointString.AddToModel(); return pointString; } /// /// 在当前模型中创建点串元素 /// /// 变换矩阵 /// /// 矩阵个数要于点数一致,且一一对应 /// public static PointStringElement CreatePointString(DMatrix3d[] ms, DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); var pointString = new PointStringElement(dgnModel, null, points, ms, true); pointString.AddToModel(); return pointString; } /// /// 拉伸投影体 /// /// 拉伸起点 /// 拉伸方向及长度 /// /// /// public static SurfaceOrSolidElement CreateProjectionSolid(DPoint3d origin, DVector3d extrudeVector, bool isSolid, params DPoint3d[] profilePoints) { var dgnModel = Session.Instance.GetActiveDgnModel(); ShapeElement shape = new(dgnModel, null, profilePoints); /* * 使用投影的方式创建拉伸面元素 * dgnModel:创建拉伸面元素的模型空间 * templateElement:元素模板 * profile:投影轮廓面(截面) * origin:拉伸起点 * extrudeVector:拉伸向量 * transform:元素变换矩阵 * preferSolid:生成拉伸体还是拉伸面(若为拉伸体则为true) */ SurfaceOrSolidElement surface = SurfaceOrSolidElement.CreateProjectionElement( dgnModel, null, shape, origin, extrudeVector, DTransform3d.Identity, isSolid); surface.AddToModel(); return surface; } /// /// 创建旋转体 /// /// 轮廓 /// 创建旋转体元素的中心点 /// 创建旋转体元素的旋转轴 public static void CreateRevolution(ShapeElement shape, DPoint3d centerPo, DVector3d axis, bool isSolid) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 SurfaceOrSolidElement solid = SurfaceOrSolidElement.CreateRevolutionElement( dgnModel, null, shape, centerPo, axis, Angle.PI.Radians / 2, isSolid); /* * 创建旋转体元素 * dgnModel:创建旋转体元素的模型空间 * templateElement:元素模板 * profile:旋转截面 * center:旋转面元素的中心点 * axis:旋转轴线 * sweepAngle:旋转扫掠角 * preferSolid:生成旋转体还是旋转面(若为旋转体则为true) */ solid.AddToModel();//将旋转体元素写入模型 } /// /// 规则拉伸体 /// /// 截面1 /// 截面2 public static void CreateRuledSweep(CurveVector profileA, CurveVector profileB) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前激活的model //创建规则拉伸体 DgnRuledSweep DgnRuledSweep dgnRuledSweepDetail = new(profileA, profileB, true); //转化为element 添加到model中 Element element = DraftingElementSchema.ToElement(dgnModel, dgnRuledSweepDetail, null); element.AddToModel(); } /// /// //在当前模型中创建形元素 /// /// /// public static ShapeElement CreateShape(params DPoint3d[] points) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); ShapeElement shape = new(dgnModel, null, points); shape.AddToModel(); return shape; } /// /// 拉伸体 /// /// 拉伸体拉伸平面轮廓线 /// 拉伸体截面轮廓线 public static Element CreateSmartSolidFromExtrusion(CurveVector profileCurve, CurveVector extrudeCurve) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 Create.BodyFromCurveVector(out SolidKernelEntity profileEntity, profileCurve, dgnModel);//将拉伸平面轮廓线转化为SolidKernelEntity 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();//将元素写入模型空间 return solidElem; } public static Element CreateSmartSolidFromLoft(params CurveVector[] profilesIns) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 Create.BodyFromLoft(out SolidKernelEntity entityOut, profilesIns, profilesIns.Length, profilesIns, 0, dgnModel, false, false); /* * 创建一组轮廓线放样创建实体 * bool segmentIn * entityOut:创建的放样实体 * profilesIn:横截面轮廓集 * nProfilesIn:横截面数量 * guidesIn:(可选)用于控制放样曲线轨迹的曲线集 注意:若不使用控制曲线,该位置可将横截面轮廓集填到此处,不可为空,否则会报错 * nGuidesIn:控制放样曲线轨迹的曲线数量 * modelRefIn:获取当前模型的比例单位 * periodicIn:若为真,则会构造一个闭合曲面,其中第一条截面将作为最后一条截面 * segmentIn:若为真,每个截面间将创建线性曲线而不做平滑 */ Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素 eeh.AddToModel();//将元素写入模型 return eeh; } public static Element CreateSmartSolidFromLoft(params ShapeElement[] profilesIns) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 CurveVector[] profilesIn = new CurveVector[profilesIns.Length];//创建截面曲线数组 for (int i = 0; i < profilesIns.Length; i++) { var shp0 = profilesIns[i]; profilesIn[i] = CurvePathQuery.ElementToCurveVector(shp0);//将面转换为曲线 } Create.BodyFromLoft(out SolidKernelEntity entityOut, profilesIn, profilesIn.Length, profilesIn, 0, dgnModel, false, false); /* * 创建一组轮廓线放样创建实体 * bool segmentIn * entityOut:创建的放样实体 * profilesIn:横截面轮廓集 * nProfilesIn:横截面数量 * guidesIn:(可选)用于控制放样曲线轨迹的曲线集 注意:若不使用控制曲线,该位置可将横截面轮廓集填到此处,不可为空,否则会报错 * nGuidesIn:控制放样曲线轨迹的曲线数量 * modelRefIn:获取当前模型的比例单位 * periodicIn:若为真,则会构造一个闭合曲面,其中第一条截面将作为最后一条截面 * segmentIn:若为真,每个截面间将创建线性曲线而不做平滑 */ Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素 eeh.AddToModel();//将元素写入模型 return eeh; } /// /// 拉伸智能实体 /// /// 轮廓线 /// 拉伸向量(包含拉伸长度及方向信息) public static Element CreateSmartSolidFromPrimitive(CurveVector profile, DVector3d vector) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 DgnExtrusionDetail detail = new(profile, vector, true); /* * 创建拉伸信息 * baseCurve:截面轮廓曲线 * extrusionVector:拉伸信息 * capped:若启用端盖则为真 */ SolidPrimitive solid = SolidPrimitive.CreateDgnExtrusion(detail);//使用拉伸信息创建实体 Create.BodyFromSolidPrimitive(out SolidKernelEntity entityOut, solid, dgnModel);//使用拉伸实体创建SolidKernelEntity Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素 eeh.AddToModel();//将元素写入模型 return eeh; } /// /// 缝合实核实体 /// /// 形状 public static void CreateSmartSolidFromSew(params ShapeElement[] shapeElements) { SolidKernelEntity[] tools = new SolidKernelEntity[shapeElements.Length];//创建实核实体列表 for (int i = 0; i < shapeElements.Length; i++) { Convert1.ElementToBody(out tools[i], shapeElements[i], false, true, false);//将Shape元素转换为实核实体 } BrepCellHeaderElement brepCellHeader = null;//初始化智能实体 if (BentleyStatus.Success == Modify.SewBodies(out SolidKernelEntity[] sewns, out SolidKernelEntity[] unsewns, ref tools, 6, 0, 1))//缝合实核实体 { for (int i = 0; i < sewns.Length; i++)//遍历缝合结果 { brepCellHeader = new BrepCellHeaderElement(Session.Instance.GetActiveDgnModel(), null, sewns[i]);//创建智能实体 brepCellHeader.AddToModel();//将智能实体写入模型 } } } /// /// 扫掠体 /// /// 截面 /// 路径 /// public static Element CreateSmartSolidFromSweep(CurveVector curve, CurveVector pathCurve) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 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:应用缩放需要缩放的轮廓端点 */ Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素 eeh.AddToModel();//将元素写入模型 return eeh; } /// /// 扫掠体 /// /// 截面形状 /// 路径点 /// public static Element CreateSmartSolidFromSweep(ShapeElement Profile, params DPoint3d[] pathPos) { DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间 CurveVector curve = CurvePathQuery.ElementToCurveVector(Profile);//使用图形元素获得轮廓线 LineStringElement lineString = new(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:应用缩放需要缩放的轮廓端点 */ Convert1.BodyToElement(out Element eeh, entityOut, null, dgnModel);//将SolidKernelEntity转换为元素 eeh.AddToModel();//将元素写入模型 return eeh; } /// /// 创建曲面 /// /// /// public static BrepCellHeaderElement CreateSmartSurface(List points) { var dgnModel = Session.Instance.GetActiveDgnModel(); CurveVector curve = CurveVector.CreateLinear(points, CurveVector.BoundaryType.Outer, true);//根据列表中的端点坐标创建曲线 Create.BodyFromCurveVector(out var solid, curve, dgnModel);//使用曲线创建SolidEntity BrepCellHeaderElement brepCellHeader = new(dgnModel, null, solid);//使用SolidEntity创建智能实体 return brepCellHeader; } public static void CreateTag(DPoint3d insertPoint, Element elementToTag, object value) { DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//获得创建文本元素的文件 DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获得创建文本元素的模型空间 DgnTagDefinition[] tagDefs = [ new DgnTagDefinition { Name = "Line",//设置标签名称 TagDataType = TagType.Double,//设置标签类型 Value = value//设置标签值 },//创建标签定义 ];//创建标签定义数组 TagSetElement tagSet = new(dgnModel, tagDefs, tagDefs[0].Name, "", true, dgnFile, 0);//创建标签集元素 tagSet.AddToModel();//将标签集元素写入模型 DMatrix3d orientation = DMatrix3d.Identity;//设置标签变换矩阵 DgnTextStyle style = DgnTextStyle.GetSettings(dgnFile);//从当前激活的文件中获得文字样式 TagElement tag = new( dgnModel, null, tagSet.SetName, tagSet.SetName, null, style, false, insertPoint, orientation, elementToTag);//创建标注元素 tag.AddToModel();//将标注元素写入模型 } /// /// 创建文本元素 /// /// /// public static TextElement CreateText(string content) { DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//获得创建文本元素的文件 DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); TextBlockProperties txtBlockProp = new(dgnModel) { IsViewIndependent = false//设置文本非独立于视图 };//创建文本属性 ParagraphProperties paraProp = new(dgnModel);//创建段落属性 DgnTextStyle txtStyle = DgnTextStyle.GetSettings(dgnFile);//从激活的文件中获得文字样式 RunProperties runProp = new(txtStyle, dgnModel);//创建运行属性 TextBlock txtBlock = new(txtBlockProp, paraProp, runProp, dgnModel);//创建文本块 txtBlock.AppendText(content);//设置文本块文字内容 TextElement text = (TextElement)TextHandlerBase.CreateElement(null, txtBlock);//创建文本元素 text.AddToModel();//将生成的文本元素写入模型 return text; } } }