更改多行文字的对齐方式,但保留实际文字位置
嗨!我构建了一个AutoCAD插件,它用一个属性块替换了一些DBText和MTextObject。我的问题:一些MTexts的对齐设置为“左上”,一些设置为“左下”。
替换MTexts的块的设计使其与文本位置完美匹配,如果它设置为“左下”-因为大多数MTexts对象都是这样绘制的;我想将所有MTexts对齐更改为“左下”,因此我可以对所有MTexts对象使用相同的块。
当我在AutoCAD中更改对齐方式时,实际的文本位置保持不变-对齐属性设置为新值,文本移动到新位置,因此字母的位置保持不变同样的
有人能让我开始如何做到这一点吗?我不知道如何解决这个问题...下面我附上了一个小测试命令来更改。MTexts的附件。
public void MTextJustificationTest()
{
Database db = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
Point3d startPos = new Point3d();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TypedValue[] filterDxf = new TypedValue[]
{
new TypedValue((int)DxfCode.Start,"MTEXT")
};
SelectionFilter selectionFilter = new SelectionFilter(filterDxf);
PromptSelectionResult psr = ed.SelectAll(selectionFilter);
SelectionSet selectionSet = psr.Value;
foreach (var objId in psr.Value.GetObjectIds())
{
MText mText = tr.GetObject(objId, OpenMode.ForWrite) as MText;
if (mText.Attachment != AttachmentPoint.BottomLeft)
{
startPos = mText.Location;
// How to get the _real_ text position?
mText.Attachment = AttachmentPoint.BottomLeft;
}
}
tr.Commit();
}
}
**** Hidden Message ***** 我忍不住会告诉你,我用.Net处理文本样式和属性已经试了一百次了,但总是有一些小错误,绘图中的一些东西,或者代码中的东西,或者任何让它成为战利品的东西。我决定继续为他们使用autolisp函数。
页:
[1]