Help Set Default TextNote (or TextNoteType) in Python

Hi is it possible to change or set default TextNoteType? I tried translating BuildingCoder snippet to Python but running into TypeErrors: Instance property must be acessed through a class instance and TypeError: cannot read…

  /// <summary>
  /// Return the first text note type matching the given name.
  /// Note that TextNoteType is a subclass of ElementType,
  /// so this method is more restrictive above all faster
  /// than Util.GetElementTypeByName.
  /// </summary>
  TextNoteType GetTextNoteTypeByName(
    Document doc,
    string name )
  {
    return new FilteredElementCollector( doc )
      .OfClass( typeof( TextNoteType ) )
      .First( q => q.Name.Equals( name ) )
        as TextNoteType;
  }

Any feedback is welcome, thank you
(I haven’t been able to find a similar post.)
@john_pierson
@GavinCrump

As far as I can see that code just attempts to get a text note by provided name. Can’t see any API implying a default text note type (it’s generally the last one you placed I think?).

My thinking is you could try placing one programatically then deleting it and see if that makes Revit focus on that text type when users next goes for it?

If you’re looking for the ‘original’ text note (unsure if this might be what you mean), generally the one with the lowest Id value would likely be it.

Thanks, that was my inquiry: set the default text type/style before placing.
From APIdocs: “The currently default style can be obtained from the Document.GetDefaultElementTypeId method.” I tested doc.SetDefaultElementTypeId but ran into some errors. I’ll test your suggestion, thanks again.

1 Like

It was in the options class SMH :angry:
Still a lot more to explore in that class but at least it works for now

tn_types = FilteredElementCollector(doc).OfClass(TextNoteType)

# Filter
pvp = ParameterValueProvider(ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME))
rule = FilterStringRule(pvp, FilterStringEquals(), "AMX - LA", False)
elem_filter = ElementParameterFilter(rule)
types_filtr = [e for e in tn_types if elem_filter.PassesFilter(e)]
textNoteType = types_filtr[0]
    
# Set text note id in text note creation 
TypeId = textNoteType.Id  

toptions = TextNoteOptions(TypeId)
 
text_note = TextNote.Create(doc, doc.ActiveView.Id, XYZ(0,0,0), "My text", toptions)
1 Like