예제 #1
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="revit">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(Autodesk.Revit.UI.ExternalCommandData revit,
                                                ref string message,
                                                ElementSet elements)
        {
            try
            {
                m_application = revit.Application.Application;
                m_document    = revit.Application.ActiveUIDocument.Document;

                // it can support in truss family document only
                if (!m_document.IsFamilyDocument ||
                    m_document.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_Truss)
                {
                    message = "Cannot execute truss creation in non-truss family document";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                m_appCreator    = m_application.Create;
                m_familyCreator = m_document.FamilyCreate;

                Transaction newTran = new Transaction(m_document);
                newTran.Start("NewTrussCurve");

                // Start the truss creation
                MakeNewTruss();

                newTran.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
예제 #2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

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

            try
            {
                // find forms in the model:

                FilteredElementCollector forms = new FilteredElementCollector(doc);
                forms.OfCategory(BuiltInCategory.OST_MassForm); // was OST_MassSurface

                foreach (Form form in forms)
                {
                    // create the divided surface on the loft form:

                    FamilyItemFactory factory = doc.FamilyCreate;
                    Options           options = creApp.NewGeometryOptions();
                    options.ComputeReferences = true;
                    options.View = doc.ActiveView;
                    GeometryElement element = form.get_Geometry(options);

                    //GeometryObjectArray geoObjectArray = element.Objects; // 2012
                    //for( int j = 0; j < geoObjectArray.Size; j++ )
                    //{
                    //  GeometryObject geoObject = geoObjectArray.get_Item( j );

                    foreach (GeometryObject geoObject in element) // 2013
                    {
                        Solid solid = geoObject as Solid;
                        foreach (Face face in solid.Faces)
                        {
                            if (face.Reference != null)
                            {
                                if (null != face)
                                {
                                    //DividedSurface divSurface = factory.NewDividedSurface( face.Reference ); // 2013
                                    DividedSurface divSurface = DividedSurface.Create(doc, face.Reference); // 2014
                                }
                            }
                        }
                    }
                }
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
예제 #3
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint( pa );
              ReferencePoint rpb = creator.NewReferencePoint( pb );
              ReferencePoint rpc = creator.NewReferencePoint( pc );

              ReferencePointArray arr = new ReferencePointArray();

              arr.Append( rpa );
              arr.Append( rpb );
              arr.Append( rpc );

              return creator.NewCurveByPoints( arr );
        }
예제 #4
0
        /// <summary>
        /// Create a CurveByPoints element by three given points
        /// </summary>
        public static CurveByPoints MakeCurve(
            FamilyItemFactory creator,
            XYZ pa,
            XYZ pb,
            XYZ pc)
        {
            ReferencePoint rpa = creator.NewReferencePoint(pa);
            ReferencePoint rpb = creator.NewReferencePoint(pb);
            ReferencePoint rpc = creator.NewReferencePoint(pc);

            ReferencePointArray arr = new ReferencePointArray();

            arr.Append(rpa);
            arr.Append(rpb);
            arr.Append(rpc);

            return(creator.NewCurveByPoints(arr));
        }
예제 #5
0
        /// <summary>
        /// Create an extrusion from a given thickness
        /// and list of XYZ points defined in millimetres
        /// in the given family document, which  must
        /// contain a sketch plane named "Ref. Level".
        /// </summary>
        Extrusion CreateExtrusion(
            Document doc,
            List <XYZ> pts,
            double thickness)
        {
            Autodesk.Revit.Creation.FamilyItemFactory factory
                = doc.FamilyCreate;

            SketchPlane sketch = FindElement(doc,
                                             typeof(SketchPlane), "Ref. Level")
                                 as SketchPlane;

            CurveArrArray curveArrArray = new CurveArrArray();

            curveArrArray.Append(CreateProfile(pts));

            double extrusionHeight = MmToFoot(thickness);

            return(factory.NewExtrusion(true,
                                        curveArrArray, sketch, extrusionHeight));
        }
예제 #6
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,
                                         ElementSet elements)
 {
     try
     {
         m_revit          = commandData.Application.Application;
         m_familyDocument = commandData.Application.ActiveUIDocument.Document;
         // create new family document if active document is not a family document
         if (!m_familyDocument.IsFamilyDocument)
         {
             m_familyDocument = m_revit.NewFamilyDocument("Generic Model.rft");
             if (null == m_familyDocument)
             {
                 message = "Cannot open family document";
                 return(Autodesk.Revit.UI.Result.Failed);
             }
         }
         m_creationFamily = m_familyDocument.FamilyCreate;
         // create generic model family in the document
         CreateGenericModel();
         if (0 == m_errCount)
         {
             return(Autodesk.Revit.UI.Result.Succeeded);
         }
         else
         {
             message = m_errorInfo;
             return(Autodesk.Revit.UI.Result.Failed);
         }
     }
     catch (Exception e)
     {
         message = e.ToString();
         return(Autodesk.Revit.UI.Result.Failed);
     }
 }
예제 #7
0
 /// <summary>
 /// The constructor of CreateAlignment class
 /// </summary>
 /// <param name="doc">the document</param>
 public CreateAlignment(Document doc)
 {
     m_document      = doc;
     m_familyCreator = m_document.FamilyCreate;
 }
예제 #8
0
        /// <summary>
        /// Create a new swept blend form using arcs to
        /// define circular start and end profiles and an
        /// arc path. The NewSweptBlend method requires
        /// the input profiles to be in the XY plane.
        /// </summary>
        public void CreateNewSweptBlendArc(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 credoc
                = doc.FamilyCreate;

            #region Original code for Revit 2012
      #if COMPILE_ORIGINAL_CODE
            XYZ           pnt1    = new XYZ(0, -1, 0);
            XYZ           pnt2    = new XYZ(1, 0, 0);
            XYZ           pnt3    = new XYZ(0, 1, 0);
            XYZ           pnt4    = new XYZ(-1, 0, 0);
            Arc           aArc1   = creapp.NewArc(pnt1, pnt3, pnt2);
            Arc           aArc2   = creapp.NewArc(pnt3, pnt1, pnt4);
            CurveArrArray arrarr1 = new CurveArrArray();

            SweepProfile bottomProfile
                = creapp.NewCurveLoopsProfile(arrarr1);

            CurveArray arr1 = new CurveArray();
            arr1.Append(aArc1);
            arr1.Append(aArc2);
            XYZ           pnt6    = new XYZ(0, -2, 0);
            XYZ           pnt7    = new XYZ(2, 0, 0);
            XYZ           pnt8    = new XYZ(0, 2, 0);
            XYZ           pnt9    = new XYZ(-2, 0, 0);
            Arc           aArc3   = creapp.NewArc(pnt6, pnt8, pnt7);
            Arc           aArc4   = creapp.NewArc(pnt8, pnt6, pnt9);
            CurveArrArray arrarr2 = new CurveArrArray();
            CurveArray    arr2    = new CurveArray();
            arr2.Append(aArc3);
            arr2.Append(aArc4);
            arrarr2.Append(arr2);

            SweepProfile topProfile
                = creapp.NewCurveLoopsProfile(arrarr2);

            XYZ   pnt10   = new XYZ(0, 0, 0);
            XYZ   pnt11   = new XYZ(0, 5, 0);
            XYZ   pnt122  = new XYZ(2.5, 2.5, 0);
            Arc   testArc = creapp.NewArc(pnt10, pnt11, pnt122);
            Curve curve   = (Curve)testArc;

            Plane geometryPlane = creapp.NewPlane(
                XYZ.BasisZ, XYZ.Zero);

            SketchPlane sketchPlane = doc.NewSketchPlane(
                geometryPlane);

            SweptBlend aSweptBlend = doc.NewSweptBlend(
                true, curve, sketchPlane, bottomProfile,
                topProfile);
      #endif // COMPILE_ORIGINAL_CODE
            #endregion // Original code for Revit 2012

            XYZ        px   = XYZ.BasisX;
            XYZ        py   = XYZ.BasisY;
            Arc        arc1 = Arc.Create(-px, px, -py);
            Arc        arc2 = Arc.Create(px, -px, py);
            CurveArray arr1 = new CurveArray();
            arr1.Append(arc1);
            arr1.Append(arc2);
            CurveArrArray arrarr1 = new CurveArrArray();
            arrarr1.Append(arr1);

            SweepProfile bottomProfile
                = creapp.NewCurveLoopsProfile(arrarr1);

            px += px;
            py += py;
            Arc        arc3 = Arc.Create(-px, px, -py);
            Arc        arc4 = Arc.Create(px, -px, py);
            CurveArray arr2 = new CurveArray();
            arr2.Append(arc3);
            arr2.Append(arc4);
            CurveArrArray arrarr2 = new CurveArrArray();
            arrarr2.Append(arr2);

            SweepProfile topProfile
                = creapp.NewCurveLoopsProfile(arrarr2);

            XYZ p0      = XYZ.Zero;
            XYZ p5      = 5 * XYZ.BasisY;
            XYZ pmid    = new XYZ(2.5, 2.5, 0);
            Arc testArc = Arc.Create(p0, p5, pmid);

            Plane geometryPlane = creapp.NewPlane(
                XYZ.BasisZ, XYZ.Zero);

            SketchPlane sketchPlane = SketchPlane.Create(
                doc, geometryPlane);

            SweptBlend aSweptBlend = credoc.NewSweptBlend(
                true, testArc, sketchPlane, bottomProfile,
                topProfile);
        }
예제 #9
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);
        }
        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);
        }
예제 #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication app = commandData.Application;

            doc             = app.ActiveUIDocument.Document;
            massdoc         = app.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2016\Family Templates\Chinese\概念体量\公制体量.rft");
            m_familyCreator = massdoc.FamilyCreate;

            //选择并初始化工井实例
            Autodesk.Revit.UI.Selection.Selection sel = app.ActiveUIDocument.Selection;
            IList <Reference> familylist = sel.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, "请选择工井");
            FamilyInstance    well1      = doc.GetElement(familylist[0]) as FamilyInstance;
            FamilyInstance    well2      = doc.GetElement(familylist[1]) as FamilyInstance;

            //初始化welldoc
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            if (collector != null)
            {
                collector.OfClass(typeof(Family));
            }
            IList <Element> list = collector.ToElements();

            foreach (Element f in list)
            {
                Family family = f as Family;
                if (family.Name == "直通工井")
                {
                    welldoc = doc.EditFamily(family);
                    break;
                }
            }

            //创建电缆族文件并保存
            Transaction trans = new Transaction(massdoc);

            trans.Start("创建新曲线");
            MakeNewCurve(well1, well2);
            trans.Commit();

            int fileNum = 0;

            string path;

            while (true)
            {
                path = "C:\\Users\\DELL\\Documents\\test" + fileNum.ToString() + ".rft";
                if (!File.Exists(path))
                {
                    massdoc.SaveAs(path);
                    break;
                }
                fileNum++;
            }

            string filename = "test" + fileNum.ToString();

            //将电缆插入项目文件中
            trans = new Transaction(doc);
            trans.Start("将曲线插入项目文件");
            doc.LoadFamily(path);
            FamilySymbol fs = getSymbolType(doc, filename);

            fs.Activate();
            FamilyInstance fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            fi.Category.Material = getMaterial(doc, "混凝土");
            trans.Commit();

            return(Result.Succeeded);
        }
예제 #12
0
 /// <summary>
 /// The constructor of CreateAlignment class
 /// </summary>        
 /// <param name="doc">the document</param>
 public CreateAlignment(Document doc)
 {
     m_document = doc;
     m_familyCreator = m_document.FamilyCreate;
 }
예제 #13
0
 /// <summary>
 /// The constructor of CreateExtrusion
 /// </summary>
 /// <param name="app">the application</param>
 /// <param name="doc">the document</param>
 public CreateExtrusion(Application app, Document doc)
 {
     m_document = doc;
     m_appCreator = app.Create;
     m_familyCreator = doc.FamilyCreate;
 }
예제 #14
0
 /// <summary>
 /// The constructor of CreateExtrusion
 /// </summary>
 /// <param name="app">the application</param>
 /// <param name="doc">the document</param>
 public CreateExtrusion(Application app, Document doc)
 {
     m_document      = doc;
     m_appCreator    = app.Create;
     m_familyCreator = doc.FamilyCreate;
 }
예제 #15
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Application app = commandData.Application.Application;

            string filename = Path.Combine(_folder, _template);

            Document familyDoc = app.NewFamilyDocument(filename);

            Family family = familyDoc.OwnerFamily;

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

            Extrusion extrusion = null;

            using (Transaction trans = new Transaction(
                       familyDoc))
            {
                trans.Start("Create Extrusion");

                XYZ arcCenter = new XYZ(0.0, 3.0, -2.0);

                // Get the "left" view

                View view = GetView(ViewType.Elevation,
                                    XYZ.BasisY.Negate(), XYZ.BasisZ, familyDoc);

                // 2D offsets from view 'left'

                XYZ xOffset = new XYZ(0.0, 10.0, 0.0);
                XYZ yOffset = new XYZ(0.0, 0.0, -10.0);

                //################## Reference planes ################################

                // Origin's reference planes

                ReferencePlane referencePlaneOriginX
                    = factory.NewReferencePlane(XYZ.BasisX,
                                                XYZ.Zero, XYZ.BasisY, view);

                referencePlaneOriginX.Name   = "ReferencePlane_OriginX";
                referencePlaneOriginX.Pinned = true;

                ReferencePlane referencePlaneOriginY
                    = factory.NewReferencePlane(XYZ.BasisZ,
                                                XYZ.Zero, -XYZ.BasisX, view);

                referencePlaneOriginY.Name   = "ReferencePlane_OriginY";
                referencePlaneOriginY.Pinned = true;

                // Reference planes the extruded arc should stick to

                ReferencePlane referencePlaneX
                    = factory.NewReferencePlane(
                          XYZ.BasisX + yOffset,
                          XYZ.Zero + yOffset,
                          XYZ.BasisY, view);
                referencePlaneX.Name = "ReferencePlane_X";

                ReferencePlane referencePlaneY
                    = factory.NewReferencePlane(
                          XYZ.BasisZ + xOffset,
                          XYZ.Zero + xOffset,
                          -XYZ.BasisX, view);
                referencePlaneY.Name = "ReferencePlane_Y";

                familyDoc.Regenerate();

                //################## Create dimensions ###############################

                // Dimension x

                ReferenceArray refArrayX = new ReferenceArray();
                refArrayX.Append(referencePlaneX.GetReference());
                refArrayX.Append(referencePlaneOriginX.GetReference());

                Line      lineX      = Line.CreateUnbound(arcCenter, XYZ.BasisZ);
                Dimension dimensionX = factory.NewDimension(
                    view, lineX, refArrayX);

                // Dimension y

                ReferenceArray refArrayY = new ReferenceArray();
                refArrayY.Append(referencePlaneY.GetReference());
                refArrayY.Append(referencePlaneOriginY.GetReference());

                Line      lineY      = Line.CreateUnbound(arcCenter, XYZ.BasisY);
                Dimension dimensionY = factory.NewDimension(
                    view, lineY, refArrayY);

                familyDoc.Regenerate();

                //################## Create arc ######################################

                double arcRadius = 1.0;

                Arc arc = Arc.Create(
                    XYZ.Zero + xOffset + yOffset,
                    arcRadius, 0.0, 2 * Math.PI,
                    XYZ.BasisZ, XYZ.BasisY.Negate());

                CurveArray curves = new CurveArray();
                curves.Append(arc);

                CurveArrArray profile = new CurveArrArray();
                profile.Append(curves);

                Plane plane = new Plane(XYZ.BasisX.Negate(),
                                        arcCenter);

                SketchPlane sketchPlane = SketchPlane.Create(
                    familyDoc, plane);

                Debug.WriteLine("Origin: " + sketchPlane.GetPlane().Origin);
                Debug.WriteLine("Normal: " + sketchPlane.GetPlane().Normal);
                Debug.WriteLine("XVec:   " + sketchPlane.GetPlane().XVec);
                Debug.WriteLine("YVec:   " + sketchPlane.GetPlane().YVec);

                extrusion = factory.NewExtrusion(true,
                                                 profile, sketchPlane, 10);

                familyDoc.Regenerate();

                //################## Add family parameters ###########################

                FamilyManager fmgr = familyDoc.FamilyManager;

                FamilyParameter paramX = fmgr.AddParameter("X",
                                                           BuiltInParameterGroup.PG_GEOMETRY,
                                                           ParameterType.Length, true);
                dimensionX.FamilyLabel = paramX;

                FamilyParameter paramY = fmgr.AddParameter("Y",
                                                           BuiltInParameterGroup.PG_GEOMETRY,
                                                           ParameterType.Length, true);
                dimensionY.FamilyLabel = paramY;

                // Set their values

                FamilyType familyType = fmgr.NewType(
                    "Standard");

                fmgr.Set(paramX, 10);
                fmgr.Set(paramY, 10);

                trans.Commit();
            }

            // Save it to inspect

            SaveAsOptions opt = new SaveAsOptions();

            opt.OverwriteExistingFile = true;

            filename = Path.Combine(Path.GetTempPath(),
                                    "test.rfa");

            familyDoc.SaveAs(filename, opt);

            return(Result.Succeeded);
        }
예제 #16
0
파일: CreateTruss.cs 프로젝트: AMEE/revit
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="revit">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(Autodesk.Revit.UI.ExternalCommandData revit,
                                                              ref string message,
                                                              ElementSet elements)
        {
            try
            {
                m_application = revit.Application.Application;
                m_document = revit.Application.ActiveUIDocument.Document;

                // it can support in truss family document only
                if (!m_document.IsFamilyDocument
                    || m_document.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_Truss)
                {
                    message = "Cannot execute truss creation in non-truss family document";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                m_appCreator = m_application.Create;
                m_familyCreator = m_document.FamilyCreate;

                Transaction newTran = new Transaction(m_document);
                newTran.Start("NewTrussCurve");

                // Start the truss creation
                MakeNewTruss();

                newTran.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return Autodesk.Revit.UI.Result.Failed;
            }
            return Autodesk.Revit.UI.Result.Succeeded;
        }