马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Geometry;
namespace TextAlign
{
public class Class1
{
[CommandMethod("TextAl")]
public static void TextAlignmentType()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Create a TypedValue array to define the filter criteria
TypedValue[] acTypValAr = new TypedValue[1];
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 0);
// Assign the filter criteria to a SelectionFilter object
SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
PromptSelectionResult acSSPrompt = doc.Editor.GetSelection(acSelFtr);
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
DBText ent = tr.GetObject(acSSet[0].ObjectId, OpenMode.ForRead) as DBText;
double dblOrigX = ent.Position.X;
double dblOrigY = ent.Position.Y;
double dblOrigZ = ent.Position.Z;
Point3d acOrigPoint = new Point3d(dblOrigX, dblOrigY, dblOrigZ);
double dblTextSize = ent.Height * 1.6;
int intSSLength = acSSet.Count;
for (int intSSCount = 1; intSSCount < intSSLength; intSSCount++)
{
DBText entModText = tr.GetObject(acSSet[intSSCount].ObjectId, OpenMode.ForWrite) as DBText;
double dbOldX = entModText.Position.X;
double dbOldY = entModText.Position.Y;
double dbOldZ = entModText.Position.Z;
Point3d acOldPoint = new Point3d(dbOldX, dbOldY, dbOldZ);
double dblTextGap = intSSCount * dblTextSize;
double dbNewX = dblOrigX;
double dbNewY = dblOrigY - dblTextGap;
double dbNewZ = dblOrigZ;
Point3d acNewPoint = new Point3d(dbNewX, dbNewY, dbNewZ);
Vector3d acVector = acOldPoint.GetVectorTo(acNewPoint);
BlockTable acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
entModText.TransformBy(Matrix3d.Displacement(acVector));
}
tr.Commit();
}
}
}
}
} |