Ejemplo n.º 1
0
        /// <summary>
        /// Create a loft form
        /// </summary>
        /// <returns>Created loft form</returns>
        private Form CreateLoft()
        {
            // Prepare profiles for loft creation
            ReferenceArrayArray profiles      = new ReferenceArrayArray();
            ReferenceArray      bottomProfile = new ReferenceArray();

            bottomProfile = CreateProfile(m_bottomLength, m_bottomWidth, m_bottomHeight);
            profiles.Append(bottomProfile);
            ReferenceArray topProfile = new ReferenceArray();

            topProfile = CreateProfile(m_topLength, m_topWidth, m_topHeight);
            profiles.Append(topProfile);

            // return the created loft form
            return(m_revitDoc.FamilyCreate.NewLoftForm(true, profiles));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            ExternalCommandData cdata = commandData;

            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Document            doc     = commandData.Application.ActiveUIDocument.Document;
            XYZ                 xyz     = new XYZ();
            ReferenceArrayArray refArAr = new ReferenceArrayArray();
            int                 x       = 0;
            double              z       = 0;

            while (x < 800)
            {
                ReferencePointArray rpAr = new ReferencePointArray();
                int y = 0;
                while (y < 800)
                {
                    z   = 50 * (Math.Cos((Math.PI / 180) * x) + Math.Cos((Math.PI / 180) * y));
                    xyz = app.Create.NewXYZ(x, y, z);
                    ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
                    rpAr.Append(rp);
                    y = y + 40;
                }
                CurveByPoints  curve = doc.FamilyCreate.NewCurveByPoints(rpAr);
                ReferenceArray refAr = new ReferenceArray();
                refAr.Append(curve.GeometryCurve.Reference);
                refArAr.Append(refAr);
                x = x + 40;
            }
            Form form = doc.FamilyCreate.NewLoftForm(true, refArAr);

            return(Result.Succeeded);
        }
Ejemplo n.º 3
0
        private static Form ByLoftCrossSectionsInternal(object[] curves, bool isSolid = true)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            // if the arguments are polycurves, explode them
            if (curves.Any(x => x is PolyCurve))
            {
                var ca = curves.Select(x => x is PolyCurve ? ((PolyCurve)x).Curves() : new[] { x }).ToArray();
                return(ByLoftMultiPartCrossSectionsInternal(ca, isSolid));
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curves)
            {
                if (l == null)
                {
                    throw new ArgumentNullException("curves");
                }
                var refArr = new ReferenceArray();

                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Ejemplo n.º 4
0
        private void SetConstraints(Document familyDoc, Extrusion extrusion)
        {
            try
            {
                CurveArrArray curvesArr = new CurveArrArray();
                curvesArr = extrusion.Sketch.Profile;

                foreach (CurveArray ca in curvesArr)
                {
                    CurveArrayIterator itor = ca.ForwardIterator();
                    itor.Reset();
                    itor.MoveNext();
                    Line l = itor.Current as Line;
                    _rightCon.Append(l.Reference);
                    itor.MoveNext();
                    l = itor.Current as Line;
                    _topCon.Append(l.Reference);
                    itor.MoveNext();
                    l = itor.Current as Line;
                    _leftCon.Append(l.Reference);
                    l = itor.Current as Line;
                    _botCon.Append(l.Reference);
                }
                ReferenceArrayArray conArray = new ReferenceArrayArray();

                conArray.Append(_rightCon);
                conArray.Append(_topCon);
                conArray.Append(_leftCon);
                conArray.Append(_botCon);

                ConstructConstraint(familyDoc, _rightCon);
                ConstructConstraint(familyDoc, _topCon);
                ConstructConstraint(familyDoc, _leftCon);
            }

            catch (Exception ex)
            {
                TaskDialog.Show("Constraint Error", ex.Message);
            }
        }
Ejemplo n.º 5
0
        public static Form ByLoftingCurveReferences(object[][] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curveReferences)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Ejemplo n.º 6
0
        private void SetConstraints(Document familyDoc, Extrusion extrusion)
        {
            CurveArrArray curvesArr = new CurveArrArray();

            curvesArr = extrusion.Sketch.Profile;

            foreach (CurveArray ca in curvesArr)
            {
                CurveArrayIterator itor = ca.ForwardIterator();
                itor.Reset();
                itor.MoveNext();
                Line l = itor.Current as Line;
                _rightCon.Append(l.Reference);
                itor.MoveNext();
                l = itor.Current as Line;
                _topCon.Append(l.Reference);
                itor.MoveNext();
                l = itor.Current as Line;
                _leftCon.Append(l.Reference);
                l = itor.Current as Line;
                _botCon.Append(l.Reference);
            }
            ReferenceArrayArray conArray = new ReferenceArrayArray();

            conArray.Append(_rightCon);
            conArray.Append(_topCon);
            conArray.Append(_leftCon);
            conArray.Append(_botCon);

            //Line line = familyDoc.Application.Create.NewLine(_vert[0], _vert[1], true);
            ConstructConstraint(familyDoc, _rightCon);
            //line = familyDoc.Application.Create.NewLine(_vert[1], _vert[2], true);
            ConstructConstraint(familyDoc, _topCon);
            //line = familyDoc.Application.Create.NewLine(_vert[2], _vert[3], true);
            ConstructConstraint(familyDoc, _leftCon);
            //line = familyDoc.Application.Create.NewLine(_vert[3], _vert[0], true);
            //ConstructConstraint(familyDoc, _botCon, line);
        }
Ejemplo n.º 7
0
        private static ReferenceArrayArray ConvertFSharpListListToReferenceArrayArray(FSharpList <Value> lstlst)
        {
            ReferenceArrayArray refArrArr = new ReferenceArrayArray();

            foreach (Value v in lstlst)
            {
                ReferenceArray     refArr = new ReferenceArray();
                FSharpList <Value> lst    = (v as Value.List).Item;

                AddReferencesToArray(refArr, lst);

                refArrArr.Append(refArr);
            }

            return(refArrArr);
        }
Ejemplo n.º 8
0
        public static Form ByLoftingCurveReferences(object[] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curveReferences)
            {
                if (l == null)
                {
                    throw new ArgumentNullException("curveReferences");
                }
                var refArr = new ReferenceArray();
                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Ejemplo n.º 9
0
        private string CreateMassFamily(string famPath, Geometry.Surface surface, string name)
        {
            var famDoc = Doc.Application.NewFamilyDocument(famPath);

            using (Transaction t = new Transaction(famDoc, "Create Mass"))
            {
                t.Start();

                try
                {
                    var pointLists = surface.GetControlPoints();
                    var curveArray = new ReferenceArrayArray();

                    foreach (var list in pointLists)
                    {
                        var arr = new ReferencePointArray();
                        foreach (var point in list)
                        {
                            var refPt = famDoc.FamilyCreate.NewReferencePoint(PointToNative(point));
                            arr.Append(refPt);
                        }

                        var curve          = famDoc.FamilyCreate.NewCurveByPoints(arr);
                        var referenceArray = new ReferenceArray();
                        referenceArray.Append(curve.GeometryCurve.Reference);
                        curveArray.Append(referenceArray);
                    }

                    var loft = famDoc.FamilyCreate.NewLoftForm(true, curveArray);
                }
                catch (Exception e)
                {
                }

                t.Commit();
            }
            var           famName        = "SpeckleMass_" + name;
            string        tempFamilyPath = Path.Combine(Path.GetTempPath(), famName + ".rfa");
            SaveAsOptions so             = new SaveAsOptions();

            so.OverwriteExistingFile = true;
            famDoc.SaveAs(tempFamilyPath, so);
            famDoc.Close();

            return(tempFamilyPath);
        }
Ejemplo n.º 10
0
        public Element SurfaceGrid(XYZ[] linearizedMatrix, int n, int m)
        {
            ReferenceArrayArray refarar = new ReferenceArrayArray();

            for (int i = 0; i < n; i++)
            {
                ReferencePointArray rpa = new ReferencePointArray();
                for (int j = 0; j < m; j++)
                {
                    XYZ p = linearizedMatrix[i * m + j];
                    rpa.Append(doc.FamilyCreate.NewReferencePoint(p));
                }
                ReferenceArray arr = new ReferenceArray();
                arr.Append(doc.FamilyCreate.NewCurveByPoints(rpa).GeometryCurve.Reference);
                refarar.Append(arr);
            }
            return(doc.FamilyCreate.NewLoftForm(true, refarar));
        }
Ejemplo n.º 11
0
        private static Form ByLoftMultiPartCrossSectionsInternal(object[][] curves, bool isSolid = true)
        {
            if (curves == null || curves.SelectMany(x => x).Any(x => x == null))
            {
                throw new ArgumentNullException("Some of the input curves are null.");
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Ejemplo n.º 12
0
        public static Form ByLoftCrossSections(object[][] curves, bool isSolid = true)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Ejemplo n.º 13
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            List <Rhino.Geometry.Curve> profiles
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    if (!Revit.ActiveDBDocument.IsFamilyDocument || !Revit.ActiveDBDocument.OwnerFamily.IsConceptualMassFamily)
                    {
                        throw new Exception("This component can only run in Conceptual Mass Family editor");
                    }

                    if (profiles == null || profiles?.Count == 0)
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be valid curve list.", Params.Input[0].Name));
                    }

                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    var planes      = new List <Rhino.Geometry.Plane>();
                    foreach (var profile in profiles)
                    {
                        if (scaleFactor != 1.0)
                        {
                            profile.Scale(scaleFactor);
                        }

                        if (!profile.TryGetPlane(out var plane))
                        {
                            continue;
                        }

                        plane.Origin = profile.IsClosed ? Rhino.Geometry.AreaMassProperties.Compute(profile).Centroid : profile.PointAt(profile.Domain.Mid);
                        planes.Add(plane);
                    }

                    if (profiles.Count != planes.Count)
                    {
                        throw new Exception(string.Format("All curves in '{0}' must be planar.", Params.Input[0].Name));
                    }

                    if (profiles.Count == 1)
                    {
                        var profile = profiles[0];
                        var plane   = planes[0];

                        var sketchPlane = SketchPlane.Create(doc, plane.ToHost());

                        var referenceArray = new ReferenceArray();
                        foreach (var curve in profile.ToHost())
                        {
                            referenceArray.Append(new Reference(doc.FamilyCreate.NewModelCurve(curve, sketchPlane)));
                        }

                        element = CopyParametersFrom(doc.FamilyCreate.NewFormByCap(true, referenceArray), element);
                    }
                    else
                    {
                        var referenceArrayArray = new ReferenceArrayArray();
                        int index = 0;
                        foreach (var profile in profiles)
                        {
                            var sketchPlane = SketchPlane.Create(doc, planes[index++].ToHost());

                            var referenceArray = new ReferenceArray();
                            foreach (var curve in profile.ToHost())
                            {
                                referenceArray.Append(new Reference(doc.FamilyCreate.NewModelCurve(curve, sketchPlane)));
                            }

                            referenceArrayArray.Append(referenceArray);
                        }

                        element = CopyParametersFrom(doc.FamilyCreate.NewLoftForm(true, referenceArrayArray), element);
                    }

                    ReplaceElement(doc, DA, Iteration, element);
                }
                catch (Exception e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                    ReplaceElement(doc, DA, Iteration, null);
                }
            }
        }
Ejemplo n.º 14
0
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            //Solid argument
            bool isSolid = ((FScheme.Value.Number)args[0]).Item == 1;

            //Surface argument
            bool isSurface = ((FScheme.Value.Number)args[2]).Item == 1;

            //Build up our list of list of references for the form by...
            var curvesListList = (FScheme.Value.List)args[1];
            //Now we add all of those references into ReferenceArrays
            ReferenceArrayArray refArrArr = new ReferenceArrayArray();

            FSharpList<FScheme.Value> vals = ((FScheme.Value.List)curvesListList).Item;

            if (vals.Any() && (vals[0] is FScheme.Value.Container) && ((FScheme.Value.Container)vals[0]).Item is ModelCurveArray)
            {
                //Build a sequence that unwraps the input list from it's Value form.
                IEnumerable<ModelCurveArray> modelCurveArrays = ((FScheme.Value.List)args[1]).Item.Select(
                   x => (ModelCurveArray)((FScheme.Value.Container)x).Item
                );

                foreach (var modelCurveArray in modelCurveArrays)
                {
                    var refArr = new ReferenceArray();
                    foreach (Autodesk.Revit.DB.ModelCurve modelCurve in modelCurveArray)
                    {
                        refArr.Append(modelCurve.GeometryCurve.Reference);
                    }
                    refArrArr.Append(refArr);
                }
            }
            else
            {
                IEnumerable<IEnumerable<Reference>> refArrays = (curvesListList).Item.Select(
                    //...first selecting everything in the topmost list...
                   delegate(FScheme.Value x)
                   {
                       //If the element in the topmost list is a sub-list...
                       if (x.IsList)
                       {
                           //...then we return a new IEnumerable of References by converting the sub list.
                           return (x as FScheme.Value.List).Item.Select(
                              delegate(FScheme.Value y)
                              {
                                  //Since we're in a sub-list, we can assume it's a container.
                                  var item = ((FScheme.Value.Container)y).Item;
                                  if (item is CurveElement)
                                      return (item as CurveElement).GeometryCurve.Reference;
                                  else
                                      return (Reference)item;
                              }
                           );
                       }
                       //If the element is not a sub-list, then just assume it's a container.
                       else
                       {
                           var obj = ((FScheme.Value.Container)x).Item;
                           Reference r;
                           if (obj is CurveElement)
                           {
                               r = (obj as CurveElement).GeometryCurve.Reference;
                           }
                           else
                           {
                               r = (Reference)obj;
                           }
                           //We return a list here since it's expecting an IEnumerable<Reference>. In reality,
                           //just passing the element by itself instead of a sub-list is a shortcut for having
                           //a list with one element, so this is just performing that for the user.
                           return new List<Reference>() { r };
                       }
                   }
                );

                //Now we add all of those references into ReferenceArrays

                foreach (IEnumerable<Reference> refs in refArrays.Where(x => x.Any()))
                {
                    var refArr = new ReferenceArray();
                    foreach (Reference r in refs)
                        refArr.Append(r);
                    refArrArr.Append(refArr);
                }
            }
            //If we already have a form stored...
            if (this.Elements.Any())
            {
                Form oldF;
                //is this same element?
                if (dynUtils.TryGetElement(this.Elements[0], out oldF))
                {
                    if (oldF.IsSolid == isSolid &&
                        _preferSurfaceForOneLoop == isSurface
                        && matchOrAddFormCurveToReferenceCurveMap(oldF, refArrArr, true))
                    {
                        return FScheme.Value.NewContainer(oldF);
                    }
                }

                //Dissolve it, we will re-make it later.
                if (FormUtils.CanBeDissolved(this.UIDocument.Document, this.Elements.Take(1).ToList()))
                    FormUtils.DissolveForms(this.UIDocument.Document, this.Elements.Take(1).ToList());
                //And register the form for deletion. Since we've already deleted it here manually, we can
                //pass "true" as the second argument.
                this.DeleteElement(this.Elements[0], true);

            }
            else if (this._formId != ElementId.InvalidElementId)
            {
                Form oldF;
                if (dynUtils.TryGetElement(this._formId, out oldF))
                {
                    if (oldF.IsSolid == isSolid
                        && _preferSurfaceForOneLoop == isSurface
                        && matchOrAddFormCurveToReferenceCurveMap(oldF, refArrArr, true))
                    {
                        return FScheme.Value.NewContainer(oldF);
                    }
                }
            }

            _preferSurfaceForOneLoop = isSurface;

            //We use the ReferenceArrayArray to make the form, and we store it for later runs.

            Form f;
            //if we only have a single refArr, we can make a capping surface or an extrusion
            if (refArrArr.Size == 1)
            {
                ReferenceArray refArr = refArrArr.get_Item(0);

                if (isSurface) // make a capping surface
                {
                    f = this.UIDocument.Document.FamilyCreate.NewFormByCap(true, refArr);
                }
                else  // make an extruded surface
                {
                    // The extrusion form direction
                    XYZ direction = new XYZ(0, 0, 50);
                    f = this.UIDocument.Document.FamilyCreate.NewExtrusionForm(true, refArr, direction);
                }
            }
            else // make a lofted surface
            {
                f = this.UIDocument.Document.FamilyCreate.NewLoftForm(isSolid, refArrArr);
            }

            matchOrAddFormCurveToReferenceCurveMap(f, refArrArr, false);
            this.Elements.Add(f.Id);

            return FScheme.Value.NewContainer(f);
        }
Ejemplo n.º 15
0
        //绘制模型线
        private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2)
        {
            XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0);
            XYZ p_normal1  = new XYZ(normal1.X, normal1.Y, 0);
            XYZ p_normal2  = new XYZ(normal2.X, normal2.Y, 0);

            p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y));
            p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y));


            XYZ XoYprj_start = new XYZ(startPoint.X, startPoint.Y, 0);
            XYZ XoYprj_end   = new XYZ(endPoint.X, endPoint.Y, 0);

            //在起点、终点间插值,并在z=0平面上绘制NurbSpline曲线
            double[]    doubleArray    = { 1, 1, 1, 1, 1, 1 };
            IList <XYZ> controlPoints2 = new List <XYZ>();

            controlPoints2.Add(XoYprj_start);
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(4000));
            controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(2000));
            controlPoints2.Add(XoYprj_end);

            Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray);


            //提取曲线上的拟合点,并在z轴方向插值拟合原曲线
            IList <XYZ> ptsOnCurve = nbLine.Tessellate();

            int ptCount = ptsOnCurve.Count;
            ReferencePointArray ptArr = new ReferencePointArray();

            for (int i = 0; i < ptCount; i++)
            {
                XYZ pt = ptsOnCurve[i];
                if (i < (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z)));
                }
                else if (i > 7 * (ptCount - 1) / 8)
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, endPoint.Z)));
                }
                else
                {
                    ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + (i - (ptCount - 1) / 8) * (endPoint.Z - startPoint.Z) / (0.75 * (ptCount - 1)))));
                }
                //ReferencePoint p = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i*(endPoint.Z - startPoint.Z)/ (ptCount - 1)));
                //ptArr.Append(p);
            }

            CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr);

            curve.Visible = false;

            //创建放样平面并加入参照数组中
            int step = 8;//取step个点进行拟合
            ReferenceArrayArray refArr = new ReferenceArrayArray();

            for (int i = 0; i <= step; i++)
            {
                int position = i * (ptCount - 1) / step;

                //取起点截面及第二个截面作为参照平面
                if (i == 0)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i + 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i + 1) * (ptCount - 1) / step)]));
                }
                //取终点截面及倒数第二个截面作为参照平面
                else if (i == step)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i - 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i - 1) * (ptCount - 1) / step)]));
                }
                else
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position]));
                }
            }

            //创建放样实体
            m_familyCreator.NewLoftForm(true, refArr);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ExternalCommandData cdata = commandData;
             Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
             app = commandData.Application.Application;
             Document doc = commandData.Application.ActiveUIDocument.Document;

             Transaction transaction = new Transaction(doc, "MakeSweptBlendForm");
             transaction.Start();

             // Create first profile
             ReferenceArray ref_ar = new ReferenceArray();
             Autodesk.Revit.DB.XYZ ptA = new Autodesk.Revit.DB.XYZ (10, 10, 0);
             Autodesk.Revit.DB.XYZ ptB = new Autodesk.Revit.DB.XYZ (50, 10, 0);
             ModelCurve modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);

             ptA = new Autodesk.Revit.DB.XYZ (50, 10, 0);
             ptB = new Autodesk.Revit.DB.XYZ (10, 50, 0);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);

             ptA = new Autodesk.Revit.DB.XYZ (10, 50, 0);
             ptB = new Autodesk.Revit.DB.XYZ (10, 10, 0);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);

             // Create second profile
             ReferenceArray ref_ar2 = new ReferenceArray();
             ptA = new Autodesk.Revit.DB.XYZ (10, 10, 90);
             ptB = new Autodesk.Revit.DB.XYZ (80, 10, 90);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar2.Append(modelcurve.GeometryCurve.Reference);

             ptA = new Autodesk.Revit.DB.XYZ (80, 10, 90);
             ptB = new Autodesk.Revit.DB.XYZ (10, 50, 90);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar2.Append(modelcurve.GeometryCurve.Reference);

             ptA = new Autodesk.Revit.DB.XYZ (10, 50, 90);
             ptB = new Autodesk.Revit.DB.XYZ (10, 10, 90);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             ref_ar2.Append(modelcurve.GeometryCurve.Reference);

             // Add profiles
             ReferenceArrayArray profiles = new ReferenceArrayArray();
             profiles.Append(ref_ar);
             profiles.Append(ref_ar2);

             // Create path for swept blend form
             ReferenceArray path = new ReferenceArray();
             ptA = new Autodesk.Revit.DB.XYZ (10, 10, 0);
             ptB = new Autodesk.Revit.DB.XYZ (10, 10, 90);
             modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
             path.Append(modelcurve.GeometryCurve.Reference);

             Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewSweptBlendForm(true, path, profiles);

             transaction.Commit();

             return Autodesk.Revit.UI.Result.Succeeded;
        }
Ejemplo n.º 17
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            if (!doc.IsFamilyDocument ||
                !doc.OwnerFamily.FamilyCategory.Name.Equals("Mass"))
            {
                message = "Please run this comand in a conceptual massing family document.";
                return(Result.Failed);
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create Loft Form");

                FamilyItemFactory creator = doc.FamilyCreate;

                // Create profiles array
                ReferenceArrayArray ref_ar_ar = new ReferenceArrayArray();

                // Create first profile
                ReferenceArray ref_ar = new ReferenceArray();

                int           y     = 100;
                int           x     = 50;
                XYZ           pa    = new XYZ(-x, y, 0);
                XYZ           pb    = new XYZ(x, y, 0);
                XYZ           pc    = new XYZ(0, y + 10, 10);
                CurveByPoints curve = FormUtils.MakeCurve(creator, pa, pb, pc);
                ref_ar.Append(curve.GeometryCurve.Reference);
                ref_ar_ar.Append(ref_ar);

                // Create second profile
                ref_ar = new ReferenceArray();

                y     = 40;
                pa    = new XYZ(-x, y, 5);
                pb    = new XYZ(x, y, 5);
                pc    = new XYZ(0, y, 25);
                curve = FormUtils.MakeCurve(creator, pa, pb, pc);
                ref_ar.Append(curve.GeometryCurve.Reference);
                ref_ar_ar.Append(ref_ar);

                // Create third profile
                ref_ar = new ReferenceArray();

                y     = -20;
                pa    = new XYZ(-x, y, 0);
                pb    = new XYZ(x, y, 0);
                pc    = new XYZ(0, y, 15);
                curve = FormUtils.MakeCurve(creator, pa, pb, pc);
                ref_ar.Append(curve.GeometryCurve.Reference);
                ref_ar_ar.Append(ref_ar);

                // Create fourth profile
                ref_ar = new ReferenceArray();

                y     = -60;
                pa    = new XYZ(-x, y, 0);
                pb    = new XYZ(x, y, 0);
                pc    = new XYZ(0, y + 10, 20);
                curve = FormUtils.MakeCurve(creator, pa, pb, pc);
                ref_ar.Append(curve.GeometryCurve.Reference);
                ref_ar_ar.Append(ref_ar);

                Form form = creator.NewLoftForm(true, ref_ar_ar);
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 18
0
        private void SetConstraints(Document familyDoc, Extrusion extrusion)
        {
            CurveArrArray curvesArr = new CurveArrArray();
            curvesArr = extrusion.Sketch.Profile;

            foreach (CurveArray ca in curvesArr)
            {
                CurveArrayIterator itor = ca.ForwardIterator();
                itor.Reset();
                itor.MoveNext();
                Line l = itor.Current as Line;
                _rightCon.Append(l.Reference);
                itor.MoveNext();
                l = itor.Current as Line;
                _topCon.Append(l.Reference);
                itor.MoveNext();
                l = itor.Current as Line;
                _leftCon.Append(l.Reference);
                l = itor.Current as Line;
                _botCon.Append(l.Reference);
            }
            ReferenceArrayArray conArray = new ReferenceArrayArray();

            conArray.Append(_rightCon);
            conArray.Append(_topCon);
            conArray.Append(_leftCon);
            conArray.Append(_botCon);

            //Line line = familyDoc.Application.Create.NewLine(_vert[0], _vert[1], true);
            ConstructConstraint(familyDoc, _rightCon);
            //line = familyDoc.Application.Create.NewLine(_vert[1], _vert[2], true);
            ConstructConstraint(familyDoc, _topCon);
            //line = familyDoc.Application.Create.NewLine(_vert[2], _vert[3], true);
            ConstructConstraint(familyDoc, _leftCon);
            //line = familyDoc.Application.Create.NewLine(_vert[3], _vert[0], true);
            //ConstructConstraint(familyDoc, _botCon, line);
        }
Ejemplo n.º 19
0
        private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2)
        {
            XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0);
            XYZ p_normal1  = new XYZ(normal1.X, normal1.Y, 0);
            XYZ p_normal2  = new XYZ(normal2.X, normal2.Y, 0);

            /**
             * double sita1 = StartToEnd.AngleTo(p_normal1);
             * double sita2 = StartToEnd.AngleTo(p_normal2);
             * XYZ e1 = Math.Abs(((0.25 * StartToEnd).GetLength() * Math.Cos(sita1) / p_normal1.GetLength())) * p_normal1;
             * XYZ e2 = Math.Abs(((0.25 * StartToEnd).GetLength() * Math.Cos(sita2) / p_normal2.GetLength())) * p_normal2;
             *
             *
             * XYZ prePt1 = new XYZ(startPoint.X + e1.X, startPoint.Y + e1.Y, 0);
             * XYZ prePt2 = new XYZ(endPoint.X + e2.X, endPoint.Y + e2.Y, 0);
             */
            p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y));
            p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y));


            //在起点、终点间插值,绘制NurbSpline曲线
            double[]    doubleArray    = { 1, 1, 1, 1, 1, 1 };
            IList <XYZ> controlPoints2 = new List <XYZ>();

            /**
             * controlPoints2.Insert(0, new XYZ(startPoint.X, startPoint.Y, 0));
             * controlPoints2.Insert(1, prePt1);
             * //controlPoints2.Insert(2, new XYZ((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2, 0));
             * controlPoints2.Insert(2, prePt2);
             * controlPoints2.Insert(3, new XYZ(endPoint.X, endPoint.Y, 0));
             */

            controlPoints2.Add(startPoint);
            controlPoints2.Add(startPoint + p_normal1 * mmToFeet(2000));
            controlPoints2.Add(startPoint + p_normal1 * mmToFeet(4000));
            controlPoints2.Add(endPoint + p_normal2 * mmToFeet(4000));
            controlPoints2.Add(endPoint + p_normal2 * mmToFeet(2000));
            controlPoints2.Add(endPoint);

            Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray);



            //提取曲线上的拟合点
            IList <XYZ> ptsOnCurve = nbLine.Tessellate();

            int ptCount = ptsOnCurve.Count;
            ReferencePointArray ptArr = new ReferencePointArray();

            for (int i = 0; i < ptCount; i++)
            {
                XYZ            pt = ptsOnCurve[i];
                ReferencePoint p  = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i / (ptCount - 1) * (endPoint.Z - startPoint.Z)));
                ptArr.Append(p);
            }

            CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr);

            curve.Visible = false;

            //创建放样平面并加入参照数组中
            int step = 16;//取4分点进行拟合
            ReferenceArrayArray refArr = new ReferenceArrayArray();

            for (int i = 0; i <= step; i++)
            {
                int position = i * (ptCount - 1) / step;
                if (i == 0)
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), normal1));
                }
                else if (i == ptArr.Size - 1)
                {
                    /**
                     * {
                     *  Plane plane = new Plane(normal2, ptArr.get_Item(position).Position);
                     *  Plane planeEx = new Plane(plane.XVec.CrossProduct(normal2),plane.YVec.CrossProduct(normal2),plane.Origin);
                     * }
                     */
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), -normal2));
                }
                else
                {
                    refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position]));
                }
            }
            //创建放样实体
            m_familyCreator.NewLoftForm(true, refArr);
        }
Ejemplo n.º 20
0
        public static Form ByLoftingCurveReferences(object[][] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curveReferences)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);

        }
Ejemplo n.º 21
0
        public static Form ByLoftingCurveReferences(object[] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curveReferences)
            {
                if (l == null) throw new ArgumentNullException("curveReferences");
                var refArr = new ReferenceArray();
                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);

        }
Ejemplo n.º 22
0
 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application 
 /// which contains data related to the command, 
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application 
 /// which will be displayed if a failure or cancellation is returned by 
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application 
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command. 
 /// A result of Succeeded means that the API external method functioned as expected. 
 /// Cancelled can be used to signify that the user cancelled the external operation 
 /// at some point. Failure should be returned if the application is unable to proceed with 
 /// the operation.</returns>
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     ExternalCommandData cdata = commandData;
     Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
     Document doc = commandData.Application.ActiveUIDocument.Document;
     XYZ xyz = new XYZ();
     ReferenceArrayArray refArAr = new ReferenceArrayArray();
     int x = 0;
     double z = 0;
     while (x < 800)
     {
         ReferencePointArray rpAr = new ReferencePointArray();
         int y = 0;
         while (y < 800)
         {
             z = 50 * (Math.Cos((Math.PI / 180) * x) + Math.Cos((Math.PI / 180) * y));
             xyz = app.Create.NewXYZ(x, y, z);
             ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(xyz);
             rpAr.Append(rp);
             y = y + 40;
         }
         CurveByPoints curve = doc.FamilyCreate.NewCurveByPoints(rpAr);
         ReferenceArray refAr = new ReferenceArray();
         refAr.Append(curve.GeometryCurve.Reference);
         refArAr.Append(refAr);
         x = x + 40;
     }
     Form form = doc.FamilyCreate.NewLoftForm(true, refArAr);
     return Result.Succeeded;
 }
Ejemplo n.º 23
0
        public static Form ByLoftingCurveReferences( CurveReference[][] curves, bool isSolid )
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(x.InternalReference));
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);
        }
Ejemplo n.º 24
0
        public static Form ByLoftingCurveElements( CurveElement[] curves, bool isSolid)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curves)
            {
                var refArr = new ReferenceArray();
                refArr.Append(l.InternalCurveElement.GeometryCurve.Reference);
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);
        }
Ejemplo n.º 25
0
        public static Form ByLoftCrossSections(object[][] curves, bool isSolid = true)
        {
            if (curves == null) throw new ArgumentNullException("curves");

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);

        }
Ejemplo n.º 26
0
        private static ReferenceArrayArray ConvertFSharpListListToReferenceArrayArray(FSharpList<Value> lstlst)
        {
            ReferenceArrayArray refArrArr = new ReferenceArrayArray();
            foreach (Value v in lstlst)
            {
                ReferenceArray refArr = new ReferenceArray();
                FSharpList<Value> lst = (v as Value.List).Item;

                AddReferencesToArray(refArr, lst);

                refArrArr.Append(refArr);
            }

            return refArrArr;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Create a loft form
        /// </summary>
        /// <returns>Created loft form</returns>
        private Form CreateLoft()
        {
            // Prepare profiles for loft creation
             ReferenceArrayArray profiles = new ReferenceArrayArray();
             ReferenceArray bottomProfile = new ReferenceArray();
             bottomProfile = CreateProfile(m_bottomLength, m_bottomWidth, m_bottomHeight);
             profiles.Append(bottomProfile);
             ReferenceArray topProfile = new ReferenceArray();
             topProfile = CreateProfile(m_topLength, m_topWidth, m_topHeight);
             profiles.Append(topProfile);

             // return the created loft form
             return m_revitDoc.FamilyCreate.NewLoftForm(true, profiles);
        }
Ejemplo n.º 28
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              if( !doc.IsFamilyDocument
            || !doc.OwnerFamily.FamilyCategory.Name.Equals( "Mass" ) )
              {
            message = "Please run this comand in a conceptual massing family document.";
            return Result.Failed;
              }

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "Create Loft Form" );

            FamilyItemFactory creator = doc.FamilyCreate;

              // Create profiles array
              ReferenceArrayArray ref_ar_ar = new ReferenceArrayArray();

              // Create first profile
              ReferenceArray ref_ar = new ReferenceArray();

              int y = 100;
              int x = 50;
              XYZ pa = new XYZ( -x, y, 0 );
              XYZ pb = new XYZ( x, y, 0 );
              XYZ pc = new XYZ( 0, y + 10, 10 );
              CurveByPoints curve = FormUtils.MakeCurve( creator, pa, pb, pc );
              ref_ar.Append( curve.GeometryCurve.Reference );
              ref_ar_ar.Append( ref_ar );

              // Create second profile
              ref_ar = new ReferenceArray();

              y = 40;
              pa = new XYZ( -x, y, 5 );
              pb = new XYZ( x, y, 5 );
              pc = new XYZ( 0, y, 25 );
              curve = FormUtils.MakeCurve( creator, pa, pb, pc );
              ref_ar.Append( curve.GeometryCurve.Reference );
              ref_ar_ar.Append( ref_ar );

              // Create third profile
              ref_ar = new ReferenceArray();

              y = -20;
              pa = new XYZ( -x, y, 0 );
              pb = new XYZ( x, y, 0 );
              pc = new XYZ( 0, y, 15 );
              curve = FormUtils.MakeCurve( creator, pa, pb, pc );
              ref_ar.Append( curve.GeometryCurve.Reference );
              ref_ar_ar.Append( ref_ar );

              // Create fourth profile
              ref_ar = new ReferenceArray();

              y = -60;
              pa = new XYZ( -x, y, 0 );
              pb = new XYZ( x, y, 0 );
              pc = new XYZ( 0, y + 10, 20 );
              curve = FormUtils.MakeCurve( creator, pa, pb, pc );
              ref_ar.Append( curve.GeometryCurve.Reference );
              ref_ar_ar.Append( ref_ar );

              Form form = creator.NewLoftForm( true, ref_ar_ar );
            tx.Commit();
              }
              return Result.Succeeded;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ExternalCommandData cdata = commandData;

            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            app = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Transaction transaction = new Transaction(doc, "MakeLoftForm");

            transaction.Start();

            // Create profiles array
            ReferenceArrayArray ref_ar_ar = new ReferenceArrayArray();

            // Create first profile
            ReferenceArray ref_ar = new ReferenceArray();

            int y = 100;
            int x = 50;

            Autodesk.Revit.DB.XYZ ptA        = new Autodesk.Revit.DB.XYZ(-x, y, 0);
            Autodesk.Revit.DB.XYZ ptB        = new Autodesk.Revit.DB.XYZ(x, y, 0);
            Autodesk.Revit.DB.XYZ ptC        = new Autodesk.Revit.DB.XYZ(0, y + 10, 10);
            ModelCurve            modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);

            ref_ar.Append(modelcurve.GeometryCurve.Reference);
            ref_ar_ar.Append(ref_ar);


            // Create second profile
            ref_ar = new ReferenceArray();

            y          = 40;
            ptA        = new Autodesk.Revit.DB.XYZ(-x, y, 5);
            ptB        = new Autodesk.Revit.DB.XYZ(x, y, 5);
            ptC        = new Autodesk.Revit.DB.XYZ(0, y, 25);
            modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
            ref_ar.Append(modelcurve.GeometryCurve.Reference);
            ref_ar_ar.Append(ref_ar);

            // Create third profile
            ref_ar = new ReferenceArray();

            y          = -20;
            ptA        = new Autodesk.Revit.DB.XYZ(-x, y, 0);
            ptB        = new Autodesk.Revit.DB.XYZ(x, y, 0);
            ptC        = new Autodesk.Revit.DB.XYZ(0, y, 15);
            modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
            ref_ar.Append(modelcurve.GeometryCurve.Reference);
            ref_ar_ar.Append(ref_ar);

            // Create fourth profile
            ref_ar = new ReferenceArray();

            y          = -60;
            ptA        = new Autodesk.Revit.DB.XYZ(-x, y, 0);
            ptB        = new Autodesk.Revit.DB.XYZ(x, y, 0);
            ptC        = new Autodesk.Revit.DB.XYZ(0, y + 10, 20);
            modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
            ref_ar.Append(modelcurve.GeometryCurve.Reference);
            ref_ar_ar.Append(ref_ar);
            ref_ar = new ReferenceArray();
            ref_ar_ar.Append(ref_ar);

            Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewLoftForm(true, ref_ar_ar);

            transaction.Commit();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Ejemplo n.º 30
0
        private static Form ByLoftCrossSectionsInternal(object[] curves, bool isSolid = true)
        {
            if (curves == null) throw new ArgumentNullException("curves");

            // if the arguments are polycurves, explode them
            if (curves.Any(x => x is PolyCurve))
            {
                var ca = curves.Select(x => x is PolyCurve ? ((PolyCurve)x).Curves() : new[] { x }).ToArray();
                return ByLoftMultiPartCrossSectionsInternal(ca, isSolid);
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curves)
            {
                if (l == null) throw new ArgumentNullException("curves");
                var refArr = new ReferenceArray();

                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ExternalCommandData cdata = commandData;
             Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
             app = commandData.Application.Application;
             Document doc = commandData.Application.ActiveUIDocument.Document;

             Transaction transaction = new Transaction(doc, "MakeLoftForm");
             transaction.Start();

             // Create profiles array
             ReferenceArrayArray ref_ar_ar = new ReferenceArrayArray();

             // Create first profile
             ReferenceArray ref_ar = new ReferenceArray();

             int y = 100;
             int x = 50;
             Autodesk.Revit.DB.XYZ ptA = new Autodesk.Revit.DB.XYZ (-x, y, 0);
             Autodesk.Revit.DB.XYZ ptB = new Autodesk.Revit.DB.XYZ (x, y, 0);
             Autodesk.Revit.DB.XYZ ptC = new Autodesk.Revit.DB.XYZ (0, y + 10, 10);
             ModelCurve modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);
             ref_ar_ar.Append(ref_ar);

             // Create second profile
             ref_ar = new ReferenceArray();

             y = 40;
             ptA = new Autodesk.Revit.DB.XYZ (-x, y, 5);
             ptB = new Autodesk.Revit.DB.XYZ (x, y, 5);
             ptC = new Autodesk.Revit.DB.XYZ (0, y, 25);
             modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);
             ref_ar_ar.Append(ref_ar);

             // Create third profile
             ref_ar = new ReferenceArray();

             y = -20;
             ptA = new Autodesk.Revit.DB.XYZ (-x, y, 0);
             ptB = new Autodesk.Revit.DB.XYZ (x, y, 0);
             ptC = new Autodesk.Revit.DB.XYZ (0, y, 15);
             modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);
             ref_ar_ar.Append(ref_ar);

             // Create fourth profile
             ref_ar = new ReferenceArray();

             y = -60;
             ptA = new Autodesk.Revit.DB.XYZ (-x, y, 0);
             ptB = new Autodesk.Revit.DB.XYZ (x, y, 0);
             ptC = new Autodesk.Revit.DB.XYZ (0, y + 10, 20);
             modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC);
             ref_ar.Append(modelcurve.GeometryCurve.Reference);
             ref_ar_ar.Append(ref_ar);
             ref_ar = new ReferenceArray();
             ref_ar_ar.Append(ref_ar);

             Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewLoftForm(true, ref_ar_ar);

             transaction.Commit();

             return Autodesk.Revit.UI.Result.Succeeded;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ExternalCommandData cdata = commandData;

            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            app = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Transaction transaction = new Transaction(doc, "MakeSweptBlendForm");

            transaction.Start();

            // Create first profile
            ReferenceArray ref_ar = new ReferenceArray();

            Autodesk.Revit.DB.XYZ ptA        = new Autodesk.Revit.DB.XYZ(10, 10, 0);
            Autodesk.Revit.DB.XYZ ptB        = new Autodesk.Revit.DB.XYZ(50, 10, 0);
            ModelCurve            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);

            ref_ar.Append(modelcurve.GeometryCurve.Reference);

            ptA        = new Autodesk.Revit.DB.XYZ(50, 10, 0);
            ptB        = new Autodesk.Revit.DB.XYZ(10, 50, 0);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            ref_ar.Append(modelcurve.GeometryCurve.Reference);

            ptA        = new Autodesk.Revit.DB.XYZ(10, 50, 0);
            ptB        = new Autodesk.Revit.DB.XYZ(10, 10, 0);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            ref_ar.Append(modelcurve.GeometryCurve.Reference);

            // Create second profile
            ReferenceArray ref_ar2 = new ReferenceArray();

            ptA        = new Autodesk.Revit.DB.XYZ(10, 10, 90);
            ptB        = new Autodesk.Revit.DB.XYZ(80, 10, 90);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            ref_ar2.Append(modelcurve.GeometryCurve.Reference);

            ptA        = new Autodesk.Revit.DB.XYZ(80, 10, 90);
            ptB        = new Autodesk.Revit.DB.XYZ(10, 50, 90);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            ref_ar2.Append(modelcurve.GeometryCurve.Reference);

            ptA        = new Autodesk.Revit.DB.XYZ(10, 50, 90);
            ptB        = new Autodesk.Revit.DB.XYZ(10, 10, 90);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            ref_ar2.Append(modelcurve.GeometryCurve.Reference);

            // Add profiles
            ReferenceArrayArray profiles = new ReferenceArrayArray();

            profiles.Append(ref_ar);
            profiles.Append(ref_ar2);

            // Create path for swept blend form
            ReferenceArray path = new ReferenceArray();

            ptA        = new Autodesk.Revit.DB.XYZ(10, 10, 0);
            ptB        = new Autodesk.Revit.DB.XYZ(10, 10, 90);
            modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB);
            path.Append(modelcurve.GeometryCurve.Reference);

            Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewSweptBlendForm(true, path, profiles);

            transaction.Commit();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Ejemplo n.º 33
0
        private static Form ByLoftMultiPartCrossSectionsInternal(object[][] curves, bool isSolid = true)
        {
            if (curves == null || curves.SelectMany(x => x).Any(x => x == null))
            {
                throw new ArgumentNullException("Some of the input curves are null.");
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return new Form(isSolid, refArrArr);
        }
Ejemplo n.º 34
0
        void ReconstructFormByCurves
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            IList <Rhino.Geometry.Curve> profiles
        )
        {
            if (!doc.IsFamilyDocument)
            {
                throw new InvalidOperationException("This component can only run in Family editor");
            }

            var planes = new List <Rhino.Geometry.Plane>();

            foreach (var profile in profiles)
            {
                if (!profile.TryGetPlane(out var plane))
                {
                    ThrowArgumentException(nameof(profiles), "All profiles must be planar");
                }

                plane.Origin = profile.IsClosed ? Rhino.Geometry.AreaMassProperties.Compute(profile).Centroid : profile.PointAtNormalizedLength(0.5);
                planes.Add(plane);
            }

            if (profiles.Count == 1)
            {
                var profile = profiles[0];
                var plane   = planes[0];

                using (var sketchPlane = SketchPlane.Create(doc, plane.ToPlane()))
                    using (var referenceArray = new ReferenceArray())
                    {
                        foreach (var curve in profile.ToCurveMany())
                        {
                            referenceArray.Append(new Reference(doc.FamilyCreate.NewModelCurve(curve, sketchPlane)));
                        }

                        ReplaceElement(ref element, doc.FamilyCreate.NewFormByCap(true, referenceArray));
                    }
            }
            else
            {
                using (var referenceArrayArray = new ReferenceArrayArray())
                {
                    int index = 0;
                    foreach (var profile in profiles)
                    {
                        using (var sketchPlane = SketchPlane.Create(doc, planes[index++].ToPlane()))
                        {
                            var referenceArray = new ReferenceArray();

                            foreach (var curve in profile.ToCurveMany())
                            {
                                referenceArray.Append(new Reference(doc.FamilyCreate.NewModelCurve(curve, sketchPlane)));
                            }

                            referenceArrayArray.Append(referenceArray);
                        }
                    }

                    ReplaceElement(ref element, doc.FamilyCreate.NewLoftForm(true, referenceArrayArray));
                }
            }
        }
Ejemplo n.º 35
0
        public override Expression Evaluate(FSharpList<Expression> args)
        {
            //If we already have a form stored...
            if (this.Elements.Any())
            {
                //Dissolve it, we will re-make it later.
                FormUtils.DissolveForms(this.UIDocument.Document, this.Elements.Take(1).ToList());
                //And register the form for deletion. Since we've already deleted it here manually, we can
                //pass "true" as the second argument.
                this.DeleteElement(this.Elements[0], true);
            }

            //Solid argument
            bool isSolid = ((Expression.Number)args[0]).Item == 1;

            //Surface argument
            bool isSurface = ((Expression.Number)args[2]).Item == 1;

            //Build up our list of list of references for the form by...
            IEnumerable<IEnumerable<Reference>> refArrays = ((Expression.List)args[1]).Item.Select(
                //...first selecting everything in the topmost list...
               delegate(Expression x)
               {
                   //If the element in the topmost list is a sub-list...
                   if (x.IsList)
                   {
                       //...then we return a new IEnumerable of References by converting the sub list.
                       return (x as Expression.List).Item.Select(
                          delegate(Expression y)
                          {
                              //Since we're in a sub-list, we can assume it's a container.
                              var item = ((Expression.Container)y).Item;
                              if (item is CurveElement)
                                  return (item as CurveElement).GeometryCurve.Reference;
                              else
                                  return (Reference)item;
                          }
                       );
                   }
                   //If the element is not a sub-list, then just assume it's a container.
                   else
                   {
                       var obj = ((Expression.Container)x).Item;
                       Reference r;
                       if (obj is CurveElement)
                       {
                           r = (obj as CurveElement).GeometryCurve.Reference;
                       }
                       else
                       {
                           r = (Reference)obj;
                       }
                       //We return a list here since it's expecting an IEnumerable<Reference>. In reality,
                       //just passing the element by itself instead of a sub-list is a shortcut for having
                       //a list with one element, so this is just performing that for the user.
                       return new List<Reference>() { r };
                   }
               }
            );

            //Now we add all of those references into ReferenceArrays
            ReferenceArrayArray refArrArr = new ReferenceArrayArray();
            foreach (IEnumerable<Reference> refs in refArrays.Where(x => x.Any()))
            {
                var refArr = new ReferenceArray();
                foreach (Reference r in refs)
                    refArr.Append(r);
                refArrArr.Append(refArr);
            }

            //We use the ReferenceArrayArray to make the form, and we store it for later runs.

            Form f;
            //if we only have a single refArr, we can make a capping surface or an extrusion
            if (refArrArr.Size == 1)
            {
                ReferenceArray refArr = refArrArr.get_Item(0);

                if (isSurface) // make a capping surface
                {
                    f = this.UIDocument.Document.FamilyCreate.NewFormByCap(true, refArr);
                }
                else  // make an extruded surface
                {
                    // The extrusion form direction
                    XYZ direction = new XYZ(0, 0, 50);
                    f = this.UIDocument.Document.FamilyCreate.NewExtrusionForm(true, refArr, direction);
                }
            }
            else // make a lofted surface
            {
                f = this.UIDocument.Document.FamilyCreate.NewLoftForm(isSolid, refArrArr);
            }

            this.Elements.Add(f.Id);

            return Expression.NewContainer(f);
        }
Ejemplo n.º 36
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            //Solid argument
            bool isSolid = ((Value.Number)args[0]).Item == 1;

            //Surface argument
            bool isSurface = ((Value.Number)args[2]).Item == 1;

            //Build up our list of list of references for the form by...
            var curvesListList = (Value.List)args[1];
            //Now we add all of those references into ReferenceArrays
            ReferenceArrayArray refArrArr = new ReferenceArrayArray();

            FSharpList <Value> vals = ((Value.List)curvesListList).Item;

            if (vals.Any() && (vals[0] is Value.Container) && ((Value.Container)vals[0]).Item is ModelCurveArray)
            {
                //Build a sequence that unwraps the input list from it's Value form.
                IEnumerable <ModelCurveArray> modelCurveArrays = ((Value.List)args[1]).Item.Select(
                    x => (ModelCurveArray)((Value.Container)x).Item
                    );

                foreach (var modelCurveArray in modelCurveArrays)
                {
                    var refArr = new ReferenceArray();
                    foreach (ModelCurve modelCurve in modelCurveArray)
                    {
                        refArr.Append(modelCurve.GeometryCurve.Reference);
                    }
                    refArrArr.Append(refArr);
                }
            }
            else
            {
                IEnumerable <IEnumerable <Reference> > refArrays = (curvesListList).Item.Select(
                    //...first selecting everything in the topmost list...
                    delegate(Value x)
                {
                    //If the element in the topmost list is a sub-list...
                    if (x.IsList)
                    {
                        //...then we return a new IEnumerable of References by converting the sub list.
                        return((x as Value.List).Item.Select(
                                   delegate(Value y)
                        {
                            //Since we're in a sub-list, we can assume it's a container.
                            var item = ((Value.Container)y).Item;
                            if (item is CurveElement)
                            {
                                return (item as CurveElement).GeometryCurve.Reference;
                            }
                            else
                            {
                                return (Reference)item;
                            }
                        }
                                   ));
                    }
                    //If the element is not a sub-list, then just assume it's a container.
                    else
                    {
                        var obj = ((Value.Container)x).Item;
                        Reference r;
                        if (obj is CurveElement)
                        {
                            r = (obj as CurveElement).GeometryCurve.Reference;
                        }
                        else
                        {
                            r = (Reference)obj;
                        }
                        //We return a list here since it's expecting an IEnumerable<Reference>. In reality,
                        //just passing the element by itself instead of a sub-list is a shortcut for having
                        //a list with one element, so this is just performing that for the user.
                        return(new List <Reference>()
                        {
                            r
                        });
                    }
                }
                    );

                //Now we add all of those references into ReferenceArrays

                foreach (IEnumerable <Reference> refs in refArrays.Where(x => x.Any()))
                {
                    var refArr = new ReferenceArray();
                    foreach (Reference r in refs)
                    {
                        refArr.Append(r);
                    }
                    refArrArr.Append(refArr);
                }
            }
            //If we already have a form stored...
            if (this.Elements.Any())
            {
                //is this same element?
                Element e = null;
                if (dynUtils.TryGetElement(this.Elements[0], typeof(Form), out e) && e != null &&
                    e is Form)
                {
                    Form oldF = (Form)e;
                    if (oldF.IsSolid == isSolid &&
                        preferSurfaceForOneLoop == isSurface &&
                        matchOrAddFormCurveToReferenceCurveMap(oldF, refArrArr, true))
                    {
                        return(Value.NewContainer(oldF));
                    }
                }

                //Dissolve it, we will re-make it later.
                if (FormUtils.CanBeDissolved(this.UIDocument.Document, this.Elements.Take(1).ToList()))
                {
                    FormUtils.DissolveForms(this.UIDocument.Document, this.Elements.Take(1).ToList());
                }
                //And register the form for deletion. Since we've already deleted it here manually, we can
                //pass "true" as the second argument.
                this.DeleteElement(this.Elements[0], true);
            }
            else if (this.formId != ElementId.InvalidElementId)
            {
                Element e = null;
                if (dynUtils.TryGetElement(this.formId, typeof(Form), out e) && e != null &&
                    e is Form)
                {
                    Form oldF = (Form)e;
                    if (oldF.IsSolid == isSolid &&
                        preferSurfaceForOneLoop == isSurface &&
                        matchOrAddFormCurveToReferenceCurveMap(oldF, refArrArr, true))
                    {
                        return(Value.NewContainer(oldF));
                    }
                }
            }

            preferSurfaceForOneLoop = isSurface;

            //We use the ReferenceArrayArray to make the form, and we store it for later runs.

            Form f;

            //if we only have a single refArr, we can make a capping surface or an extrusion
            if (refArrArr.Size == 1)
            {
                ReferenceArray refArr = refArrArr.get_Item(0);

                if (isSurface) // make a capping surface
                {
                    f = this.UIDocument.Document.FamilyCreate.NewFormByCap(true, refArr);
                }
                else  // make an extruded surface
                {
                    // The extrusion form direction
                    XYZ direction = new XYZ(0, 0, 50);
                    f = this.UIDocument.Document.FamilyCreate.NewExtrusionForm(true, refArr, direction);
                }
            }
            else // make a lofted surface
            {
                f = this.UIDocument.Document.FamilyCreate.NewLoftForm(isSolid, refArrArr);
            }

            matchOrAddFormCurveToReferenceCurveMap(f, refArrArr, false);
            this.Elements.Add(f.Id);

            return(Value.NewContainer(f));
        }
Ejemplo n.º 37
0
        private void SetConstraints(Document familyDoc, Extrusion extrusion)
        {
            try
            {
                CurveArrArray curvesArr = new CurveArrArray();
                curvesArr = extrusion.Sketch.Profile;

                foreach (CurveArray ca in curvesArr)
                {
                    CurveArrayIterator itor = ca.ForwardIterator();
                    itor.Reset();
                    itor.MoveNext();
                    Line l = itor.Current as Line;
                    _rightCon.Append(l.Reference);
                    itor.MoveNext();
                    l = itor.Current as Line;
                    _topCon.Append(l.Reference);
                    itor.MoveNext();
                    l = itor.Current as Line;
                    _leftCon.Append(l.Reference);
                    l = itor.Current as Line;
                    _botCon.Append(l.Reference);
                }
                ReferenceArrayArray conArray = new ReferenceArrayArray();

                conArray.Append(_rightCon);
                conArray.Append(_topCon);
                conArray.Append(_leftCon);
                conArray.Append(_botCon);

                ConstructConstraint(familyDoc, _rightCon);
                ConstructConstraint(familyDoc, _topCon);
                ConstructConstraint(familyDoc, _leftCon);
            }

            catch (Exception ex)
            {
                TaskDialog.Show("Constraint Error", ex.Message);
            }
        }