Revit 2016 API Leader Attachment

Revit 2016 API Leader Attachment

Anonymous
Not applicable
2,212 Views
5 Replies
Message 1 of 6

Revit 2016 API Leader Attachment

Anonymous
Not applicable

I'm create a new note, and needing to add a leader to it. This is updating code from a 2015 plugin to 2016. Previously I was using (where 'note' is my TextNote.Create() object):

 

 // Set the left and right leader attachments to Top
note.get_Parameter("Left Attachment").Set(0);
note.get_Parameter("Right Attachment").Set(0);

That has become obsolete and using the new method, I'm currently using:

 

// Set the left and right leader attachments to Top
note.LeaderLeftAttachment.Equals("TopLine");
note.LeaderRightAttachment.Equals("TopLine");

I pulled the "TopLine" from Revit Snoop. However, this is not making it into my text note when created in Revit. It is Top for the Left Attachment, but Bottom for Right Attachment. Is there a best time to pass these values (currently I do it after the leader's been created and before the command completes)?

 

Thanks in advance for any help.

0 Likes
Accepted solutions (2)
2,213 Views
5 Replies
Replies (5)
Message 2 of 6

arnostlobel
Alumni
Alumni
crobertsnc:

my sincere advice to you so to do less snooping. I understand that the Snoop is a popular tool and is occasionally necessary too, but at many times it does not do any good to you and your application.

As you can find in the RevitAPI.CHM file, text note has three methods related to Leaders. They somehow mirror the UI commands in Revit:
- AddLeader
- GetLeaders
- RemoveLeaders

In your case you will probably be using:

Leader leftLeader = myNote.AddLeader(TextNoetLeaderTypes.TNT_STRAIGHT_L);
and
Leader rightLeader = myNote.AddLeader(TextNoetLeaderTypes.TNT_STRAIGHT_R);

The Add method returns you the newly created Leader object. You will notice, that just like in the UI, the above method add leaders with some default shape and position. However, you can use the returned leader object and using its method a properties adjust the appearance and position of each leader.

For example:

leftLeader.End = xyzPointSomewhereOnTheModel;

I hope that makes it clear.
Arnošt Löbel
0 Likes
Message 3 of 6

Anonymous
Not applicable

You're right, but I'm running a decision to only put the leader that I need based upon where it was drawn, see here:

 

UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Leader leader = null;

if (uiDoc.ActiveView.ViewType != ViewType.DraftingView && uiDoc.ActiveView.ViewType != ViewType.Legend)
{
Plane plane = commandData.Application.Application.Create.NewPlane(uiDoc.ActiveView.ViewDirection, uiDoc.ActiveView.Origin);
SketchPlane sketchPlane = SketchPlane.Create(uiDoc.Document, plane);
uiDoc.ActiveView.SketchPlane = sketchPlane;
}

try
{
// Prompt the user to select three points and store there values
startPoint = uiDoc.Selection.PickPoint(snapTypeNone, "Pick the start point of the leader.");
elbowPoint = uiDoc.Selection.PickPoint(snapTypeNone, "Pick the elbow point of the leader.");
endPoint = uiDoc.Selection.PickPoint(snapTypeNone, "Pick the text location.");
}

if (Math.Abs(uiDoc.ActiveView.RightDirection.X) == 1 && (startPoint.X * uiDoc.ActiveView.RightDirection.X) > (elbowPoint.X * uiDoc.ActiveView.RightDirection.X) || Math.Abs(uiDoc.ActiveView.RightDirection.Y) == 1 && (startPoint.Y * uiDoc.ActiveView.RightDirection.Y) > (elbowPoint.Y * uiDoc.ActiveView.RightDirection.Y))
{ leader = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); } else { leader = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_L); }

if (Math.Abs(uiDoc.ActiveView.RightDirection.X) == 1)
leader.Elbow = new XYZ(elbowPoint.X, leader.Elbow.Y, leader.Elbow.Z);
else if (Math.Abs(uiDoc.ActiveView.RightDirection.Y) == 1)
leader.Elbow = new XYZ(leader.Elbow.X, elbowPoint.Y, leader.Elbow.Z);
else
leader.Elbow = new XYZ(elbowPoint.X, elbowPoint.Y, leader.Elbow.Z);

So now the note has a leader using .AddLeader(). However, I don't want to change the endPoint as you showed as an example below. I want to change the Right Attachment property in the object. See the Screenshot I have attached - it shows that the Left Attachment is Top and the Right Attachment is Bottom. This is the default activity of a new leader on a note - I want to override that and make them both Top.


I can't seem to find anything useful beyond the "TopLine" I posted before, but that doesn't work.... Any additional ideas on how to make that work? Thank you for your help!!

0 Likes
Message 4 of 6

arnostlobel
Alumni
Alumni
Accepted solution

crobertsnc:

 

it is the TextNote class that has the LeaderLeftAttachement and LeaderRightAtachement properties you are looking for.

(With the updated API we tried to follow the UI features as closely as possible).

Arnošt Löbel
Message 5 of 6

Anonymous
Not applicable
Accepted solution

Oof. So all I ended up needing was a slight tweak to the original declarations and to use:

 

  // Set the left and right leader attachments to Top
      
            note.LeaderRightAttachment = LeaderAtachement.TopLine;
            note.LeaderLeftAttachment = LeaderAtachement.TopLine;

Thank you as always for your help - I've learned a lot on this seemingly simple project. Works now, as expected.

0 Likes
Message 6 of 6

BethEvanoo
Advocate
Advocate

What node goes into the LeaderAttachment input when you use this in Dynamo? It isn't working when I pull the leaders using a Rhythm node. 

BethEvanoo_0-1719929450706.png

 

0 Likes