PDA

View Full Version : Create New Annotation Symbol



jwells
2012-12-04, 02:35 AM
I'm working on a add-in to edit and insert annotation symbols. I can edit and delete annotation symbols easily enough, but I can't figure out how to insert a new one! I know the name of the family, and it has only one type. There's the NewAnnotationSymbol method, but I can't seem to get the annotationsymboltype from the name. I think I may have gotten around this by filtering the database for an element, and then working my way back up to the symbol. So I have three questions: 1) Is that the only way to get the annotation symbol type? 2) is the following line correct?

new_key=doc.Document.Create.NewAnnotationSymbol(point, ann_type, doc.ActiveView);

/* where the following were previously defined
Element new_key;
XYZ point;
AnnotationSymbolType ann_type */

and 3) Just before this line, I'm prompting for a point (doc.Selection.Pickpoint). I assume I have to close my form first. I'm doing something wrong there, because I tried to call the close() method but the form is still visible and it locks up everything.

Thank you for reading this, and I apologize if it seems incoherent. If I've left out a lot of necessary information, please let me know.

jwells
2012-12-04, 05:05 PM
Discovered part of the solution through trial and error. I needed to call the form.dispose() method instead of form.close() to pick my point.

ColinStark
2012-12-17, 09:16 PM
If I know the family/type name that I want to use, I use these methods to get a loaded family symbol. I'm assuming that you're using a Generic Annotation - you should change the category to whatever is appropriate in your situation. You could also remove the "OfCategory(cat)" filter from the getFamilySymbols method if you're not sure what category of annotation it is.




FamilySymbol symbol = Families.getFamilySymbol(doc, BuiltInCategory.OST_GenericAnnotation, "Family Name", "Type Name");

AnnotationSymbolType symType = symbol as AnnotationSymbolType;

AnnotationSymbol sym = createDoc.NewAnnotationSymbol(point, symType, doc.ActiveView);


The helper methods are below:


public static class Families
{

public static Dictionary<string,List<FamilySymbol>> getFamilySymbols(Document doc, BuiltInCategory cat)
{
Dictionary<string, List<FamilySymbol>> symbols = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.OfCategory(cat)
.Cast<FamilySymbol>()
.GroupBy(f => f.Family.Name)
.ToDictionary(f => f.Key, f => f.ToList());

return symbols;
}

public static FamilySymbol getFamilySymbol(Document doc, BuiltInCategory cat, string familyName, string symbolName)
{
Dictionary<string, List<FamilySymbol>> symbolDict = getFamilySymbols(doc, cat);

List<FamilySymbol> symbolList;

FamilySymbol familySymbol = null;

if (symbolDict.ContainsKey(familyName))
{
symbolList = symbolDict[familyName];

IEnumerable<FamilySymbol> foundSymbols = symbolList.Where(g => g.Name == symbolName);

if (foundSymbols.Count() > 0)
{
familySymbol = foundSymbols.First();
}
}

return familySymbol;
}
}
}


I haven't tested that on families that don't have any named types but it shouldn't be too hard to modify if you need that functionality.