The is issue is while automation the letter inside the block gets rotated about 358 & 359 rotatio which makes the text inside the block little slantly tilted.
this is the output where the value for x is slantly tilted.if you see the rotation is 358
this is the template where the value is automated based on this . here the rotation is 0
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using ScalingTool.ACADCommunications;
using System.Collections.Generic;
namespace ScalingTool
{
internal class TextBlockCreate
{
public static string TextBlockCreation(string Text, double spacingFactor)
{
string strMainBlockName = string.Empty;
Dictionary<BlockReference, double> textalignBlkRef = new Dictionary<BlockReference, double>();
using (Transaction tr = ACADObject.WorkingDocument.Database.TransactionManager.StartTransaction())
{
BlockTable blockTable = tr.GetObject(ACADObject.WorkingDocument.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord blockTableRec = tr.GetObject(ACADObject.WorkingDocument.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
bool first = true;
foreach (char c in Text.ToCharArray())
{
string blockName = "f_romans_" + ((int)c).ToString();
BlockTableRecord blockTableRecord = tr.GetObject(blockTable[blockName], OpenMode.ForWrite) as BlockTableRecord;
if (blockTableRecord != null)
{
BlockReference blockReference = new BlockReference(new Point3d(0, 0, 0), blockTableRecord.ObjectId);
blockTableRec.AppendEntity(blockReference);
tr.AddNewlyCreatedDBObject(blockReference, true);
if (first)
textalignBlkRef.Add(blockReference, 0);
else
textalignBlkRef.Add(blockReference, spacingFactor);
first = false;
}
}
tr.Commit();
using (Transaction tran = ACADObject.WorkingDocument.Database.TransactionManager.StartTransaction())
{
strMainBlockName = Text + "_TextAlign";
BlockTableRecord newblocktablerecord = new BlockTableRecord();
newblocktablerecord.Name = strMainBlockName;
blockTable.Add(newblocktablerecord);
tran.AddNewlyCreatedDBObject(newblocktablerecord, true);
double width = 0;
double height = 0;
foreach (var a in textalignBlkRef)
{
Entity entity = tran.GetObject(a.Key.ObjectId, OpenMode.ForWrite) as Entity;
BlockReference block = entity as BlockReference;
Extents3d extents = block.GeometricExtents;
block.Position = new Point3d(block.Position.X - extents.MinPoint.X + width + a.Value, block.Position.Y - extents.MinPoint.Y, 0);
//if(block.Rotation>=358&& block.Rotation<=360)
//{
// block.Rotation = 0;
//}
extents = block.GeometricExtents;
width = extents.MaxPoint.X;
height = extents.MaxPoint.Y;
BlockReference blockReference = new BlockReference(block.Position, blockTable[block.Name]);
newblocktablerecord.AppendEntity(blockReference);
tran.AddNewlyCreatedDBObject(blockReference, true);
block.Erase();
}
newblocktablerecord.Origin = new Point3d(width / 2, height / 2, 0);
tran.Commit();
}
}
return strMainBlockName;
}
}
}