Message 1 of 2
Create Beams from level
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone!
I'm working with this plugin and I have a problem: when I want to set the "Level 2" for some reason, this is not set in the beam.
If there is any solution I would appreciate it.
Regards.
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
var cadLinkInstances = new FilteredElementCollector(doc)
.OfClass(typeof(ImportInstance))
.Cast<ImportInstance>()
.ToList();
if (!cadLinkInstances.Any())
{
message = "No se encontró ningún archivo CAD cargado.";
return Result.Failed;
}
ImportInstance cadInstance = cadLinkInstances.First();
Options geometryOptions = new Options { DetailLevel = ViewDetailLevel.Fine };
GeometryElement geometryElement = cadInstance.get_Geometry(geometryOptions);
List<Line> cadLines = new List<Line>();
foreach (GeometryObject geometryObject in geometryElement)
{
if (geometryObject is GeometryInstance geometryInstance)
{
GeometryElement symbolGeometry = geometryInstance.GetInstanceGeometry();
foreach (GeometryObject geomObj in symbolGeometry)
{
if (geomObj is Line line)
{
cadLines.Add(line);
}
else if (geomObj is PolyLine polyline)
{
IList<XYZ> points = polyline.GetCoordinates();
for (int i = 0; i < points.Count - 1; i++)
{
Line segment = Line.CreateBound(points[i], points[i + 1]);
cadLines.Add(segment);
}
}
}
}
}
if (!cadLines.Any())
{
message = "No se encontraron líneas o polilíneas en el archivo CAD.";
return Result.Failed;
}
Level level = new FilteredElementCollector(doc)
.OfClass(typeof(Level))
.Cast<Level>()
.FirstOrDefault(l => l.Name == "Level 2");
if (level == null)
{
message = "No se encontró el nivel 'Level 2'.";
return Result.Failed;
}
using (Transaction trans = new Transaction(doc, "Crear vigas desde CAD"))
{
trans.Start();
FamilySymbol beamType = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.OfCategory(BuiltInCategory.OST_StructuralFraming)
.Cast<FamilySymbol>()
.FirstOrDefault(fs => fs.FamilyName == "VIGA Hº Aº");
if (beamType == null)
{
message = "No se encontró la familia 'VIGA Hº Aº'.";
return Result.Failed;
}
if (!beamType.IsActive)
{
beamType.Activate();
doc.Regenerate();
}
foreach (Line line in cadLines)
{
FamilyInstance beam = doc.Create.NewFamilyInstance(
line,
beamType,
level,
StructuralType.Beam);
LocationCurve locationCurve = beam.Location as LocationCurve;
if (locationCurve != null)
{
locationCurve.Curve = line;
}
}
trans.Commit();
}
return Result.Succeeded;
}
}
Developer Advocacy and Support +