如图,我自己生成了TextBlock,然后利用设置了DimensionStyle的相关参数后,生成了NoteCellHeaderElement,但发现文字直有一部分有引线,我需要整个文字下面都有下划线,该如何设置呢?
DgnFile dgnFile = dgnModel.GetDgnFile(); DgnTextStyle txtStyle = DgnTextStyle.GetSettings(dgnFile); double uor = dgnModel.GetModelInfo().UorPerMaster; double angle = Math.PI / 6; double fontWidth = this.SheetScale * 0.0042 * uor; double fontHeight = this.SheetScale * 0.006 * uor; TextBlockProperties blockProp = new TextBlockProperties(dgnModel); ParagraphProperties paraProp = new ParagraphProperties(dgnModel); RunProperties runProp = new RunProperties(txtStyle, dgnModel); //blockProp.IsViewIndependent = false; runProp.FontSize = new DPoint2d(fontWidth, fontHeight); TextBlock txtBlock = new TextBlock(blockProp, paraProp, runProp, dgnModel); txtBlock.AppendText("站场通号电缆沟400mm(宽)×425mm(深)"); DimensionStyle dimStyle = DimensionStyle.GetSettings(dgnFile); dimStyle.SetBooleanProp(true, DimStyleProp.MLNote_ShowLeader_BOOLINT);//显示引线 dimStyle.SetIntegerProp(1, DimStyleProp.MLNote_HorAttachment_INTEGER);// //dimStyle.SetIntegerProp(0, DimStyleProp.MLNote_Justification_INTEGER);//文字水平对齐方式 //dimStyle.SetIntegerProp(0, DimStyleProp.MLNote_VerticalJustification_INTEGER);//文字水平对齐方式 DPoint3d[] pts = new DPoint3d[2]; pts[0] = new DPoint3d(point.X, point.Y) * uor; pts[1] = new DPoint3d(point.X + vector.X * 50 , point.Y + vector.Y * 50) * uor; NoteCellHeaderElement noteEle = new NoteCellHeaderElement(out Element leaderEle, txtBlock, dimStyle, dgnModel, pts); noteEle.AddToModel(out leaderEle, dgnModel);
请提供对应的DGN文件和不依赖任何条件就能直接执行的代码供我们测试。您现在的代码中还会涉及到太多其他的内容,请都用硬编码来写成具体的值。
DgnModel dgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel(); DgnFile dgnFile = dgnModel.GetDgnFile(); double uor = dgnModel.GetModelInfo().UorPerMaster; DgnTextStyle txtStyle = DgnTextStyle.GetSettings(dgnFile); TextBlockProperties blockProp = new TextBlockProperties(dgnModel); ParagraphProperties paraProp = new ParagraphProperties(dgnModel); RunProperties runProp = new RunProperties(txtStyle, dgnModel); //blockProp.IsViewIndependent = false; double fontWidth = 1000 * 0.0042 * uor; double fontHeight = 1000 * 0.006 * uor; runProp.FontSize = new DPoint2d(fontWidth, fontHeight); TextBlock txtBlock = new TextBlock(blockProp, paraProp, runProp, dgnModel); txtBlock.AppendText("站场通号电缆沟400mm(宽)×425mm(深)"); DimensionStyle dimStyle = DimensionStyle.GetSettings(dgnFile); dimStyle.SetBooleanProp(true, DimStyleProp.MLNote_ShowLeader_BOOLINT);//显示引线 dimStyle.SetIntegerProp(0, DimStyleProp.MLNote_HorAttachment_INTEGER);//文字在引线的方位,自动 dimStyle.SetIntegerProp(0, DimStyleProp.MLNote_Justification_INTEGER);//横向对齐方式,居中 dimStyle.SetIntegerProp(2, DimStyleProp.MLNote_VerticalJustification_INTEGER);//竖向对齐方式,下部 DPoint3d[] pts = new DPoint3d[2]; pts[0] = new DPoint3d(0, 0) * uor; pts[1] = new DPoint3d(-50, -50) * uor; NoteCellHeaderElement noteEle = new NoteCellHeaderElement(out Element leaderEle, txtBlock, dimStyle, dgnModel, pts); noteEle.AddToModel(out leaderEle, dgnModel);
硬编码代码如上,dgn文件无特殊要求,新建即可。
我感觉还是参数控制的问题,Notes的参数非常多,我手工调整参数后能达到您的效果如下:
主要调整了如下这个参数(它应该是文字高度的倍数)。你从代码角度搜索一下这个参数设置后看一下效果。
对应的DGN如下:
5078.test01.dgn
如果实在搞不对的话,可以提取我这个DGN文件中的样例的各个参数做比较,看看到底还有哪些参数会影响到最终的效果。
我又仔细测试了一下,发现是MSCE的一个Bug,只要在Notes的文字内容中出现英汉混杂的情况,这个水平引出线就会在英汉切换的地方停下来。而MSV8i则没有此Bug。MSCE对底层的文字功能做了全新修改,从而引出了这个Bug。我会报告给开发组去解决。感谢您的反馈。
经测试,设置DimStyleProp.MLNote_ElbowLength_DOUBLE的值确实有效果,但程序中需要将值设置为15000左右,不知这个到底是以什么为单位!
dimStyle.SetDoubleProp(1.5*uor, DimStyleProp.MLNote_ElbowLength_DOUBLE);
lingwei liu said:程序中需要将值设置为15000左右,不知这个到底是以什么为单位!
应该是UOR(Unit Of Resolution)单位。有关DGN文件的单位,请看如下文章:
MicroStation中的工作单位