嗨!
我构建了一个AutoCAD插件,它用一个属性块替换了一些DBText和MTextObject。我的问题:一些MTexts的对齐设置为“左上”,一些设置为“左下”。
替换MTexts的块的设计使其与文本位置完美匹配,如果它设置为“左下”-因为大多数MTexts对象都是这样绘制的;我想将所有MTexts对齐更改为“左下”,因此我可以对所有MTexts对象使用相同的块。
当我在AutoCAD中更改对齐方式时,实际的文本位置保持不变-对齐属性设置为新值,文本移动到新位置,因此字母的位置保持不变同样的
有人能让我开始如何做到这一点吗?我不知道如何解决这个问题...下面我附上了一个小测试命令来更改。MTexts的附件。
- [CommandMethod("MTextJustificationTest")]
- 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();
- }
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |