So I want to change the family and type of an elbow. Here is how I started:
//changeTypeTo is the name of the new family I want to change to.
//This is where I find an existing element that matches the family and type that I want to change all the old elbow family and types to
FamilyInstance m_ElementType = null;
FilteredElementCollector collector = new FilteredElementCollector(GlobalData.doc);
collector
.OfClass(typeof(FamilyInstance));
var ElbowTypes = from fsymbol in collector
where fsymbol.Name == changeTypeTo
select fsymbol;
if (ElbowTypes != null)
{
//m_ElementType = ElbowTypes.Cast<FamilyInstance>().ElementAt<FamilyInstance>(0);
foreach (FamilyInstance element in ElbowTypes)
{
if (element.Symbol.Family.Name.ToString() == cmbNewFamilies.SelectedItem.ToString())
{
m_ElementType = element;
break; //I am only looking for one element that currently exists in the model right now that I want to change
} //all the old elbow values to.
}
//Here is where I actually change the old element to the new element
//oldlist contains every Id of every elbow that I would like to change
if (m_ElementType != null)
{
// Change the elbow to the cached elbow type.
foreach (ElementId addedElemId in oldlist)
{
try
{
elbow = GlobalData.doc.GetElement(addedElemId) as FamilyInstance; //get instance of family
// Get Family document for family
if (elbow != null)
{
elbow.Symbol = m_ElementType.Symbol;
successCheck = 1;
TaskDialog.Show("New Element", "It's now a " + elbow.Symbol.Family.Name.ToString() + "\n\n" +elbow.Name.ToString() + "\n\n" + elbow.Id.ToString());
}
else
{
TaskDialog.Show("ERROR", "Elbow is empty");
successCheck = 0;
}
}
catch
{
TaskDialog.Show("ERROR", "Exception found at Id: " + addedElemId.ToString());
successCheck = 0;
return Result.Cancelled;
}
}
}
My final issue here is that I get thrown into my catch statement. Something goes wrong during "try". Is there a better way to do what I am trying to achieve. I know for sure that the existing element containing the family and type that I want to change to exist and that it is set to m_element_type. I have checked this and pushed it to a dialog box to make sure I was getting a value. Maybe I should not be trying to change the value by finding an existing elbow that I want all the others to be like.
If this is not enough information or anyone has questions, let me know. I would love to get this cleared up as best I can. All help will be appreciated. Thanks.
If there is a way to do this without having to have an element of the family and type I desire, that would be the prefered method of solving this issue. I had trouble just trying to do this with any other method.