Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3D Sweep

1 REPLY 1
Reply
Message 1 of 2
Moustafa_K
455 Views, 1 Reply

3D Sweep

Hi Again!!

I really don't know why i can't create a 3d Sweep with a pick edge from geometry in a family Document. it keeps saying the reference is "Null" although i specified in the options to compute reference.

 

See this code:

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            IList<Reference> refs = null;
            refs = uidoc.Selection.PickObjects(ObjectType.Edge);

            ReferenceArray rArr = new ReferenceArray();


            foreach (Reference r in refs)
            {
 Element e = doc.GetElement(r.ElementId);

                Options op = new Options();
                op.ComputeReferences = true;
                
                GeometryElement ge = e.get_Geometry(op);

                foreach (GeometryObject Gobj in ge)
                {
                    Solid solid = Gobj as Solid;
                    foreach (Edge edg in solid.Edges)
                    {
                        rArr.Append(edg.AsCurveFollowingFace(edg.GetFace(1)).Reference);
                    }
                }
            }

            Transaction t = new Transaction(doc, "Create Sweep2d");
            t.Start();
         
            FamilyItemFactory factory = doc.FamilyCreate;
           
            IList<Curve> cel = new List<Curve>();

            for (int i = 0; i < _profilepoints.Count; i = i + 2)
            {
                try
                {
                    cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[i + 1]) as Curve);

                }
                catch (Exception)
                {

                    cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[0]) as Curve);

                }

            }

            CurveArray sweepArray = DrawLoops.convert2loop(cel);

            CurveArrArray swerarar = new CurveArrArray();
            swerarar.Append(sweepArray);

            SweepProfile swpprof = doc.Application.Create.NewCurveLoopsProfile(swerarar);       // this is the profile

           
          
            Sweep sweep3D = factory.NewSweep(true, rArr, swpprof, 0, ProfilePlaneLocation.Start);
           
          

            t.Commit();

            return Result.Succeeded;

        }

 

 

may i have any explaination ???


-----------------------------------------------------
Moustafa Khalil
Tags (2)
1 REPLY 1
Message 2 of 2
Moustafa_K
in reply to: Moustafa_K

Very Strange, it worked Only if i redraw that edge as Model Curve through picking the edge references and sketchplan, and perform ModelCurve and then use these model Curves as Reference for the 3dSweep

this is the modification i implemented... it still not 100% answered my question but i 'd like any one would explain me... the week point of this method that the model curve will still exist as an extra element which will require you to delete it only if you don't care about the reference any more...

 

 

if (edg.Reference.ConvertToStableRepresentation(m_doc) == r.ConvertToStableRepresentation(m_doc))
{
 
SketchPlane plan = SketchPlane.Create(m_doc, edg.GetFace(1).Reference);
ModelCurve mc = m_doc.FamilyCreate.NewModelCurve(edg.AsCurve(), plan);
rArr.Append(mc.GeometryCurve.Reference);

}

 


-----------------------------------------------------
Moustafa Khalil

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community