- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
this should be quite simple, but i can not find the way to add a Text for each selected Line, so that the Text gets aligned to the center of the line, even if the lines change in the Z axis
Until now i have this
public void PrintLinesLenght()
{
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ed.WriteMessage("Selecting Lines SPR... ");
//set the filter with two criteria: Line and LayerName
TypedValue[] typedValues = new TypedValue[2];
typedValues.SetValue(new TypedValue((int)DxfCode.Start, "LINE"), 0); //index 0 in array
typedValues.SetValue(new TypedValue((int)DxfCode.LayerName, "SPR"), 1); //index 1
//assign the filter criteria to a selection filter object
SelectionFilter filter = new SelectionFilter(typedValues);
//request for objects to be selected by the user
PromptSelectionResult psr;
psr = ed.GetSelection(filter);
ObjectId[] objectIds = null;
if (psr.Status == PromptStatus.OK)
{
SelectionSet selectionSet = psr.Value;
objectIds = selectionSet.GetObjectIds();
ed.WriteMessage("Numbers of Objects selected: " + objectIds.Length.ToString());
//AcAp.ShowAlertDialog("Number of objects selected: " + );
foreach (ObjectId objectId in objectIds)
{
Line line = trans.GetObject(objectId, OpenMode.ForRead, true) as Line;
string length = line.Length.ToString();
SetUcsBy2Points(line.StartPoint, line.EndPoint);
Vector3d vector = line.EndPoint - line.StartPoint;
Point3d midpoint = line.StartPoint + vector * 0.5;
CreateText(trans, midpoint, length + " mm.", 0.00);
ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
}
}
else
{
AcAp.ShowAlertDialog("Nothing was selected.");
}
trans.Commit();
}
}
catch (System.Exception ex)
{
AcAp.ShowAlertDialog("Error found: " + ex.Message + " Found in: " + ex.TargetSite.ToString());
}
}
private void SetUcsBy2Points(Point3d pt1, Point3d pt2)
{
Editor ed = doc.Editor;
Vector3d zAxis = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;
Vector3d xAxis = pt1.GetVectorTo(pt2).GetNormal();
Vector3d yAxis = zAxis.CrossProduct(xAxis).GetNormal();
Matrix3d mat = Matrix3d.AlignCoordinateSystem(
Point3d.Origin,
Vector3d.XAxis,
Vector3d.YAxis,
Vector3d.ZAxis,
pt1,
xAxis,
yAxis,
zAxis);
ed.CurrentUserCoordinateSystem = mat;
}
public void CreateText(Transaction tr, Point3d InsertionPoint, string txt, double ang)
{
Database db = doc.Database;
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (DBText mtx = new DBText())
{
mtx.TextString = txt;
mtx.Position = InsertionPoint;
mtx.Height = 10;
mtx.Rotation = ang;
btr.AppendEntity(mtx);
tr.AddNewlyCreatedDBObject(mtx, true);
}
}
So far I'm getting this Non Unitary UCS Y Axis; Normalizing Message
and the Text do not get aligned
I will honestly appreciate any help.
Thanks a lot
Solved! Go to Solution.
Link copied