How can I use the API to create a new KeynoteTag hosted to a Line Based Detail Component in a DraftingView?
Now, keep in mind that I'm new to Revit API and C#, so my questions will be pretty basic. My past experience is with Visual Basic. but I'm looking to improve my skills in C# and a better understanding of C#. My best learning method is to see sample codes. Thanks for all your help!!
Here's my current code to add the IndependentTag to the Element:
Element FindLine(Document doc)
{
FilteredElementCollector collector
= new FilteredElementCollector(doc, doc.ActiveView.Id);
foreach (Element e in collector)
{
if( e.Name.Equals("Line"))
{
return e;
}
}
return null;
}
Element elemLine = FindLine(doc);
LocationCurve elc = elemLine.Location as LocationCurve;
Line elLine = elc.Curve as Line;
XYZ p = elLine.get_EndPoint(0);
FamilySymbol KeynoteTagType = GetFirstFamilySymbol(doc, BuiltInCategory.OST_KeynoteTags);
IndependentTag newTag = createDoc.NewTag(view, elemLine, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, p);
I'm know this code would just tag the detail line, and I'm pretty sure the issue is the XYZ.
What's the problem then?
Probably forgot to use the transaction, so it failed to create the tag.
If this cannot help, Please give detailed information abou the problem.
I was using the transaction but at the begining of the routine, because I wanted 1 undo for the entire routine, not for each keynote I was adding. I learned after playing with it more that my XYZ coordinate was coorect, but that the API won't allow you to add keynotes, unless you have sample code or documentation to support otherwise.
Thanks.
Thanks for your update. Even via the Revit UI command, we cannot create tag for the detail line. I think this is the cause that you cannot create a tag for the detail line in the drafting view.
You seem to have trouble understanding what I'm talking about. You're first solution suggests that it IS possible to create the keynote tag via the API, but after my next post where I asked you to provide some sample code or documentation showing it's possible, you respond with "Thanks for your update. Even via the Revit UI command, we cannot create tag for the detail line. I think this is the cause that you cannot create a tag for the detail line in the drafting view. " Even though my first post clearly states "Line Based Detail Component", NOT a detail line.
Since you seem to think it might be possible to use the Revit API to generate a keynote tag for a Line Based Detail Component I'd love to see some sample code or documentation to support that.
HI atiefenbach,
Sorry for the confusion. When I replied your firstly, I didn't write code to test if tags can be created for Line Based Detail Component . There is no full code. So I just provide the possible reason.
Via the Revit UI command, tags cannot be created for Line Based Detail Component either. Normally If UI commands cannot achieve a functionality, neither do the correspondant Revit API.
Joe,
Unfortunately, you are wrong about not being able to keynote a "Line Based Detail Component" via the UI. I think your confused about what a "Line Based Detail Component" is. Maybe you're still thinking of a "Detail Line" or a "Repeating Detail Component"?
And example of a Line Based Detail Component would be the Gypsum Wallboard family that comes with Revit.
Hi atiefenbach,
Sorry for keeping misunderstanding. As you said, i was thinking the "Repeating Detail Component".
We can use Revit API to create a non-keynote tag for line based component as the UI does. (for example, the category tag, and material tag)
However there is no available API to change the tag type to Keynote tag type.