- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on building a windows form add-in that will allow easier modification of a custom family we use instead of going into edit type every time.
I am starting with just trying to get a single parameter and populate that parameters value inside a text box. Once I get that working, the text box will be able to be edited to change the value of the type and apply it back to the type to update the model when the user clicks save at the bottom.
I am very new to coding and the API and seem to have hit a wall while trying to get the parameter and show it in the text box. I think I am successfully getting it, but cannot figure out how to show it correctly. It is currently just saying "Autodesk.Revit.DB.FamilyParameter" in the text box.
Here is an image of the form and the method I am using
private void comboBoxFamilyType_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxFamilyType.SelectedItem is FamilyType selectedFamilyType)
{
// Use a filtered element collector to find all instances of the selected family type
var collector = new FilteredElementCollector(_doc)
.OfClass(typeof(FamilyInstance))
.WhereElementIsNotElementType()
.Where(x => ((FamilyInstance)x).Symbol.Id == selectedFamilyType.Id);
// Debugging: Output the number of instances found
MessageBox.Show($"Number of instances found: {collector.Count()}");
// Try to get the first instance of this family type
var selectedInstance = collector.FirstOrDefault() as FamilyInstance;
if (selectedInstance != null)
{
// Debugging: Confirm the instance ID
MessageBox.Show($"Instance ID: {selectedInstance.Id.IntegerValue}");
Family family = selectedInstance.Symbol.Family;
Document familyDoc = _doc.EditFamily( family );
FamilyManager familyManager = familyDoc.FamilyManager;
FamilyParameter depthParam = familyManager.get_Parameter("DD_Depth");
if (depthParam != null)
{
textBoxDD_Depth.Text = depthParam.ToString();
// Debugging: Show the parameter's storage type and value
MessageBox.Show($"Parameter storage type: {depthParam.StorageType}");
}
else
{
textBoxDD_Depth.Text = "Parameter not found";
// Debugging: Parameter not found
MessageBox.Show("DD_Depth parameter not found.");
}
}
else
{
MessageBox.Show("No instances found for the selected family type.");
}
}
}
Solved! Go to Solution.