Structural Section

By Augusto Goncalves

This sample was created by Andrzej Trelinski from Revit development team. Thanks!

It shows how add a structural section for a beam. The interesting point is about the FamilySymbol.HasStructuralSection method that, despite the name, return true if the symbol can contain a structural section.

Finally, only StructuralSectionPipeStandard and StructuralSectionRoundHSS can be instantiated via API. Below is a sample code.

 

UIApplication uiApp = commandData.Application;
Application app = uiApp.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;

var collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_StructuralFraming);

if (uiDoc.Selection.GetElementIds().Count < 1)
{
  TaskDialog.Show("Warning", "No element selected!"+
    " Select strutcural framing element, like eg. Beam");
  return Result.Cancelled;
}

using (Transaction tran = new Transaction(doc,
  "AddStructuralSection"))
{
  tran.Start();

  foreach (ElementId id in uiDoc.Selection.GetElementIds())
  {
    Element elem = doc.GetElement(id);
    if (!(elem is FamilyInstance))
    {
      TaskDialog.Show("Warning", string.Format(
        "Element ID='{0}’ is not FamilyInstance. "+
        "Only FamilyInstance elements can have StructuralSection",
        elem.Id.IntegerValue));
      return Result.Cancelled;
    }

    FamilyInstance famInst = elem as FamilyInstance;

    // HasStructuralSection() check if element
    // can have StructuralSection
    if (!famInst.Symbol.Family.HasStructuralSection()) 
    {
      TaskDialog.Show("Warning", string.Format(
        "Element ID='{0}’ can not have Structural section. "
        "Pick different family",
        elem.Id.IntegerValue));
      return Result.Cancelled;
    }

    {
      // create new Structural Section
      double diameter = 5.25;
      double sectionArea = 3.14159265358979 * diameter * diameter;
      double perimeter = 3.14159265358979 * diameter;
      double centroidHorizontal = 2.5;
      double centroidVertical = 1.5;
      double principalAxesAngle = 1.57;
      double elasticModulusStrongAxis = 10e7;
      double elasticModulusWeakAxis = 9e7;
      double momentOfInertiaStrongAxis = 100;
      double momentOfInertiaWeakAxis = 80;
      double nominalWeight = 1023;
      double plasticModulusStrongAxis = 120;
      double plasticModulusWeakAxis = 55;
      double shearAreaStrongAxis = 1;
      double shearAreaWeakAxis = 2;
      double torsionalModulus = 10;
      double torsionalMomentOfInertia = 15;
      double warpingConstant = 5;
      double wallDesignThickness = 1.2;
      double wallNominalThickness = 1.1978;

      StructuralSectionPipeStandard SSPipeStandard =
        new StructuralSectionPipeStandard(
          diameter, centroidHorizontal, 
          centroidVertical, principalAxesAngle, 
          wallNominalThickness, wallDesignThickness,
          sectionArea, perimeter, nominalWeight, 
          momentOfInertiaStrongAxis,
          momentOfInertiaWeakAxis, elasticModulusStrongAxis,
          elasticModulusWeakAxis, plasticModulusStrongAxis,
          plasticModulusWeakAxis, torsionalMomentOfInertia,
          torsionalModulus, warpingConstant,
  
        shearAreaStrongAxis, shearAreaWeakAxis);
      famInst.Symbol.SetStructuralSection(SSPipeStandard);
    }
  }

  if (tran.Commit() != TransactionStatus.Committed)
  {
    TaskDialog.Show("ERROR", "ERROR: Committing transaction failed");
    return Result.Failed;
  }
}

return Result.Succeeded;


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading