Beispiel #1
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(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                m_application = commandData.Application;
                m_document    = m_application.ActiveUIDocument;
                if (m_document.Document.IsFamilyDocument)
                {
                    m_CreationBase = m_document.Document.FamilyCreate;
                }
                else
                {
                    m_CreationBase = m_document.Document.Create;
                }

                //Pick a face from UI, create a new sketch plane via the face and set it to the current view.
                Reference      faceRef         = m_document.Selection.PickObject(ObjectType.Face, new PlanarFaceFilter(m_document.Document), "Please pick a planar face to set the work plane. ESC for cancel.");
                GeometryObject geoObject       = m_document.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef);
                PlanarFace     planarFace      = geoObject as PlanarFace;
                SketchPlane    faceSketchPlane = CreateSketchPlane(planarFace.Normal, planarFace.Origin);
                if (faceSketchPlane != null)
                {
                    Transaction changeSketchPlane = new Transaction(m_document.Document, "Change Sketch Plane.");
                    changeSketchPlane.Start();
                    m_document.Document.ActiveView.SketchPlane = faceSketchPlane;
                    m_document.Document.ActiveView.ShowActiveWorkPlane();
                    changeSketchPlane.Commit();
                }

                // Pick point from current work plane with snaps.
                ObjectSnapTypes snapType = ObjectSnapTypes.Centers | ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections
                                           | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Nearest | ObjectSnapTypes.WorkPlaneGrid;
                XYZ point = m_document.Selection.PickPoint(snapType, "Please pick a point to place component.");

                // Create a model curve by a circle with picked point as center.
                Transaction createModelCurve = new Transaction(m_document.Document, "Create a circle.");
                createModelCurve.Start();
                Curve circle = m_application.Application.Create.NewArc(point, 5, 0, Math.PI * 2, faceSketchPlane.Plane.XVec, faceSketchPlane.Plane.YVec);
                m_CreationBase.NewModelCurve(circle, faceSketchPlane);
                createModelCurve.Commit();

                return(Result.Succeeded);
            }
            catch (Exceptions.OperationCanceledException)
            {
                // Selection Cancelled. For picking face and picking point.
                return(Result.Cancelled);
            }
            catch (System.Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Prompt the user to select a face on an element
        /// and then pick a point on that face. The first
        /// picking of the face on the element temporarily
        /// redefines the active work plane, on which the
        /// second point can be picked.
        /// </summary>
        bool PickFaceSetWorkPlaneAndPickPoint(
            UIDocument uidoc,
            out XYZ point_in_3d)
        {
            point_in_3d = null;

            Document doc = uidoc.Document;

            try
            {
                Reference r = uidoc.Selection.PickObject(
                    ObjectType.Face,
                    "Please select a planar face to define work plane");

                Element e = doc.GetElement(r.ElementId);

                if (null != e)
                {
                    PlanarFace face
                        = e.GetGeometryObjectFromReference(r)
                          as PlanarFace;

                    if (face != null)
                    {
                        //Plane plane = new Plane( face.FaceNormal, face.Origin ); // 2016
                        Plane plane = Plane.CreateByNormalAndOrigin(
                            face.FaceNormal, face.Origin); // 2017

                        using (Transaction t = new Transaction(doc))
                        {
                            t.Start("Temporarily set work plane"
                                    + " to pick point in 3D");

                            //SketchPlane sp = doc.Create.NewSketchPlane( plane ); // 2013

                            SketchPlane sp = SketchPlane.Create(doc, plane); // 2014

                            uidoc.ActiveView.SketchPlane = sp;
                            uidoc.ActiveView.ShowActiveWorkPlane();

                            point_in_3d = uidoc.Selection.PickPoint(
                                "Please pick a point on the plane"
                                + " defined by the selected face");

                            t.RollBack();
                        }
                    }
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
            }

            return(null != point_in_3d);
        }
Beispiel #3
0
        /// <summary>
        /// Create a model line between the two given points.
        /// Internally, it creates an arbitrary sketch
        /// plane given the model line end points.
        /// </summary>
        public static ModelLine CreateModelLine(
            Document doc,
            XYZ p,
            XYZ q)
        {
            if (p.DistanceTo(q) < Util.MinLineLength)
            {
                return(null);
            }

            // Create sketch plane; for non-vertical lines,
            // use Z-axis to span the plane, otherwise Y-axis:

            XYZ v = q - p;

            double dxy = Math.Abs(v.X) + Math.Abs(v.Y);

            XYZ w = (dxy > Util.TolPointOnPlane)
        ? XYZ.BasisZ
        : XYZ.BasisY;

            XYZ norm = v.CrossProduct(w).Normalize();

            //Autodesk.Revit.Creation.Application creApp
            //  = doc.Application.Create;

            //Plane plane = creApp.NewPlane( norm, p ); // 2014
            Plane plane = new Plane(norm, p); // 2015

            //SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
            SketchPlane sketchPlane = SketchPlane.Create(doc, plane); // 2014

            //Line line = creApp.NewLine( p, q, true ); // 2013
            Line line = Line.CreateBound(p, q); // 2014

            // The following line is only valid in a project
            // document. In a family, it will throw an exception
            // saying "Document.Create can only be used with
            // project documents. Use Document.FamilyCreate
            // in the Family Editor."

            //Autodesk.Revit.Creation.Document creDoc
            //  = doc.Create;

            //return creDoc.NewModelCurve(
            //  //creApp.NewLine( p, q, true ), // 2013
            //  Line.CreateBound( p, q ), // 2014
            //  sketchPlane ) as ModelLine;

            ModelCurve curve = doc.IsFamilyDocument
        ? doc.FamilyCreate.NewModelCurve(line, sketchPlane)
        : doc.Create.NewModelCurve(line, sketchPlane);

            return(curve as ModelLine);
        }
Beispiel #4
0
        SketchBoundary()
        {
            Revit.Creation.Document doc         = m_revitApp.ActiveUIDocument.Document.Create;
            SketchPlane             sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

            RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
            if (lev.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Level curLevel = lev.LevelSelected;

            if (curLevel == null)
            {
                MessageBox.Show("No Level was selected.");
                return;
            }

            // Get the plan topology of the active doc first
            PlanTopology            planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
            ICollection <ElementId> roomIds  = planTopo.GetRoomIds();

            if (roomIds.Count > 0)
            {
                IEnumerator <ElementId> setIter = roomIds.GetEnumerator();
                while (setIter.MoveNext())
                {
                    Autodesk.Revit.DB.Architecture.Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Autodesk.Revit.DB.Architecture.Room;

                    if (null != room)
                    {
                        IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundSegArrayArray = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

                        foreach (IList <Autodesk.Revit.DB.BoundarySegment> boundSegArray in boundSegArrayArray)
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegArray)
                            {
                                if (null != boundSeg)
                                {
                                    // once you get to the Boundary Segment which represent one of the sides of the room boundary, draw a Model Curve to
                                    // represent the outline.
                                    ModelCurve modCurve = m_revitApp.ActiveUIDocument.Document.Create.NewModelCurve(boundSeg.Curve, sketchPlane);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Creates a new Sketch Plane from a Curve
        /// </summary>
        /// <param name="document">Active Document</param>
        /// <param name="curve">Curve to get plane from</param>
        /// <returns>Plane of the curve</returns>
        public static SketchPlane NewSketchPlaneFromCurve(Document document, Autodesk.Revit.DB.Curve curve)
        {
            XYZ startPoint = curve.GetEndPoint(0);
            XYZ endPoint   = curve.GetEndPoint(1);

            // If Start end Endpoint are the same check further points.
            int i = 2;

            while (startPoint == endPoint && endPoint != null)
            {
                endPoint = curve.GetEndPoint(i);
                i++;
            }



            // Plane to return
            Plane plane;


            // If Z Values are equal the Plane is XY
            if (startPoint.Z == endPoint.Z)
            {
                plane = CreatePlane(document, XYZ.BasisZ, startPoint);
            }
            // If X Values are equal the Plane is YZ
            else if (startPoint.X == endPoint.X)
            {
                plane = CreatePlane(document, XYZ.BasisX, startPoint);
            }
            // If Y Values are equal the Plane is XZ
            else if (startPoint.Y == endPoint.Y)
            {
                plane = CreatePlane(document, XYZ.BasisY, startPoint);
            }
            // Otherwise the Planes Normal Vector is not X,Y or Z.
            // We draw lines from the Origin to each Point and use the Plane this one spans up.
            else
            {
                CurveArray curves = new CurveArray();
                curves.Append(curve);
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint));
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0)));
#if (Revit2015 || Revit2016 || Revit2017)
                plane = document.Application.Create.NewPlane(curves);
#else
                plane = Plane.CreateByThreePoints(startPoint, new XYZ(0, 0, 0), endPoint);
#endif
            }


            // return new Sketchplane
            return(SketchPlane.Create(document, plane));
        }
        /// <summary>
        /// Use Autodesk.Revit.DB.ElementId to get the corresponding sketch plane
        /// </summary>
        /// <param name="id">the element id value</param>
        /// <returns>the corresponding sketch plane</returns>
        SketchPlane GetSketchPlaneById(ElementId id)
        {
            // First get the sketch plane by the giving element id.
            SketchPlane workPlane = GetElementById(id) as SketchPlane;

            if (null == workPlane)
            {
                throw new Exception("Don't have the work plane you select.");
            }
            return(workPlane);
        }
Beispiel #7
0
 private void SetWorkPlane(View view1, Document doc1)
 {
     Plane plane1 = Plane.CreateByNormalAndOrigin(view1.ViewDirection, view1.Origin);
     using (Transaction t1 = new Transaction(doc1, "Set new wokplane"))
     {
         t1.Start();
         SketchPlane sp1 = SketchPlane.Create(doc1, plane1);
         doc1.ActiveView.SketchPlane = sp1;
         t1.Commit();
     }
 }
Beispiel #8
0
        SketchPlane CreateSketchPlane(
            Document doc,
            XYZ normal,
            XYZ origin)
        {
            Plane geometryPlane = doc.Application.Create
                                  .NewPlane(normal, origin);

            //return doc.Create.NewSketchPlane( geometryPlane ); // 2013

            return(SketchPlane.Create(doc, geometryPlane)); // 2014
        }
Beispiel #9
0
        /// <summary>
        /// Create line element
        /// </summary>
        /// <param name="app">revit application</param>
        /// <param name="ptA">start point</param>
        /// <param name="ptB">end point</param>
        /// <returns></returns>
        public static ModelCurve MakeLine(UIApplication app, Autodesk.Revit.DB.XYZ ptA, Autodesk.Revit.DB.XYZ ptB, Autodesk.Revit.DB.XYZ norm)
        {
            Document doc = app.ActiveUIDocument.Document;
            // Create plane by the points
            Line        line    = Line.CreateBound(ptA, ptB);
            Plane       plane   = app.Application.Create.NewPlane(norm, ptB);
            SketchPlane skplane = SketchPlane.Create(doc, plane);
            // Create line here
            ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(line, skplane);

            return(modelcurve);
        }
Beispiel #10
0
        /// <summary>
        /// Create one SweptBlend
        /// </summary>
        private void CreateSweptBlend()
        {
            try
            {
                #region Create top and bottom profiles and path curve
                Autodesk.Revit.DB.XYZ pnt1 = new Autodesk.Revit.DB.XYZ(0, 0, 0);
                Autodesk.Revit.DB.XYZ pnt2 = new Autodesk.Revit.DB.XYZ(1, 0, 0);
                Autodesk.Revit.DB.XYZ pnt3 = new Autodesk.Revit.DB.XYZ(1, 1, 0);
                Autodesk.Revit.DB.XYZ pnt4 = new Autodesk.Revit.DB.XYZ(0, 1, 0);
                Autodesk.Revit.DB.XYZ pnt5 = new Autodesk.Revit.DB.XYZ(0, 0, 1);

                CurveArrArray arrarr1 = new CurveArrArray();
                CurveArray    arr1    = new CurveArray();
                arr1.Append(Line.CreateBound(pnt1, pnt2));
                arr1.Append(Line.CreateBound(pnt2, pnt3));
                arr1.Append(Line.CreateBound(pnt3, pnt4));
                arr1.Append(Line.CreateBound(pnt4, pnt1));
                arrarr1.Append(arr1);

                Autodesk.Revit.DB.XYZ pnt6    = new Autodesk.Revit.DB.XYZ(0.5, 0, 0);
                Autodesk.Revit.DB.XYZ pnt7    = new Autodesk.Revit.DB.XYZ(1, 0.5, 0);
                Autodesk.Revit.DB.XYZ pnt8    = new Autodesk.Revit.DB.XYZ(0.5, 1, 0);
                Autodesk.Revit.DB.XYZ pnt9    = new Autodesk.Revit.DB.XYZ(0, 0.5, 0);
                CurveArrArray         arrarr2 = new CurveArrArray();
                CurveArray            arr2    = new CurveArray();
                arr2.Append(Line.CreateBound(pnt6, pnt7));
                arr2.Append(Line.CreateBound(pnt7, pnt8));
                arr2.Append(Line.CreateBound(pnt8, pnt9));
                arr2.Append(Line.CreateBound(pnt9, pnt6));
                arrarr2.Append(arr2);

                SweepProfile bottomProfile = m_revit.Create.NewCurveLoopsProfile(arrarr1);
                SweepProfile topProfile    = m_revit.Create.NewCurveLoopsProfile(arrarr2);

                Autodesk.Revit.DB.XYZ pnt10 = new Autodesk.Revit.DB.XYZ(5, 0, 0);
                Autodesk.Revit.DB.XYZ pnt11 = new Autodesk.Revit.DB.XYZ(0, 20, 0);
                Curve curve = Line.CreateBound(pnt10, pnt11);

                Autodesk.Revit.DB.XYZ normal      = Autodesk.Revit.DB.XYZ.BasisZ;
                SketchPlane           sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
                #endregion
                // here create one swept blend
                SweptBlend newSweptBlend1 = m_creationFamily.NewSweptBlend(true, curve, sketchPlane, bottomProfile, topProfile);
                // move to proper place
                Autodesk.Revit.DB.XYZ transPoint1 = new Autodesk.Revit.DB.XYZ(11, 32, 0);
                ElementTransformUtils.MoveElement(m_familyDocument, newSweptBlend1.Id, transPoint1);
            }
            catch (Exception e)
            {
                m_errCount++;
                m_errorInfo += "Unexpected exceptions occur in CreateSweptBlend: " + e.ToString() + "\r\n";
            }
        }
Beispiel #11
0
        void CreateModelCurves(
            View view,
            CurveLoop loop)
        {
            Document    doc = view.Document;
            SketchPlane sp  = view.SketchPlane;

            foreach (Curve curve in loop)
            {
                doc.Create.NewModelCurve(curve, sp);
            }
        }
Beispiel #12
0
        public bool Create()
        {
            IList <ElementId>       idList             = new List <ElementId>();
            ICollection <ElementId> elementIdsToDivide = new List <ElementId>();

            idList.Add(Floor.Id);
            if (PartUtils.AreElementsValidForCreateParts(PublicVariables.Doc, idList))
            {
                using (Transaction tr = new Transaction(PublicVariables.Doc, "CreatePart"))
                {
                    tr.Start();
                    try
                    {
                        PartUtils.CreateParts(PublicVariables.Doc, idList);
                        tr.Commit();
                    }
                    catch
                    {
                        tr.RollBack();
                    }
                    elementIdsToDivide = PartUtils.GetAssociatedParts(PublicVariables.Doc
                                                                      , Floor.Id, true, true);
                }
            }

            ICollection <ElementId> intersectingReferenceIds = new List <ElementId>();
            var curveList = (from Curve elem in BoundingSquare
                             select elem).ToList();

            using (Transaction tr = new Transaction(PublicVariables.Doc, "DivideParts"))
            {
                tr.Start();
                try
                {
                    SketchPlane sp = SketchPlane.Create(PublicVariables.Doc,
                                                        Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), BoundingSquare[0].GetEndPoint(0)));

                    PartMaker maker = PartUtils.DivideParts(PublicVariables.Doc,
                                                            elementIdsToDivide, intersectingReferenceIds, curveList, sp.Id);

                    Parameter partVisInView = PublicVariables.Doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY);
                    partVisInView.Set(0);
                    tr.Commit();
                }
                catch
                {
                    tr.RollBack();
                }
            }

            return(true);
        }
Beispiel #13
0
        public void Process(DataTreeBranch b, DataTreeBranch currentBranch)
        {
            List <XYZ>    ptArr   = new List <XYZ>();
            List <double> weights = new List <double>();

            foreach (object o in b.Leaves)
            {
                ReferencePoint pt = o as ReferencePoint;
                ptArr.Add(pt.Position);
                weights.Add(1);
            }

            //only make a curve if
            //there's enough points
            if (ptArr.Count > 1)
            {
                //make a curve
                NurbSpline ns       = dynElementSettings.SharedInstance.Doc.Application.Application.Create.NewNurbSpline(ptArr, weights);
                double     rawParam = ns.ComputeRawParameter(.5);
                Transform  t        = ns.ComputeDerivatives(rawParam, false);

                XYZ norm = t.BasisZ;

                if (norm.GetLength() == 0)
                {
                    norm = XYZ.BasisZ;
                }

                Plane       p  = new Plane(norm, t.Origin);
                SketchPlane sp = dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewSketchPlane(p);
                sps.Add(sp);

                ModelNurbSpline c = (ModelNurbSpline)dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewModelCurve(ns, sp);

                //add the element to the collection
                //so it can be deleted later
                Elements.Append(c);

                //create a leaf node on the local branch
                currentBranch.Leaves.Add(c);
            }

            foreach (DataTreeBranch b1 in b.Branches)
            {
                //every time you read a branch
                //create a branch
                DataTreeBranch newBranch = new DataTreeBranch();
                this.Tree.Trunk.Branches.Add(newBranch);

                Process(b1, newBranch);
            }
        }
Beispiel #14
0
        public void SelectReferenceASTGeneration()
        {
            Form extrude;

            using (var trans = new Transaction(DocumentManager.Instance.CurrentDBDocument, "Create an extrusion Form"))
            {
                trans.Start();

                FailureHandlingOptions fails = trans.GetFailureHandlingOptions();
                fails.SetClearAfterRollback(true);
                trans.SetFailureHandlingOptions(fails);

                var p   = new Plane(new XYZ(0, 0, 1), new XYZ());
                var arc = Arc.Create(p, 2, 0, System.Math.PI);
                var sp  = SketchPlane.Create(DocumentManager.Instance.CurrentDBDocument, p);
                var mc  = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewModelCurve(arc, sp);

                var profiles = new ReferenceArray();
                profiles.Append(mc.GeometryCurve.Reference);
                extrude = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewExtrusionForm(false, profiles, new XYZ(0, 0, 1));
                trans.Commit();
            }

            var geom = extrude.get_Geometry(new Options()
            {
                ComputeReferences        = true,
                DetailLevel              = ViewDetailLevel.Medium,
                IncludeNonVisibleObjects = true
            });

            var solid = geom.FirstOrDefault(x => x is Solid) as Solid;
            var face  = solid.Faces.get_Item(0);

            Assert.Greater(solid.Faces.Size, 0);

            var sel = new DSFaceSelection()
            {
                SelectedElement = face.Reference
            };

            var buildOutput = sel.BuildOutputAst(new List <AssociativeNode>());

            var funCall = (FunctionCallNode)((IdentifierListNode)((BinaryExpressionNode)buildOutput.First()).RightNode).RightNode;

            Assert.IsInstanceOf <IdentifierNode>(funCall.Function);
            Assert.AreEqual(1, funCall.FormalArguments.Count);
            Assert.IsInstanceOf <StringNode>(funCall.FormalArguments[0]);

            var stableRef = face.Reference.ConvertToStableRepresentation(DocumentManager.Instance.CurrentDBDocument);

            Assert.AreEqual(stableRef, ((StringNode)funCall.FormalArguments[0]).value);
        }
Beispiel #15
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";
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // UIApplication uiapp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            Selection  sel   = uidoc.Selection;
            //
            // View acView = uidoc.ActiveView;
            // UIView acuiview = uidoc.ActiveUiview();

            //创建简单的拉升族
            string templateFileName = @"C:\ProgramData\Autodesk\RVT 2019\Family Templates\Chinese\公制常规模型.rft";

            Document familyDoc = commandData.Application.Application.NewFamilyDocument
                                     (templateFileName);


            using (Transaction ts = new Transaction(familyDoc))

            {
                ts.Start("CreatFamily");


                CurveArray curveArray = new CurveArray();
                curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5 / 304.8, 0, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(5 / 304.8, 0, 0), new XYZ(5 / 304.8, 5 / 304.8, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(5 / 304.8, 5 / 304.8, 0), new XYZ(0, 5 / 304.8, 0)));
                curveArray.Append(Line.CreateBound(new XYZ(0, 5 / 304.8, 0), new XYZ(0, 0, 0)));

                CurveArrArray curveArrArray = new CurveArrArray();
                curveArrArray.Append(curveArray);

                Plane plane =
                    Plane.CreateByOriginAndBasis(XYZ.Zero, new XYZ(1, 0, 0), new XYZ(0, 1, 0));
                SketchPlane sketchPlane = SketchPlane.Create(familyDoc, plane);

                //创建一个拉拉升体
                familyDoc.FamilyCreate.NewExtrusion
                    (true, curveArrArray, sketchPlane, 10 / 304.8);

                //创建一个族类型
                familyDoc.FamilyManager.NewType("MyNewType");

                ts.Commit();

                familyDoc.SaveAs(@"D:\MyNewFamily3.rfa");
                familyDoc.Close();
            }

            TaskDialog.Show("提示", "创建成功");
            return(Result.Succeeded);
        }
Beispiel #17
0
        public static void NewLine_withoutTransaction(this Document doc, Line line)
        {
            var dir    = line.Direction;
            var origin = line.Origin;
            var norm   = default(XYZ);

            norm = dir.getRandomNorm();

            var plan        = Plane.CreateByNormalAndOrigin(norm, origin);
            var sketchplane = SketchPlane.Create(doc, plan);

            doc.Create.NewModelCurve(line, sketchplane);
        }
Beispiel #18
0
      /// <summary>
      /// Create a sketch plane via given normal and origin points.
      /// </summary>
      /// <param name="normal">The vector for normal of sketch plane.</param>
      /// <param name="origin">The vector for origin of sketch plane.</param>
      /// <returns>The new sketch plane created by specific normal and origin.</returns>
      internal SketchPlane CreateSketchPlane(Autodesk.Revit.DB.XYZ normal, Autodesk.Revit.DB.XYZ origin)
      {
         // First create a Geometry.Plane which need in NewSketchPlane() method
         Plane geometryPlane = m_application.Application.Create.NewPlane(normal, origin);

         // Then create a sketch plane using the Geometry Plane
         Transaction createSketchPlane = new Transaction(m_document.Document, "Create a sketch plane.");
         createSketchPlane.Start();
         SketchPlane plane = SketchPlane.Create(m_document.Document, geometryPlane);
         createSketchPlane.Commit();

         return plane;
      }
Beispiel #19
0
        ModelCurve CreateModelCurve(
            Curve curve,
            XYZ origin,
            XYZ normal)
        {
            Plane plane = _creapp.NewPlane(normal, origin);

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

            return(_credoc.NewModelCurve(
                       curve, sketchPlane));
        }
Beispiel #20
0
        EllipticalArcHardwire()
        {
            double revitPi = 3.14159265358979;  // TBD: see above

            // make a simple Ellipse, oriented in the X axis, at the origin.
            double      radiusX     = 8.0;
            double      radiusY     = 5.0;
            SketchPlane sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);
            // TBD: in order to get a full ellipse, I have to know the exact full parameter range (see above).  Should just be two signatures.
            Ellipse ellipse = Ellipse.Create(GeomUtils.kOrigin, radiusX, radiusY, GeomUtils.kXAxis, GeomUtils.kYAxis, 0.0, (revitPi * 1.5));

            m_revitApp.ActiveUIDocument.Document.Create.NewModelCurve(ellipse, sketchPlane);
        }
Beispiel #21
0
        public void ByPlane_ValidArgs()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);

            var sketchPlane = SketchPlane.ByPlane(plane);

            Assert.NotNull(sketchPlane);
            Assert.NotNull(sketchPlane.Plane);
            Assert.AreEqual(normal, sketchPlane.Plane.Normal);
            Assert.AreEqual(origin, sketchPlane.Plane.Origin);
            Assert.NotNull(sketchPlane.ElementPlaneReference);
        }
Beispiel #22
0
        public Dimension CreateLinearDimension1(Document doc, XYZ pt1, XYZ pt2, SketchPlane sketch, Application app)
        {
            // first create line

            Line       line       = Line.CreateBound(pt1, pt2);
            ModelCurve modelcurve = doc.Create
                                    .NewModelCurve(line, sketch);

            ReferenceArray ra = new ReferenceArray();

            ra.Append(modelcurve.GeometryCurve.GetEndPointReference(0));
            ra.Append(modelcurve.GeometryCurve.GetEndPointReference(1));
            return(doc.Create.NewDimension(doc.ActiveView, line, ra));
        }
Beispiel #23
0
        /// <summary>
        ///     Creates a new sketch plane.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public static SketchPlane CreateSketchPlane(this Document doc, Line line)
        {
            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (line is null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            return(SketchPlane.Create(doc, line.CreatePlane()));
        }
Beispiel #24
0
        ModelCurve CreateModelCurve(
            Curve curve,
            XYZ origin,
            XYZ normal)
        {
            //Plane plane = _creapp.NewPlane( normal, origin ); // 2016
            Plane plane = Plane.CreateByNormalAndOrigin(normal, origin); // 2020

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

            return(_credoc.NewModelCurve(
                       curve, sketchPlane));
        }
Beispiel #25
0
        public void ByPlane_CanBeUsedToCreateSketchPlaneInFamilyDocument()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);

            var sketchPlane = SketchPlane.ByPlane(plane);

            Assert.NotNull(sketchPlane);
            Assert.NotNull(sketchPlane.Plane);
            Assert.AreEqual(normal, sketchPlane.Plane.Normal);
            Assert.AreEqual(origin, sketchPlane.Plane.Origin);
            Assert.NotNull(sketchPlane.ElementPlaneReference);
        }
        public static ModelCurve DrawCircle(Document doc, Plane p, SketchPlane sp, double radius)
        {
            SubTransaction st = new SubTransaction(doc);

            st.Start();


            Curve circle = Arc.Create(p, radius, 0, Math.PI * 2.0 - 0.5);

            ModelCurve curve = doc.Create.NewModelCurve(circle, sp);

            st.Commit();
            return(curve as ModelLine);
        }
Beispiel #27
0
        /// <summary>
        ///     Creates a new sketch plane.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        public static SketchPlane CreateSketchPlane(this Document doc, Plane plane)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (plane == null)
            {
                throw new ArgumentNullException(nameof(plane));
            }

            return(SketchPlane.Create(doc, plane));
        }
Beispiel #28
0
        public static IList <Solid> CreateSolid(Document doc, FamilyInstance familyInstance, Transform transform)
        {
            IList <Solid> solids = new List <Solid>();

            try
            {
                Curve    curve      = GetCurvemaxfamily(familyInstance);
                Element  ele        = doc.GetElement(familyInstance.Id);
                string[] parameters = new string[]
                {
                    "DIM_WWF_YY",
                    "DIM_LENGTH"
                };
                Parameter   pa          = LookupElementParameter(ele, parameters);
                double      lengthcurve = pa.AsDouble();
                XYZ         starpointfa = new XYZ(lengthcurve / 2, 0, 0);
                XYZ         endpointfa  = new XYZ(-lengthcurve / 2, 0, 0);
                XYZ         startpoint  = transform.OfPoint(starpointfa);
                XYZ         endpoint    = transform.OfPoint(endpointfa);
                XYZ         norm        = new XYZ((startpoint.X - endpoint.X), (startpoint.Y - endpoint.Y), (startpoint.Z - endpoint.Z));
                Plane       plane       = Plane.CreateByNormalAndOrigin(norm, startpoint);
                Transaction newtran     = new Transaction(doc, "ss");
                newtran.Start();
                SketchPlane stk       = SketchPlane.Create(doc, plane);
                XYZ         pt1       = startpoint.Add(0.01 * plane.XVec).Add(0.01 * plane.YVec);
                XYZ         pt2       = startpoint.Add(0.01 * plane.YVec);
                XYZ         pt3       = startpoint.Add(-0.01 * plane.YVec);
                XYZ         pt4       = startpoint.Add(0.01 * plane.XVec).Add(-0.01 * plane.YVec);
                XYZ         pt5       = (-1) * norm;
                Line        lineleft  = Line.CreateBound(pt1, pt2);
                Line        linetop   = Line.CreateBound(pt2, pt3);
                Line        lineright = Line.CreateBound(pt3, pt4);
                Line        linebot   = Line.CreateBound(pt4, pt1);
                CurveLoop   profile   = new CurveLoop();
                profile.Append(lineleft);
                profile.Append(linetop);
                profile.Append(lineright);
                profile.Append(linebot);
                IList <CurveLoop> listloop1 = new List <CurveLoop>();
                listloop1.Add(profile);
                Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(listloop1, pt5, lengthcurve);
                newtran.Commit();
                solids.Add(solid);
            }
            catch
            {
                solids = null;
            }
            return(solids);
        }
Beispiel #29
0
        /// <summary>
        ///     Creates a new sketch plane.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="pt"></param>
        /// <returns></returns>
        public static SketchPlane CreateSketchPlane(this Document doc, XYZ pt)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (pt == null)
            {
                throw new ArgumentNullException(nameof(pt));
            }

            return(SketchPlane.Create(doc, pt.CreatePlane()));
        }
Beispiel #30
0
        private static ElementId createModelCurve(Document document, Curve curve, SketchPlane sp = null)
        {
            Line          line     = curve as Line;
            Arc           arc      = curve as Arc;
            Ellipse       ellipse  = curve as Ellipse;
            HermiteSpline spline   = curve as HermiteSpline;
            NurbSpline    nbSpline = curve as NurbSpline;

            if (line != null && null == sp)
            {
                XYZ normal = getVertVec(line.Direction).Normalize();
                XYZ origin = line.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }
            else if (arc != null && null == sp)
            {
                XYZ normal = arc.Normal;
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, arc.Center));
            }
            else if (ellipse != null && null == sp)
            {
                XYZ normal = ellipse.Normal;
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, ellipse.Center));
            }
            else if (spline != null && null == sp)
            {
                Transform tran   = spline.ComputeDerivatives(0, false);
                XYZ       normal = getVertVec(tran.BasisX).Normalize();
                XYZ       origin = spline.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }
            else if (nbSpline != null && null == sp)
            {
                Transform tran   = nbSpline.ComputeDerivatives(0, false);
                XYZ       normal = getVertVec(tran.BasisX).Normalize();
                XYZ       origin = nbSpline.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }

            if (sp == null)
            {
                throw new ArgumentException("Not valid sketchplane to create curve:" + curve.GetType().Name);
            }
            //
            // create model line with curve and the specified sketch plane.
            ModelCurve mCurve = document.Create.NewModelCurve(curve, sp);

            return((null != mCurve) ? mCurve.Id : ElementId.InvalidElementId);
        }
Beispiel #31
0
 //override the destroy method for all point objects
 public override void Destroy()
 {
     try
     {
         if (ll1 != null)
         {
             Settings.Doc.Document.Delete(ll1);
             Settings.Doc.Document.Delete(ll2);
             Settings.Doc.Document.Delete(ll3);
             Settings.Doc.Document.Delete(topSketch);
             Settings.Doc.Document.Delete(fbSketch);
             Settings.Doc.Document.Delete(lrSketch);
             ll1 = null;
             ll2 = null;
             ll3 = null;
             topSketch = null;
             fbSketch = null;
             lrSketch = null;
         }
         if (xyPlane != null)
         {
             point = null;
             xyPlane = null;
             yzPlane = null;
             xzPlane = null;
         }
     }
     catch
     {
         ll1 = null;
         ll2 = null;
         ll3 = null;
         topSketch = null;
         fbSketch = null;
         lrSketch = null;
         point = null;
         xyPlane = null;
         yzPlane = null;
         xzPlane = null;
     }
 }
        private void Stream( ArrayList data, SketchPlane sketchPlane )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( SketchPlane ) ) );

              data.Add( new Snoop.Data.Object( "Plane", sketchPlane.GetPlane() ) );
        }
Beispiel #33
0
        public override void Draw()
        {
            //dynDouble x = Inputs[0] as dynDouble;
            //dynDouble y = Inputs[1] as dynDouble;
            //dynDouble z = Inputs[2] as dynDouble;

            //if (x != null && y != null && z != null)
            //{
            //    point = new XYZ(x.D, y.D, z.D);
            //}
            //else
            //{
            //    point = null;
            //}

            if (point != null)
            {

                //generate the planes
                xyPlane = this.Settings.Revit.Application.Create.NewPlane(up, point);
                yzPlane = this.Settings.Revit.Application.Create.NewPlane(xAxis, point);
                xzPlane = this.Settings.Revit.Application.Create.NewPlane(yAxis, point);

                //generate the tick lines
                Line l1 = this.Settings.Revit.Application.Create.NewLineBound(point, point + up);
                Line l2 = this.Settings.Revit.Application.Create.NewLineBound(point, point + xAxis);
                Line l3 = this.Settings.Revit.Application.Create.NewLineBound(point, point + yAxis);

                //generate the sketch planes
                topSketch = this.Settings.Doc.Document.Create.NewSketchPlane(xyPlane);
                lrSketch = this.Settings.Doc.Document.Create.NewSketchPlane(yzPlane);
                fbSketch = this.Settings.Doc.Document.Create.NewSketchPlane(xzPlane);

                ll1 = this.Settings.Doc.Document.Create.NewModelCurve(l1, lrSketch) as ModelLine;
                ll2 = this.Settings.Doc.Document.Create.NewModelCurve(l2, topSketch) as ModelLine;
                ll3 = this.Settings.Doc.Document.Create.NewModelCurve(l3, topSketch) as ModelLine;

                if (xyPlane_out != null && yzPlane_out != null && xzPlane_out != null)
                {
                    //update the outputs
                    xyPlane_out.P = xyPlane;
                    yzPlane_out.P = yzPlane;
                    xzPlane_out.P = xzPlane;
                }
            }
        }
Beispiel #34
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="app"></param>
 /// <param name="sketchPlane"></param>
 /// <returns></returns>
 private static Revit.Element CloneElement( Autodesk.Revit.UI.UIApplication app, SketchPlane sketchPlane )
 {
     SketchPlane sketchPlaneClone = SketchPlane.Create( app.ActiveUIDocument.Document, sketchPlane.GetPlane() );
       Utils.ParamUtil.SetParameters( sketchPlaneClone.Parameters, sketchPlane.Parameters );
       return sketchPlaneClone;
 }
Beispiel #35
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pts"></param>
        private void CreatePolyline(IList<XYZ> pts)
        {
            if (m_sketchPlane == null) {
                XYZ zAxis = GeomUtils.kZAxis;
                XYZ origin = GeomUtils.kOrigin;
                Plane plane = m_app.Application.Create.NewPlane(zAxis, origin);

                m_sketchPlane = SketchPlane.Create(m_app.ActiveUIDocument.Document, plane);
            }

            Line line;
            XYZ startPt;
            XYZ endPt;
            CurveArray curveArray = new CurveArray();

            for (int i = 0; i < (pts.Count - 1); ++i)
            {
                startPt = pts[i];
                endPt   = pts[i + 1];

                line = Line.CreateBound(startPt, endPt);
                curveArray.Append(line);
            }

            m_app.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, m_sketchPlane);
        }
        /// <summary>
        /// Create model lines representing a closed 
        /// planar loop in the given sketch plane.
        /// </summary>
        static void DrawModelLineLoop(
            SketchPlane sketchPlane,
            XYZ[] corners)
        {
            Autodesk.Revit.Creation.Document factory
            = sketchPlane.Document.Create;

              int n = corners.GetLength( 0 );

              for( int i = 0; i < n; ++i )
              {
            int j = 0 == i ? n - 1 : i - 1;

            factory.NewModelCurve( Line.CreateBound(
              corners[j], corners[i] ), sketchPlane );
              }
        }
        /// <summary>
        /// Return true if the sketch plane belongs to us
        /// and its origin and normal vector match the 
        /// given targets.
        /// Nope, we are unable to set the sketch plane 
        /// name. However, Revit throws an exception if 
        /// we try to draw on the skatch plane named
        /// 'Level 1', so lets ensure we use '<not 
        /// associated>'.
        /// </summary>
        static bool SketchPlaneMatches(
            SketchPlane sketchPlane,
            XYZ origin,
            XYZ normal)
        {
            //bool rc = sketchPlane.Name.StartsWith(
              //  _sketch_plane_name_prefix );

              bool rc = sketchPlane.Name.Equals(
            _sketch_plane_name_prefix2 );

              if( rc )
              {
            Plane plane = sketchPlane.GetPlane();

            rc = plane.Normal.IsAlmostEqualTo( normal )
              && IsAlmostZero( SignedDistanceTo(
            plane, origin ) );
              }
              return rc;
        }
Beispiel #38
0
        /// <summary>
        /// Utility method to create a truss model curve.
        /// </summary>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <param name="sketchPlane">The sketch plane for the new curve.</param>
        /// <param name="type">The type of truss curve.</param>
        /// <returns>the created truss model curve.</returns>
        private ModelCurve MakeTrussCurve(Autodesk.Revit.DB.XYZ start, Autodesk.Revit.DB.XYZ end, SketchPlane sketchPlane, TrussCurveType type)
        {
            Line line = m_appCreator.NewLineBound(start, end);
            ModelCurve trussCurve = m_familyCreator.NewModelCurve(line, sketchPlane);
            trussCurve.TrussCurveType = type;
            m_document.Regenerate();

            return trussCurve;
        }
 ModelCurveArray CreateModelCurveArray(
     Document doc,
     CurveArray geometryCurveArray,
     SketchPlane sketchPlane)
 {
     return doc.Create.NewModelCurveArray(
     geometryCurveArray, sketchPlane );
 }