Example #1
0
 /// <summary>
 /// Create from an existign Revit element
 /// </summary>
 /// <param name="wallType"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static WallType FromExisting(Autodesk.Revit.DB.WallType wallType, bool isRevitOwned)
 {
     return(new WallType(wallType)
     {
         IsRevitOwned = isRevitOwned
     });
 }
Example #2
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);
        }
Example #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(
                Convert.ToDouble(txtX1.Text.Trim()),
                Convert.ToDouble(txtY1.Text.Trim()),
                Convert.ToDouble(txtZ1.Text.Trim()));

            Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(
                Convert.ToDouble(txtX2.Text.Trim()),
                Convert.ToDouble(txtY2.Text.Trim()),
                Convert.ToDouble(txtZ2.Text.Trim()));

            if (startPoint.Equals(endPoint))
            {
                Autodesk.Revit.UI.TaskDialog.Show("Revit", "Start point should not equal end point.");
                return;
            }

            double diff = Math.Abs(startPoint.Z - endPoint.Z);

            if (diff > Precision)
            {
                Autodesk.Revit.UI.TaskDialog.Show("Revit", "Z coordinate of start and end points should be equal.");
                return;
            }

            Autodesk.Revit.DB.Level level = cmbLevel.SelectedItem as Autodesk.Revit.DB.Level; // level information
            if (null == level)                                                                // assert it isn't null
            {
                Autodesk.Revit.UI.TaskDialog.Show("Revit", "The selected level is null or incorrect.");
                return;
            }

            Autodesk.Revit.DB.WallType type = cmbType.SelectedItem as Autodesk.Revit.DB.WallType; // wall type
            if (null == type)                                                                     // assert it isn't null
            {
                Autodesk.Revit.UI.TaskDialog.Show("Revit", "The selected wall type is null or incorrect.");
                return;
            }

            // Invoke SetNecessaryData method to set the collected support data
            m_dataBuffer.SetNecessaryData(startPoint, endPoint, level, type);

            // Set result information and close the form
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #4
0
 /// <summary>
 /// Set the internal Element, ElementId, and UniqueId
 /// </summary>
 /// <param name="wallType"></param>
 private void InternalSetWallType(Autodesk.Revit.DB.WallType wallType)
 {
     this.InternalWallType  = wallType;
     this.InternalElementId = wallType.Id;
     this.InternalUniqueId  = wallType.UniqueId;
 }
Example #5
0
 /// <summary>
 /// Initialize a WallType element
 /// </summary>
 /// <param name="type"></param>
 private void InitWallType(Autodesk.Revit.DB.WallType type)
 {
     InternalSetWallType(type);
 }
Example #6
0
 /// <summary>
 /// Construct from an existing Revit Element
 /// </summary>
 /// <param name="type"></param>
 private WallType(Autodesk.Revit.DB.WallType type)
 {
     SafeInit(() => InitWallType(type));
 }