Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello ,I have some leader with mtext. Mtext contain text with reinforcement bar data something like "2-T16+2-T20+4-T25" .
From this leader i want to create 3 separate leader with each leader containining only one bar data like leader 1 with 2-T16 text, leader 2 with 2-T20 text, , leader 3 with 4-T25 text.
I wrote some sample code to try to clone existing leader with text annotation but it's not valid input warning
here's my sample code
[CommandMethod("CloneLeaderWithMText")]
public void CloneLeaderWithMText()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Prompt for the leader to clone
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a leader to clone: ");
peo.SetRejectMessage("\nSelected entity is not a leader.");
peo.AddAllowedClass(typeof(Leader), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
Leader originalLeader = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Leader;
if (originalLeader == null)
return;
// Clone the leader
Leader clonedLeader = originalLeader.Clone() as Leader;
if (clonedLeader == null)
return;
// Add the cloned leader to the database
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(clonedLeader);
tr.AddNewlyCreatedDBObject(clonedLeader, true);
// Clone the associated MText
MText originalMText = tr.GetObject(originalLeader.Annotation, OpenMode.ForRead) as MText;
if (originalMText != null)
{
MText clonedMText = originalMText.Clone() as MText;
if (clonedMText != null)
{
btr.AppendEntity(clonedMText);
tr.AddNewlyCreatedDBObject(clonedMText, true);
// Associate the cloned MText with the cloned leader
clonedLeader.Annotation = clonedMText.ObjectId;
clonedLeader.TransformBy(Matrix3d.Displacement(new Vector3d(1000, 500, 0)));
clonedMText.TransformBy(Matrix3d.Displacement(new Vector3d(1000, 500, 0)));
}
}
tr.Commit();
}
}
Solved! Go to Solution.