Exemple #1
0
        /// <summary>
        /// Initialize a ModelText element
        /// </summary>
        /// <param name="text"></param>
        /// <param name="sketchPlane"></param>
        /// <param name="xCoordinateInPlane"></param>
        /// <param name="yCoordinateInPlane"></param>
        /// <param name="textDepth"></param>
        /// <param name="modelTextType"></param>
        private void InitModelText(string text, Autodesk.Revit.DB.SketchPlane sketchPlane,
                                   double xCoordinateInPlane, double yCoordinateInPlane, double textDepth,
                                   Autodesk.Revit.DB.ModelTextType modelTextType)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ModelText>(Document);


            // Note: not sure if there's a way to mutate the sketchPlane for a ModelText, so we need
            // to insure the Element hasn't changed position, otherwise, we destroy and rebuild the Element
            if (oldEle != null && PositionUnchanged(oldEle, sketchPlane, xCoordinateInPlane, yCoordinateInPlane))
            {
                // There was an element and it's position hasn't changed
                InternalSetModelText(oldEle);
                InternalSetText(text);
                InternalSetDepth(textDepth);
                InternalSetModelTextType(modelTextType);
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            // We have to clean up the old ModelText b/c we can't mutate it's position
            if (oldEle != null)
            {
                DocumentManager.Instance.DeleteElement(new ElementUUID(oldEle.UniqueId));
            }

            var mt = CreateModelText(text, sketchPlane, xCoordinateInPlane, yCoordinateInPlane, textDepth, modelTextType);

            InternalSetModelText(mt);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Exemple #2
0
 public static ModelTextType Wrap(Autodesk.Revit.DB.ModelTextType ele, bool isRevitOwned)
 {
     return(ModelTextType.FromExisting(ele, isRevitOwned));
 }
 /// <summary>
 /// Internal constructor for the ModelText
 /// </summary>
 /// <param name="text"></param>
 /// <param name="sketchPlane"></param>
 /// <param name="xCoordinateInPlane"></param>
 /// <param name="yCoordinateInPlane"></param>
 /// <param name="textDepth"></param>
 /// <param name="modelTextType"></param>
 private ModelText(string text, Autodesk.Revit.DB.SketchPlane sketchPlane, double xCoordinateInPlane,
                   double yCoordinateInPlane, double textDepth, Autodesk.Revit.DB.ModelTextType modelTextType)
 {
     SafeInit(() => InitModelText(text, sketchPlane, xCoordinateInPlane, yCoordinateInPlane, textDepth, modelTextType));
 }
        /// <summary>
        /// Create a ModelText element in the current Family Document
        /// </summary>
        /// <param name="text"></param>
        /// <param name="sketchPlane"></param>
        /// <param name="xCoordinateInPlane"></param>
        /// <param name="yCoordinateInPlane"></param>
        /// <param name="textDepth"></param>
        /// <param name="modelTextType"></param>
        /// <returns></returns>
        private static Autodesk.Revit.DB.ModelText CreateModelText(string text, Autodesk.Revit.DB.SketchPlane sketchPlane, double xCoordinateInPlane, double yCoordinateInPlane, double textDepth, Autodesk.Revit.DB.ModelTextType modelTextType)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // obtain the position of the ModelText element in the plane of the sketchPlane
            var plane = sketchPlane.GetPlane();
            var pos   = plane.Origin + plane.XVec * xCoordinateInPlane + plane.YVec * yCoordinateInPlane;

            // create the modeltext
            var mt = Document.FamilyCreate.NewModelText(text, modelTextType, sketchPlane, pos, HorizontalAlign.Left, textDepth);

            TransactionManager.Instance.TransactionTaskDone();

            return(mt);
        }