[CommandMethod("0RotateMText")]
public static void RotateMtext()
{
var mtexts = SelectObjectsOnScreen();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using ( tr )
{
foreach ( var item in mtexts )
{
MText mtext = (MText) tr.GetObject(item.ObjectId, OpenMode.ForWrite, false, true);
mtext.Width = 0; // 0.66*mtext.TextHeight*chars;
//mtext.ColumnType = ColumnType.StaticColumns;
if ( mtext.Rotation == 0 )
{
mtext.Rotation = Math.PI/2;
}
else
{
mtext.Rotation = 0;
}
}
tr.Commit();
}
}
public static List < Entity > SelectObjectsOnScreen()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
List < Entity > listOfEntities = new List < Entity >();
using ( tr )
{
// Request for objects to be selected in the drawing area
PromptSelectionResult PrSeRes = doc.Editor.GetSelection();
// If the prompt status is OK, objects were selected
if ( PrSeRes.Status == PromptStatus.OK )
{
SelectionSet SelSet = PrSeRes.Value;
// Step through the objects in the selection set
foreach ( SelectedObject SelObj in SelSet )
{
// Check to make sure a valid SelectedObject object was returned
if ( SelObj != null )
{
// Open the selected object for write
Entity entity = (Entity) tr.GetObject(SelObj.ObjectId, OpenMode.ForWrite);
if ( entity != null )
{
listOfEntities.Add(entity);
}
}
}
}
tr.Commit();
}
return listOfEntities;
}