Curve elements


#1

Hi guys, I don’t know where to ask for help but I really need your help :slight_smile:
I’m trying to create a new loft using some cross sections.
I can place the cross section (basically a generic 2D object) exactly on reference points and orient this in the right direction.
My problem now is to extract the geometries to be able to create the loft. The NewLoftForm expect as input a ReferenceArrayArray but I’m really struggling to get this result.
Here the code for my command

     namespace TestCurves
    {
        [Transaction(TransactionMode.Manual)]
        public class Command : IExternalCommand
        {
            public Result Execute(
              ExternalCommandData commandData,
              ref string message,
              ElementSet elements)
            {
                UIApplication uiapp = commandData.Application;
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Application app = uiapp.Application;
                Document doc = uidoc.Document;

            // Access current selection

            Selection sel = uidoc.Selection;
            Reference reference = sel.PickObject(ObjectType.Element);
            FamilyInstance fi = doc.GetElement(reference) as FamilyInstance;
            FamilySymbol fs = fi.Symbol;

            FilteredElementCollector refPoints = new FilteredElementCollector(doc).OfClass(typeof(ReferencePoint));

            // Retrieve elements from database

            using (Transaction tx = new Transaction(doc))
            {
                ReferenceArrayArray refArAr = new ReferenceArrayArray();
                tx.Start("Transaction Name");
                foreach (ReferencePoint rp in refPoints)
                {
                    if (rp.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM).AsValueString() == "Reference Points")
                    {
                        try
                        {
                            XYZ origin = new XYZ(rp.Position.X, rp.Position.Y, rp.Position.Z);
                            XYZ normal = rp.GetCoordinateSystem().BasisY;
                            SketchPlane sp = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(normal, origin));
                            FamilyInstance fInstance = doc.FamilyCreate.NewFamilyInstance(rp.GetCoordinatePlaneReferenceXZ(), origin, new XYZ(-1, 0, 0), fs);
                            refArAr.Append(GetObjects(doc, fi, sp));
                            //doc.FamilyCreate.NewLoftForm(true, refArAr);
                        }
                        catch { }
                    }
                }
                
                tx.Commit();
            }

            return Result.Succeeded;
        }

        public static ReferenceArray GetObjects(Document doc, FamilyInstance fi, SketchPlane sp)
        {
            ReferenceArray refAr = new ReferenceArray();

            GeometryElement ge = fi.get_Geometry(new Options { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = true });
            foreach (GeometryObject go in ge)
            {
                GeometryInstance gi = go as GeometryInstance;
                GeometryElement gEl = gi.GetInstanceGeometry();
                foreach (GeometryObject gObj in gEl)
                {
                    if (gObj.GetType() == typeof(Arc))
                    {
                        try
                        {
                            Arc crv = gObj as Arc;
                            ModelCurve mc = doc.FamilyCreate.NewModelCurve(crv, sp);
                            TaskDialog.Show("aaa", crv.ToString());
                        }
                        catch (Exception ex)
                        { TaskDialog.Show("Error", ex.Message); }
                    }
                }
            }

            return refAr;
         }


    }
}

this is the actual result in Revit


#2

I’ve moved the post to this other forum…
https://forums.autodesk.com/t5/revit-api-forum/new-loft-from-elements/m-p/7852151/highlight/false#M29474