Exemplo n.º 1
0
        private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //calculate the desired rotation
            //we do this by finding the angle between the z axis
            //and vector between the start of the beam and the target point
            //both projected onto the start plane of the beam.
            var zAxis = new Autodesk.Revit.DB.XYZ(0, 0, 1);
            var yAxis = new Autodesk.Revit.DB.XYZ(0, 1, 0);

            //flatten the beam line onto the XZ plane
            //using the start's z coordinate
            var start  = curve.GetEndPoint(0);
            var end    = curve.GetEndPoint(1);
            var newEnd = new Autodesk.Revit.DB.XYZ(end.X, end.Y, start.Z); //drop end point to plane

            //catch the case where the end is directly above
            //the start, creating a normal with zero length
            //in that case, use the Z axis
            var planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

            var gamma = upVector.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

            return(new FamilyInstanceCreationData(curve, symbol, level, structuralType)
            {
                RotateAngle = gamma
            });
        }
Exemplo n.º 2
0
        public static object ApproximateToRvt(this Curve curve)
        {
            if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.NurbsCurve))
            {
                NurbsCurve nurbsCurve = (NurbsCurve)curve;

                if (nurbsCurve.IsLinear())
                {
                    return(Autodesk.Revit.DB.Line.CreateBound(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType()));
                }
                else
                {
                    return(Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType()));
                }
            }
            else if (curve.GetType() == typeof(Autodesk.DesignScript.Geometry.PolyCurve))
            {
                DynamoRebar.RevitPolyCurve revitpolycurve = new RevitPolyCurve((Autodesk.DesignScript.Geometry.PolyCurve)curve);
                return(revitpolycurve);
            }
            else
            {
                Autodesk.Revit.DB.Curve result = curve.ToRevitType();

                if (result.GetType() == typeof(Autodesk.Revit.DB.NurbSpline))
                {
                    return(Autodesk.Revit.DB.Arc.Create(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), curve.PointAtParameter(0.5).ToRevitType()));
                }
                else
                {
                    return(result);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Init a new detail curve from curve
        /// </summary>
        /// <param name="view"></param>
        /// <param name="curve"></param>
        private void Init(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Curve curve)
        {
            // Open Transaction and get document
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            // Get exsiting element
            var element = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.DetailCurve>(document);

            if (element == null)
            {
                if (document.IsFamilyDocument)
                {
                    element = document.FamilyCreate.NewDetailCurve(view, curve);
                }
                else
                {
                    element = document.Create.NewDetailCurve(view, curve);
                }
            }
            else
            {
                element.SetGeometryCurve(curve, true);
            }

            InternalSetCurveElement(element);

            // Set transaction task done & element for trace
            TransactionManager.Instance.TransactionTaskDone();
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize a StructuralFraming element
        /// </summary>
        private void InitStructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(symbol);
                InternalSetCurve(curve);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var creationData = GetCreationData(curve, upVector, level, structuralType, symbol);

            Autodesk.Revit.DB.FamilyInstance fi;
            if (Document.IsFamilyDocument)
            {
                var elementIds = Document.FamilyCreate.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception(Properties.Resources.FamilyInstanceCreationFailure);
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }
            else
            {
                var elementIds = Document.Create.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception(Properties.Resources.FamilyInstanceCreationFailure);
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Exemplo n.º 5
0
        private void InternalSetPosition(Autodesk.Revit.DB.Curve pos)
        {
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            if (InternalFamilyInstance.Location is Autodesk.Revit.DB.LocationCurve lp && lp.Curve != pos)
            {
                lp.Curve = pos;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new instance of WallType, deleting the original
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private Wall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var wallElem =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Wall>(Document);

            bool successfullyUsedExistingWall = false;

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
                var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
                if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc))
                {
                    wallLocation.Curve = curve;

                    Autodesk.Revit.DB.Parameter baseLevelParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                    Autodesk.Revit.DB.Parameter topOffsetParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    Autodesk.Revit.DB.Parameter wallTypeParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                    if (baseLevelParameter.AsElementId() != baseLevel.Id)
                    {
                        baseLevelParameter.Set(baseLevel.Id);
                    }
                    if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                    {
                        topOffsetParameter.Set(height);
                    }
                    if (wallTypeParameter.AsElementId() != wallType.Id)
                    {
                        wallTypeParameter.Set(wallType.Id);
                    }
                    successfullyUsedExistingWall = true;
                }
            }

            var wall = successfullyUsedExistingWall ? wallElem :
                       Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);

            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }
Exemplo n.º 7
0
        private void InternalSetPosition(Autodesk.Revit.DB.Curve pos)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            var lp = InternalFamilyInstance.Location as Autodesk.Revit.DB.LocationCurve;

            if (lp != null && lp.Curve != pos)
            {
                lp.Curve = pos;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new instance of WallType, deleting the original
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private Wall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var wallElem =
                ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.Wall>(Document);

            bool successfullyUsedExistingWall = false;
            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild 
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
               var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
               if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                   (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc))
               {
                  wallLocation.Curve = curve;

                  Autodesk.Revit.DB.Parameter baseLevelParameter =
                     wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                  Autodesk.Revit.DB.Parameter topOffsetParameter =
                     wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                  Autodesk.Revit.DB.Parameter wallTypeParameter =
                     wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                  if (baseLevelParameter.AsElementId() != baseLevel.Id)
                     baseLevelParameter.Set(baseLevel.Id);
                  if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                     topOffsetParameter.Set(height);
                  if (wallTypeParameter.AsElementId() != wallType.Id)
                     wallTypeParameter.Set(wallType.Id);
                  successfullyUsedExistingWall = true;
               }
            }
 
            var wall = successfullyUsedExistingWall ? wallElem :
                     Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);
            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }
Exemplo n.º 9
0
        private void SelectCurve_Click(object sender, EventArgs e)
        {
            try
            {
                Autodesk.Revit.DB.Reference  eleR  = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Autodesk.Revit.DB.Element    ele   = doc.GetElement(eleR);
                Autodesk.Revit.DB.ModelCurve curve = ele as Autodesk.Revit.DB.ModelCurve;
                crv          = curve.GeometryCurve;
                CurveID.Text = string.Format("Curve: {0}", curve.Id.ToString());
                this.BringToFront();
            }

            catch
            {
                TaskDialog.Show("Error", "Must select a model curve");
                this.BringToFront();
            }
        }
Exemplo n.º 10
0
        private void InternalSetCurve(Autodesk.Revit.DB.Curve crv)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // Updating the curve will cause a document modification event
            // which will be handled by this node and could cause an
            // infinite loop. Check the framing's curve for similarity to the
            // provided curve and update only if the two are different.

            var locCurve = InternalFamilyInstance.Location as Autodesk.Revit.DB.LocationCurve;

            if (locCurve != null && !CurveUtils.CurvesAreSimilar(locCurve.Curve, crv))
            {
                locCurve.Curve = crv;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
Exemplo n.º 11
0
 static Autodesk.Revit.DB.Curve CreateReversedCurve(Autodesk.Revit.DB.Curve orig)
 {
     if (orig is Autodesk.Revit.DB.Line)
     {
         return(Autodesk.Revit.DB.Line.CreateBound(
                    orig.GetEndPoint(1),
                    orig.GetEndPoint(0)));
     }
     else if (orig is Autodesk.Revit.DB.Arc)
     {
         return(Autodesk.Revit.DB.Arc.Create(orig.GetEndPoint(1),
                                             orig.GetEndPoint(0),
                                             orig.Evaluate(0.5, true)));
     }
     else
     {
         throw new Exception(
                   "CreateReversedCurve - Unreachable");
     }
 }
Exemplo n.º 12
0
        public static void SortCurvesContiguous(IList <Autodesk.Revit.DB.Curve> curves)
        {
            int n = curves.Count;

            // Walk through each curve (after the first)
            // to match up the curves in order

            for (int i = 0; i < n; ++i)
            {
                Autodesk.Revit.DB.Curve curve    = curves[i];
                Autodesk.Revit.DB.XYZ   endPoint = curve.GetEndPoint(1);


                Autodesk.Revit.DB.XYZ p;

                // Find curve with start point = end point

                bool found = (i + 1 >= n);

                for (int j = i + 1; j < n; ++j)
                {
                    p = curves[j].GetEndPoint(0);

                    // If there is a match end->start,
                    // this is the next curve

                    if (_sixteenth > p.DistanceTo(endPoint))
                    {
                        if (i + 1 != j)
                        {
                            Autodesk.Revit.DB.Curve tmp = curves[i + 1];
                            curves[i + 1] = curves[j];
                            curves[j]     = tmp;
                        }
                        found = true;
                        break;
                    }

                    p = curves[j].GetEndPoint(1);

                    // If there is a match end->end,
                    // reverse the next curve

                    if (_sixteenth > p.DistanceTo(endPoint))
                    {
                        if (i + 1 == j)
                        {
                            curves[i + 1] = CreateReversedCurve(curves[j]);
                        }
                        else
                        {
                            Autodesk.Revit.DB.Curve tmp = curves[i + 1];
                            curves[i + 1] = CreateReversedCurve(curves[j]);
                            curves[j]     = tmp;
                        }
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    throw new Exception("SortCurvesContiguous:"
                                        + " non-contiguous input curves");
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Construct a detail curve by curve
 /// </summary>
 /// <param name="view">View</param>
 /// <param name="curve">Curve</param>
 private DetailCurve(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Curve curve)
 {
     SafeInit(() => Init(view, curve));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Internal constructor - creates a single StructuralFraming instance
 /// </summary>
 internal StructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.Level level,
                            Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
 {
     SafeInit(() => InitStructuralFraming(curve, level, structuralType, symbol));
 }
Exemplo n.º 15
0
 private static FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
 {
     return(new FamilyInstanceCreationData(curve, symbol, level, structuralType));
 }