- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The idea is to open a "roomtag family", change the "lable texts" parameter "Textsize" and reload the "roomtag family" into an active Revit project all automatically.
The problem I am facing is that I cant access the "lable text family" wich is inside the "roomtag family".
What already works:
1.) Get the "roomtag family"
2.) Open the "roomtag family" document
3.) Get the all parameters from the "roomtag family" (only to test and see what the result is)
6.) Load the "roomtag family" back into the active Revit project
7.) Closing the "roomtag family" document
What does not work:
4.) Get the "lable text family" that is inside the "roomtag family"
5.) Change the parameter value of "Textsize" parameter
Here you can see screenshots to better understand what I am trying to do:
I am using the Revit sample project file: "rac_basic_sample_project.rvt"
Here is the link:
https://help.autodesk.com/view/RVT/2023/ENU/?guid=GUID-61EF2F22-3A1F-4317-B925-1E85F138BE88
Navigate to the "Level 1" floor plan. Now you can see the "room tag" instance shown in the screenshot.
Here you see that I was able to get the "roomtag family parameters" from steps 1-3 described above
Now click "Edit Family" and select a lable text.In the screenshot I highlighted the parameter i need to get to:
Now for steps 4-5 I have tried to apply a filter to get the "textlable family", I have also already tried to get the specific element with its id, I have tried to open another familydoc inside the already opened familydoc. As well as have tried multiple other things that did not work, even ChatGPT was not helpful.
This is the full code:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get the UIApplication object
UIApplication uiApp = commandData.Application;
// Get the current document
Document doc = uiApp.ActiveUIDocument.Document;
string familyName = "M_Room Tag";
double textSize = 10;
string typeName = "M_Room Tag_10";
// 1.) Get the roomtag family
// Create a new FilteredElementCollector for the current document
FilteredElementCollector collector = new FilteredElementCollector(doc);
// Filter the elements in the collector to get only Family elements
ICollection<Element> families = collector.OfClass(typeof(Family)).ToElements();
// Declare a variable to store the found family
Family family = null;
family = families.OfType<Family>().FirstOrDefault(fam => fam.Name == familyName);
// 2.) Open the roomtag family document
Document familyDoc = doc.EditFamily(family);
FamilyManager mgr = familyDoc.FamilyManager;
FamilyType familyType;
using (Transaction trans = new Transaction(familyDoc, "Create New Type"))
{
trans.Start();
// x.) Create a new family type
// familyType = mgr.NewType(typeName);
// 3.) Get the all parameters from roomtag family (only to test and see what the result is)
IList <FamilyParameter> familyParameters = mgr.GetParameters();
string printRoomTagParameters = "";
foreach(FamilyParameter familyParameter in familyParameters)
{
printRoomTagParameters += familyParameter.Definition.Name.ToString() + "\n";
}
TaskDialog.Show("parametersPrint", printRoomTagParameters);
// 4.) Get the lable text somehow
ElementCategoryFilter filterRT = new ElementCategoryFilter(BuiltInCategory.OST_RoomTags);
FilteredElementCollector collectorRT = new FilteredElementCollector(familyDoc);
var roomTags = collectorRT.WherePasses(filterRT).WhereElementIsNotElementType().ToElements();
string roomTagss = "";
foreach (var roomTag in roomTags)
{
roomTagss += roomTag.Name.ToString() + "\n";
}
TaskDialog.Show("roomTagss", roomTagss);
// 5.) Change the parameter value of "Textsize" parameter
trans.Commit();
}
// 6.) Load the roomtag family back into the active revit project
familyDoc.LoadFamily(doc, new FamilyLoadOptions());
// 7.) Finally, closing the document (False = without saving)
familyDoc.Close(false);
return Result.Succeeded;
}
Result of step 4.)
I have already looked at the following links:
https://www.revitapidocs.com/2016/56e636ee-5008-0ee5-9d6c-5f622dedfbcb.htm
https://thebuildingcoder.typepad.com/blog/2009/11/family-parameter-value.html
https://www.revitapidocs.com/2018/7fc40346-6188-66ff-4c00-bd4360e70c6f.htm
https://www.revitapidocs.com/2018/86e30f63-4894-aed9-c6df-0074cdfa89a7.htm
I know that I could just create a new "roomtag family type" with the desired textsize, but we want to develop a more automated/easier way to create famiy types as well as perform different actions on it such as changing the text size.
It would be great if someone has a solution or can point me in the right direction. I am also wondering if this is even possible?
Solved! Go to Solution.