Setting the default ID of a system text using API

Setting the default ID of a system text using API

Anonymous
Not applicable
1,060 Views
3 Replies
Message 1 of 4

Setting the default ID of a system text using API

Anonymous
Not applicable

Hi all,

 

I am a newbie in Revit API.

 

I am just wondering how to set the default ID for a system text families. I used the link below for the similar scenario but this can only access loadable families:

https://forums.autodesk.com/t5/revit-api-forum/set-default-family-type-id-for-my-room-tag/m-p/555547...

 

Here's the updated code that supposed to set the system text ID.

FilteredElementCollector collector = new FilteredElementCollector(doc);

collector = collector.OfClass(typeof(TextNote));

var query = from element in collector where element.Name == "Text-3.0mm-Dot-O" select element;

List<Element> famSyms = query.ToList<Element>();

ElementId symbolId = famSyms[0].Id;

FamilyInstanceFilter filter = new FamilyInstanceFilter(doc, symbolId);

collector = new FilteredElementCollector(doc);

ICollection<Element> familyInstances = collector.WherePasses(filter).ToElements();

ElementId txId = new ElementId(BuiltInCategory.OST_TextNotes);

doc.SetDefaultFamilyTypeId(txId, symbolId);

 

 

Any thoughts please.

 

Much appreciated,

Wil

 

0 Likes
Accepted solutions (1)
1,061 Views
3 Replies
Replies (3)
Message 2 of 4

JimJia
Alumni
Alumni
Accepted solution

Dear Wilfredo Mayo,

 

Yes, the Document.SetDefaultFamilyTypeId(...) requires one family type for second method parameter.

 

Note that your code below has some problem on family type retrieval:

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector = collector.OfClass(typeof(TextNote)); // This is instance, it's incorrect

 

The correct code should be:

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector = collector.OfClass(typeof(TextNoteType)); // family type is correct

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
Message 3 of 4

Anonymous
Not applicable

Many thanks Jim! Will try to amend the codes then see how it goes.

 

Much appreciated,

Wil

0 Likes
Message 4 of 4

Anonymous
Not applicable

Apologies for not coming back soon. This works a fortune! Thanks a lot Jim for your valuable time to help newbies like me...

0 Likes