接口IExtElemChangeBeamSection用于定义Revit中梁截面的更改。
bool ChangeBeamSection(FamilyInstance beamInstance, ElementId newSectionId);
beamInstance
:要更改截面的梁族实例。newSectionId
:新梁截面元素的ID,从ElementType或Type或族实例获取。bool类型的值,指示操作是否成功。
public void ChangeBeamSection(ElementId beamInstanceId, ElementId newSectionId)
{
Document doc = ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "Change Beam Section");
try
{
trans.Start();
Element beamInstance = doc.GetElement(beamInstanceId);
IExtensibleElement extBeamInstance = beamInstance as IExtensibleElement;
IExtensibleElementType extBeamType = beamInstance.Document.GetElement(beamInstance.GetTypeId()) as IExtensibleElementType;
Element newSectionElement = doc.GetElement(newSectionId);
if (extBeamInstance != null && extBeamType != null && newSectionElement is FamilySymbol)
{
IExtElemChangeBeamSection changeBeamSection = extBeamType.GetExtension<IExtElemChangeBeamSection>(extBeamInstance);
bool result = changeBeamSection.ChangeBeamSection(beamInstance as FamilyInstance, newSectionId);
if (result)
{
TaskDialog.Show("Success", "Successfully changed beam section.");
}
}
}
catch (Exception ex)
{
TaskDialog.Show("Error", ex.Message);
}
finally
{
trans.Commit();
}
}