scowsert
2014-09-17, 10:05 PM
I run this code through the macro interface.
If I take a piece of text add a curved leader, then remove it (so its blank), then run my code it fails.
If I take a piece of text add a straight leader, then remove it (so its blank), then run my code it works.
It looks to me like leaderless text will only except whatever leader type it was using previously. How can I can force it to work? I've got other code to remove leaders but run into this same issue.
Thanks Sage
===============
Code below.
public void AddStraightLeader()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = new UIDocument(doc);
TextNote selected = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select text to add leader.")) as TextNote;
XYZ leaderOrigin = uidoc.Selection.PickPoint("Pick Leader End");
using (Transaction t = new Transaction(doc,"Change dimension style to default"))
{
t.Start();
Leader noteLeader = selected.AddLeader(
TextNoteLeaderTypes.TNLT_STRAIGHT_R);
// Use default Y!
noteLeader.Elbow = new XYZ( leaderOrigin.X,
noteLeader.Elbow.Y, leaderOrigin.Z );
noteLeader.End = leaderOrigin;
t.Commit();
}
}
If I take a piece of text add a curved leader, then remove it (so its blank), then run my code it fails.
If I take a piece of text add a straight leader, then remove it (so its blank), then run my code it works.
It looks to me like leaderless text will only except whatever leader type it was using previously. How can I can force it to work? I've got other code to remove leaders but run into this same issue.
Thanks Sage
===============
Code below.
public void AddStraightLeader()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = new UIDocument(doc);
TextNote selected = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select text to add leader.")) as TextNote;
XYZ leaderOrigin = uidoc.Selection.PickPoint("Pick Leader End");
using (Transaction t = new Transaction(doc,"Change dimension style to default"))
{
t.Start();
Leader noteLeader = selected.AddLeader(
TextNoteLeaderTypes.TNLT_STRAIGHT_R);
// Use default Y!
noteLeader.Elbow = new XYZ( leaderOrigin.X,
noteLeader.Elbow.Y, leaderOrigin.Z );
noteLeader.End = leaderOrigin;
t.Commit();
}
}