Exemplo n.º 1
0
        /// <summary>
        /// Create one blend
        /// </summary>
        private void CreateBlend()
        {
            try
            {
                #region Create top and base profiles
                CurveArray topProfile  = new CurveArray();
                CurveArray baseProfile = new CurveArray();

                Autodesk.Revit.DB.XYZ normal      = Autodesk.Revit.DB.XYZ.BasisZ;
                SketchPlane           sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);

                // create one blend
                Autodesk.Revit.DB.XYZ p00 = Autodesk.Revit.DB.XYZ.Zero;
                Autodesk.Revit.DB.XYZ p01 = new Autodesk.Revit.DB.XYZ(10, 0, 0);
                Autodesk.Revit.DB.XYZ p02 = new Autodesk.Revit.DB.XYZ(10, 10, 0);
                Autodesk.Revit.DB.XYZ p03 = new Autodesk.Revit.DB.XYZ(0, 10, 0);
                Line line01 = Line.CreateBound(p00, p01);
                Line line02 = Line.CreateBound(p01, p02);
                Line line03 = Line.CreateBound(p02, p03);
                Line line04 = Line.CreateBound(p03, p00);

                baseProfile.Append(line01);
                baseProfile.Append(line02);
                baseProfile.Append(line03);
                baseProfile.Append(line04);

                Autodesk.Revit.DB.XYZ p10 = new Autodesk.Revit.DB.XYZ(5, 2, 10);
                Autodesk.Revit.DB.XYZ p11 = new Autodesk.Revit.DB.XYZ(8, 5, 10);
                Autodesk.Revit.DB.XYZ p12 = new Autodesk.Revit.DB.XYZ(5, 8, 10);
                Autodesk.Revit.DB.XYZ p13 = new Autodesk.Revit.DB.XYZ(2, 5, 10);
                Line line11 = Line.CreateBound(p10, p11);
                Line line12 = Line.CreateBound(p11, p12);
                Line line13 = Line.CreateBound(p12, p13);
                Line line14 = Line.CreateBound(p13, p10);

                topProfile.Append(line11);
                topProfile.Append(line12);
                topProfile.Append(line13);
                topProfile.Append(line14);
                #endregion
                // here create one blend
                Blend blend = m_creationFamily.NewBlend(true, topProfile, baseProfile, sketchPlane);
                // move to proper place
                Autodesk.Revit.DB.XYZ transPoint1 = new Autodesk.Revit.DB.XYZ(0, 11, 0);
                ElementTransformUtils.MoveElement(m_familyDocument, blend.Id, transPoint1);
            }
            catch (Exception e)
            {
                m_errCount++;
                m_errorInfo += "Unexpected exceptions occur in CreateBlend: " + e.ToString() + "\r\n";
            }
        }
        static Blend CreateBlend(Document doc)
        {
            Debug.Assert(doc.IsFamilyDocument,
                         "this method will only work in a family document");

            Application app = doc.Application;

            Autodesk.Revit.Creation.Application creApp
                = app.Create;

            Autodesk.Revit.Creation.FamilyItemFactory factory
                = doc.FamilyCreate;

            double startAngle = 0;
            double midAngle   = Math.PI;
            double endAngle   = 2 * Math.PI;

            XYZ xAxis = XYZ.BasisX;
            XYZ yAxis = XYZ.BasisY;

            XYZ    center = XYZ.Zero;
            XYZ    normal = -XYZ.BasisZ;
            double radius = 0.7579;

            //Arc arc1 = creApp.NewArc( center, radius, startAngle, midAngle, xAxis, yAxis ); // 2013
            //Arc arc2 = creApp.NewArc( center, radius, midAngle, endAngle, xAxis, yAxis ); // 2013

            Arc arc1 = Arc.Create(center, radius, startAngle, midAngle, xAxis, yAxis); // 2014
            Arc arc2 = Arc.Create(center, radius, midAngle, endAngle, xAxis, yAxis);   // 2014

            CurveArray baseProfile = new CurveArray();

            baseProfile.Append(arc1);
            baseProfile.Append(arc2);

            // create top profile:

            CurveArray topProfile = new CurveArray();

            bool circular_top = false;

            if (circular_top)
            {
                // create a circular top profile:

                XYZ center2 = new XYZ(0, 0, 1.27);

                //Arc arc3 = creApp.NewArc( center2, radius, startAngle, midAngle, xAxis, yAxis ); // 2013
                //Arc arc4 = creApp.NewArc( center2, radius, midAngle, endAngle, xAxis, yAxis ); // 2013

                Arc arc3 = Arc.Create(center2, radius, startAngle, midAngle, xAxis, yAxis); // 2014
                Arc arc4 = Arc.Create(center2, radius, midAngle, endAngle, xAxis, yAxis);   // 2014

                topProfile.Append(arc3);
                topProfile.Append(arc4);
            }
            else
            {
                // create a skewed rectangle top profile:

                XYZ[] pts = new XYZ[] {
                    new XYZ(0, 0, 3),
                    new XYZ(2, 0, 3),
                    new XYZ(3, 2, 3),
                    new XYZ(0, 4, 3)
                };

                for (int i = 0; i < 4; ++i)
                {
                    //topProfile.Append( creApp.NewLineBound( // 2013

                    topProfile.Append(Line.CreateBound( // 2014
                                          pts[0 == i ? 3 : i - 1], pts[i]));
                }
            }

            //Plane basePlane = creApp.NewPlane( normal, center ); // 2016
            Plane basePlane = Plane.CreateByNormalAndOrigin(normal, center); // 2017

            //SketchPlane sketch = factory.NewSketchPlane( basePlane ); // 2013
            SketchPlane sketch = SketchPlane.Create(doc, basePlane); // 2014

            Blend blend = factory.NewBlend(true,
                                           topProfile, baseProfile, sketch);

            return(blend);
        }