PDA

View Full Version : 2014 Working with Text Leaders....



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();
}
}

floris
2014-10-14, 10:01 AM
The reason why macro failed is simple. When you add a curved leader on a text manually, the Arc leader parameter in the panel "propriety" is checked , and if you delete curved leader, the parameter is always checked.
If you want fix that, you can change this parameter to "false" before add straight leader.
for exemple, you can add this code :
Parameter arc_leader = selected.get_Parameter(BuiltInParameter.ARC_LEADER_PARAM);
arc_leader.Set(0);

After t.Start();

this piece of code uncheck the text note before add straight leader.