如下代码中第2个创建的文字AnnotationScale设置为2,但比例没变,请问是为什么?
public static void CreateTextElement(DgnModel dgnModel) { double uor = dgnModel.GetModelInfo().UorPerMeter; DgnTextStyle dgnTextStyle = DgnTextStyle.GetSettings(dgnModel.GetDgnFile()); TextBlockProperties textBlockProperties = new TextBlockProperties(dgnTextStyle, dgnModel); ParagraphProperties paragraphProperties = new ParagraphProperties(dgnTextStyle, dgnModel); RunProperties runProperties = new RunProperties(dgnTextStyle, dgnModel); TextBlock textBlock0 = new TextBlock(textBlockProperties, paragraphProperties, runProperties, dgnModel); textBlock0.AppendText("图形软件"); TextHandlerBase textHandlerBase0 = TextHandlerBase.CreateElement(null, textBlock0); textHandlerBase0.AddToModel(); textBlockProperties.AnnotationScale = 2; TextBlock textBlock1 = new TextBlock(textBlockProperties, paragraphProperties, runProperties, dgnModel); textBlock1.AppendText("图形软件"); TextHandlerBase textHandlerBase1 = TextHandlerBase.CreateElement(null, textBlock1); DTransform3d transform = DTransform3d.FromTranslation(new DPoint3d(3, 0, 0) * uor); textHandlerBase1.ApplyTransform(new TransformInfo(transform)); textHandlerBase1.AddToModel(); }
只有在您的Text是Annotation Text时该比例才会起作用。
代码中如何创建Annotation类型的文字元素呢?
采用AnnotationHandler可以将文字元素(注意,不是TextBlock,而是TextElement)设置为注释文字。
AnnotationHandler anno = AnnotationHandler.GetAsAnnotationHandler(tElem); anno.AddAnnotationScale(dgnModel);
另外,请尽量不要设置文字的AnnotationScale,设置该比例会导致文字的高和宽发生变化引起不必要的误解。我们只要将文字搞成注释文字,其比例就会自动取自模型自身的注释比例的。所有注释元素的比例都来自于当前模型的注释比例设置。
我刚试了下,按上面的方法生成AnnotationHandler后,这个比例依然没有生效。直接textBlockProperties.AnnotationScale = 2这样设置,创建元素后我在MS界面上修改textstyle中的某个值保存后,这个比例又可以生效,不知为什么!
所以我建议您不要对Text单独设置其AnnotationScale。而要保证整个模型有一个AnnotationScale,文字仅仅区分是Annotation的和不是Annotation的。这样就简化了问题。
换句话说,在同一个模型中,所有的文字如果是AnnotationText,则它们应该具有同一个AnnotationScale,这个Scale来自模型的AnnotationScale。如果你在都是Annotation Text的基础上还想写出不同大小的文字时,可以直接设置其Height和Width属性。
MS学习资源:
MicroStation Wednesday视频分享
深入探讨MicroStation DGN基本概念系列
一步步学习MicroStation CE Addin开发
一步步学习MicroStation CE MDL开发
好的,谢谢!