实战案例
目标
实现如图所示的工字钢实体
实现思路
首先创建形元素和拉伸向量,之后创建拉伸实体,然后再根据放置的位置创建文字元素和标注元素
public static void CmdPracticeWork(string unparsed)
{
DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//定义当前激活的文件
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间
#region Create profile
int H = 700 * 10000;
int H1 =125 * 10000, H2 = 125 * 10000;
int H3 = 275 * 10000;
int H4 = 75 * 10000, B4 = 75 * 10000;
int H5 = 100 * 10000;
int B3 = 125 * 10000;
int B1 = 400 * 10000;
int B2 = 300 * 10000;
int B = 150 * 10000;
DPoint3d p1 = new DPoint3d(-1*0.5*B1, 0, 0);//定义体元素端点
DPoint3d p2 = new DPoint3d(-1*0.5*B1,H2,0);
DPoint3d p3 = new DPoint3d(-0.5*B,H2+H5,0);
DPoint3d p4 = new DPoint3d(-0.5*B,H2+H5+H3,0);
DPoint3d p5 = new DPoint3d(-0.5*B2,H2+H5+H3+H4, 0);
DPoint3d p6 = new DPoint3d(-0.5*B2,H, 0);
DPoint3d p7 = new DPoint3d(0.5*B2,H,0);
DPoint3d p8 = new DPoint3d(0.5*B2, H2 + H5 + H3 + H4,0);
DPoint3d p9 = new DPoint3d(0.5 * B, H2 + H5 + H3,0);
DPoint3d p10 = new DPoint3d(0.5 * B,H2 + H5, 0);
DPoint3d p11 = new DPoint3d(0.5 * B1, H2,0);
DPoint3d p12 = new DPoint3d(0.5 * B1, 0, 0);
DPoint3d[] pos = { p1, p2, p3, p4,p5,p6,p7,p8,p9,p10,p11,p12 };//将面元素端点添加到面元素端点数组中
ShapeElement shape = new ShapeElement(dgnModel, null, pos);//定义形元素
#endregion
DPoint3d origin = DPoint3d.Zero;//定义拉伸基点
DVector3d extrudeVector = new DVector3d(0, 0,-12000*10000);//定义拉伸向量
SurfaceOrSolidElement solid = SurfaceOrSolidElement.CreateProjectionElement(dgnModel, null, shape, origin, extrudeVector, DTransform3d.Identity, true);//使用投影的方式定义拉伸体元素
solid.AddToModel();//将拉伸体写入模型
DPoint3d d1 = new DPoint3d(-0.5*B2, H + 50*10000,0);
DPoint3d d2 = new DPoint3d(0.5*B2, H+ 50 * 10000,0);
DPoint3d[] dimensionPos1 = { d1, d2 };
DimensionElement dimEle1 = CreateDimensionElement(dgnFile,dgnModel , dimensionPos1);
dimEle1.AddToModel();
DPoint3d d3 = new DPoint3d(-0.5*B2, H + 10 * 10000,0);
DPoint3d d4 = new DPoint3d(-0.5*B, H+ 10 * 10000,0);
DPoint3d d5 = new DPoint3d(0.5*B, H + 10 *10000, 0);
DPoint3d d6 = new DPoint3d(0.5*B2,H + 10 *10000, 0);
DPoint3d[] dimensionPos2 = { d3, d4,d5,d6 };
DimensionElement dimEle2 = CreateDimensionElement(dgnFile, dgnModel, dimensionPos2);
dimEle2.AddToModel();
TextBlockProperties txtBlockProp = new TextBlockProperties(dgnModel);//定义文本属性
txtBlockProp.IsViewIndependent = false;//设置文本非独立于视图
ParagraphProperties paraProp = new ParagraphProperties(dgnModel);//定义段落属性
DgnTextStyle txtStyle = DgnTextStyle.GetSettings(dgnFile);//从激活的文件中定义文字样式
RunProperties runProp = new RunProperties(txtStyle, dgnModel);//定义运行属性
TextBlock txtBlock = new TextBlock(txtBlockProp, paraProp, runProp, dgnModel);//定义文本块
txtBlock.AppendText("Side View");//设置文本块文字内容
DPoint3d txtOrigin = new DPoint3d(0,-2*10000,0);
txtBlock.SetUserOrigin(txtOrigin);//设置文本块放置位置
TextElement text = (TextElement)TextElement.CreateElement(null, txtBlock);//定义文本元素
DTransform3d trans = DTransform3d.Scale(40);
TransformInfo transInfo = new TransformInfo(trans);
text.ApplyTransform(transInfo);
text.AddToModel();//将生成的文本元素写入模型
}