Message 1 of 6
Get Solid Geometry From Rebar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
i want to get rebar geometry as solid. as below code i get the rebar diameter & rebar centerlines. then i want use below method.
public static Solid CreateSweptGeometry(
CurveLoop sweepPath,
int pathAttachmentCrvIdx,
double pathAttachmentParam,
IList<CurveLoop> profileLoops,
SolidOptions solidOptions
)
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
// Step 1: Retrieve assemblies in the project and select one
List<AssemblyInstance> assemblies = new FilteredElementCollector(doc)
.OfClass(typeof(AssemblyInstance))
.Cast<AssemblyInstance>()
.ToList();
AssemblySelector assemblySelector = new AssemblySelector(assemblies);
bool? dialogResult = assemblySelector.ShowDialog();
if (dialogResult != true || assemblySelector.SelectedAssembly == null)
{
return Result.Cancelled;
}
AssemblyInstance selectedAssembly = assemblySelector.SelectedAssembly;
// Step 2: Retrieve all structural rebars in the selected assembly
ICollection<ElementId> memberIds = selectedAssembly.GetMemberIds();
List<Rebar> rebars = new List<Rebar>();
foreach (ElementId memberId in memberIds)
{
Element member = doc.GetElement(memberId);
if (member is Rebar rebar)
{
rebars.Add(rebar);
}
}
if (rebars.Count == 0)
{
TaskDialog.Show("Rebar Clash", "No rebars found in the selected assembly.");
return Result.Cancelled;
}
// Step 3: Collect rebar diameter and centerline curves
StringBuilder messageBuilder = new StringBuilder();
foreach (Rebar rebar in rebars)
{
// Get the rebar's bar diameter (radius = diameter / 2)
double diameter = rebar.get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER).AsDouble();
double radius = diameter / 2;
// Get the rebar's centerline curves
IList<Curve> centerlineCurves = rebar.GetCenterlineCurves(
adjustForSelfIntersection: true,
suppressHooks: false,
suppressBendRadius: false,
MultiplanarOption.IncludeAllMultiplanarCurves,
0);
// Build the message for this rebar
messageBuilder.AppendLine($"Rebar Id: {rebar.Id.IntegerValue}");
messageBuilder.AppendLine($"Diameter: {diameter} (feet)");
messageBuilder.AppendLine("Centerline Curves:");
foreach (Curve curve in centerlineCurves)
{
messageBuilder.AppendLine($"- Curve: Start: {curve.GetEndPoint(0)}, End: {curve.GetEndPoint(1)}");
}
messageBuilder.AppendLine(); // Add an empty line between rebars
}
// Show the message box with the rebar information
TaskDialog.Show("Rebar Info", messageBuilder.ToString());
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
i don't know what the process of next. please guide me.
Thanks in Advanced