Example #1
0
        public new void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            //Ensure that the object is still alive
            if (!IsAlive)
            {
                return;
            }

            //Location Point
            DB.LocationPoint locPoint = InternalElement.Location as DB.LocationPoint;
            GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(locPoint.Point)).Tessellate(package, parameters);
            package.ApplyPointVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, 255, 0, 0, 0));

            //Boundaries
            foreach (DB.BoundarySegment segment in InternalBoundarySegments)
            {
                Curve crv = RevitToProtoCurve.ToProtoType(segment.GetCurve().CreateTransformed(InternalTransform));

                crv.Tessellate(package, parameters);

                if (package.LineVertexCount > 0)
                {
                    package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, 255, 0, 0, 0));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Determine if an element lies
        /// within the volume of the Space
        /// </summary>
        public bool IsInSpace(Element element)
        {
            DB.FamilyInstance familyInstance = element.InternalElement as DB.FamilyInstance;
            if (familyInstance != null)
            {
                if (familyInstance.HasSpatialElementCalculationPoint)
                {
                    DB.XYZ insertionPoint = familyInstance.GetSpatialElementCalculationPoint();

                    if (InternalSpace.IsPointInSpace(insertionPoint))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            DB.LocationPoint insertionLocationPoint = element.InternalElement.Location as DB.LocationPoint;
            if (insertionLocationPoint != null)
            {
                DB.XYZ insertionPoint = insertionLocationPoint.Point;

                if (InternalSpace.IsPointInSpace(insertionPoint))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
 /// <summary>
 /// Update an elements location Point
 /// </summary>
 /// <param name="element"></param>
 /// <param name="point"></param>
 public static void UpdateLocationPoint(Revit.Elements.Element element, Point point)
 {
     if (element.InternalElement.Location.GetType() == typeof(Autodesk.Revit.DB.LocationPoint))
     {
         Autodesk.Revit.DB.LocationPoint pt = (Autodesk.Revit.DB.LocationPoint)element.InternalElement.Location;
         pt.Point = point.ToRevitType(true);
     }
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="roomTag"></param>
        /// <returns></returns>
        private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, Autodesk.Revit.DB.Architecture.RoomTag roomTag)
        {
            Revit.LocationPoint locationPoint = roomTag.Location as Revit.LocationPoint;
            UV      point        = new UV(locationPoint.Point.X, locationPoint.Point.Y);
            RoomTag roomTagClone = null;//app.ActiveUIDocument.Document.Create.NewRoomTag(roomTag.Room, ref point, );

            Utils.ParamUtil.SetParameters(roomTagClone.Parameters, roomTag.Parameters);
            return(roomTagClone);
        }
Example #5
0
        internal static List <revitViewport> _renumberViewsOnSheet(FamilyType familyType, string xGridName, string yGridName, revitSheet rSheet, revitDoc document)
        {
            string transactionName = "Renumber views on sheet";

            //  Initialize variables
            revitFamilySymbol rFamilySymbol = (revitFamilySymbol)familyType.InternalElement;

            //  Get all viewport ID's on the sheet.
            List <revitElemId>   viewportIds = (List <revitElemId>)rSheet.GetAllViewports();
            List <revitViewport> viewports   = null;

            //  Get the family Instances in view
            revitElemId symbolId = familyType.InternalElement.Id;

            revitCollector     collector      = new revitCollector(document, rSheet.Id);
            revitElementFilter filterInstance = new revitDB.FamilyInstanceFilter(document, symbolId);

            collector.OfClass(typeof(revitDB.FamilyInstance)).WherePasses(filterInstance);

            revitDB.FamilyInstance originFamily = (revitDB.FamilyInstance)collector.FirstElement();

            //  If family instance is found in the view
            //  Then renumber views.
            if (originFamily != null)
            {
                revitDB.LocationPoint location = (revitDB.LocationPoint)originFamily.Location;
                revitXYZ originPoint           = location.Point;

                double gridX = rFamilySymbol.LookupParameter(xGridName).AsDouble();
                double gridY = rFamilySymbol.LookupParameter(yGridName).AsDouble();

                //  If the document is modifieable,
                //  then a transaction is already open
                //  and function uses the Dynamo Transaction Manager.
                //  Else, open a new transaction.
                if (document.IsModifiable)
                {
                    TransactionManager.Instance.EnsureInTransaction(document);
                    viewports = View._tempRenumberViewports(viewportIds, document);
                    viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y);
                    TransactionManager.Instance.TransactionTaskDone();
                }
                else
                {
                    using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                    {
                        trans.Start(transactionName);
                        viewports = View._tempRenumberViewports(viewportIds, document);
                        viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y);
                        trans.Commit();
                    }
                }
            }

            return(viewports);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="room"></param>
        /// <returns></returns>
        private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, Autodesk.Revit.DB.Architecture.Room room)
        {
            Revit.LocationPoint locationPoint = room.Location as Revit.LocationPoint;
            UV point = new UV(locationPoint.Point.X, locationPoint.Point.Y);

            Room roomClone = app.ActiveUIDocument.Document.Create.NewRoom((Level)room.Document.GetElement(room.LevelId), point);

            Utils.ParamUtil.SetParameters(roomClone.Parameters, room.Parameters);
            return(roomClone);
        }
Example #7
0
 /// <summary>
 /// Update an elements location Point
 /// </summary>
 /// <param name="element"></param>
 /// <param name="point"></param>
 public static void UpdateLocationPoint(Revit.Elements.Element element, Point point)
 {
     if (element.InternalElement.Location.GetType() == typeof(Autodesk.Revit.DB.LocationPoint))
     {
         Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
         TransactionManager.Instance.EnsureInTransaction(document);
         Autodesk.Revit.DB.LocationPoint pt = (Autodesk.Revit.DB.LocationPoint)element.InternalElement.Location;
         pt.Point = point.ToRevitType(true);
         TransactionManager.Instance.TransactionTaskDone();
     }
 }
Example #8
0
 /// <summary>
 /// Get an exsiting element's location
 /// </summary>
 /// <returns>Location Geometry</returns>
 public Geometry GetLocation()
 {
     if (this.InternalElement.Location is Autodesk.Revit.DB.LocationPoint)
     {
         Autodesk.Revit.DB.LocationPoint pt = this.InternalElement.Location as Autodesk.Revit.DB.LocationPoint;
         return(pt.Point.ToPoint(true));
     }
     else if (this.InternalElement.Location is Autodesk.Revit.DB.LocationCurve)
     {
         Autodesk.Revit.DB.LocationCurve curve = this.InternalElement.Location as Autodesk.Revit.DB.LocationCurve;
         return(curve.Curve.ToProtoType(true));
     }
     else
     {
         throw new Exception(Properties.Resources.InvalidElementLocation);
     }
 }
Example #9
0
        private void Init(Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.XYZ location, string name, string number)
        {
            // Get document and open transaction
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            // Get existing room element if possible
            var RoomElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Architecture.Room>(document);

            if (RoomElem == null)
            {
                // Create new Room element
                RoomElem = document.Create.NewRoom(level, new Autodesk.Revit.DB.UV(location.X, location.Y));
            }
            else
            {
                if (RoomElem.LevelId.Equals(level.Id))
                {
                    // Update Location only
                    Autodesk.Revit.DB.LocationPoint point = (Autodesk.Revit.DB.LocationPoint)RoomElem.Location;
                    point.Point = location;
                }
                else
                {
                    RoomElem = document.Create.NewRoom(level, new Autodesk.Revit.DB.UV(location.X, location.Y));
                }
            }

            // Apply name and number if set
            if (!string.IsNullOrEmpty(name))
            {
                RoomElem.Name = name;
            }

            if (!string.IsNullOrEmpty(number))
            {
                RoomElem.Number = number;
            }

            InternalSetElement(RoomElem);

            // Commit transaction
            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #10
0
        private void Init(Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.XYZ location, string name, string number)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // Get existing space element if possible
            var spaceElement = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Mechanical.Space>(Document);

            if (spaceElement == null)
            {
                // Create new Space element
                spaceElement = Document.Create.NewSpace(level, new Autodesk.Revit.DB.UV(location.X, location.Y));
            }
            else
            {
                if (spaceElement.LevelId.Equals(level.Id))
                {
                    // Update Location only
                    Autodesk.Revit.DB.LocationPoint point = (Autodesk.Revit.DB.LocationPoint)spaceElement.Location;
                    point.Point = location;
                }
                else
                {
                    spaceElement = Document.Create.NewSpace(level, new Autodesk.Revit.DB.UV(location.X, location.Y));
                }
            }

            // Apply name and number if set
            if (!string.IsNullOrEmpty(name))
            {
                spaceElement.Name = name;
            }

            if (!string.IsNullOrEmpty(number))
            {
                spaceElement.Number = number;
            }

            InternalSetElement(spaceElement);

            // Commit transaction
            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="familyInstance"></param>
        /// <returns></returns>
        private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, FamilyInstance familyInstance)
        {
            XYZ location = new XYZ();

            // special case for something like a beam system which has a curve
            Revit.LocationCurve locationCurve = familyInstance.Location as Revit.LocationCurve;
            if (locationCurve != null)
            {
                location = locationCurve.Curve.GetEndPoint(0);
            }
            Revit.LocationPoint locationPoint = familyInstance.Location as Revit.LocationPoint;
            if (locationPoint != null)
            {
                location = locationPoint.Point;
            }

            FamilyInstance familyInstanceClone = app.ActiveUIDocument.Document.Create.NewFamilyInstance(location, familyInstance.Symbol, familyInstance.StructuralType);

            Utils.ParamUtil.SetParameters(familyInstanceClone.Parameters, familyInstance.Parameters);
            return(familyInstanceClone);
        }
Example #12
0
        /// <summary>
        /// Update an existing element's location
        /// </summary>
        /// <param name="geometry">New Location Point or Curve</param>
        public void SetLocation(Geometry geometry)
        {
            TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument);

            if (this.InternalElement.Location is Autodesk.Revit.DB.LocationPoint)
            {
                if (geometry is Autodesk.DesignScript.Geometry.Point)
                {
                    Autodesk.DesignScript.Geometry.Point point = geometry as Autodesk.DesignScript.Geometry.Point;
                    Autodesk.Revit.DB.LocationPoint      pt    = this.InternalElement.Location as Autodesk.Revit.DB.LocationPoint;
                    pt.Point = point.ToRevitType(true);
                }
                else
                {
                    throw new Exception(Properties.Resources.PointRequired);
                }
            }
            else if (this.InternalElement.Location is Autodesk.Revit.DB.LocationCurve && geometry is Curve)
            {
                if (geometry is Curve)
                {
                    Curve dynamoCurve = geometry as Curve;
                    Autodesk.Revit.DB.LocationCurve curve = this.InternalElement.Location as Autodesk.Revit.DB.LocationCurve;
                    curve.Curve = dynamoCurve.ToRevitType(true);
                }
                else
                {
                    throw new Exception(Properties.Resources.CurveRequired);
                }
            }
            else
            {
                throw new Exception(Properties.Resources.InvalidElementLocation);
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
        /// <summary>
        /// Run this sample
        /// </summary>
        public void Run()
        {
            RotateFramingObjectsForm displayForm = new RotateFramingObjectsForm(this);
            ElementSet selection = new ElementSet();
            ICollection <ElementId> sel;

            foreach (ElementId elementid in m_doc.Selection.GetElementIds())
            {
                selection.Insert(m_doc.Document.GetElement(elementid));
            }

            bool isSingle            = true;              //selection is single object
            bool isAllFamilyInstance = true;              //all is not familyInstance

            // There must be beams, braces or columns selected
            if (selection.IsEmpty)
            {
                // nothing selected
                MessageBox.Show("Please select FamilyInstance.(such as column)", "RotateFramingObjects");
                return;
            }
            else if (1 != selection.Size)
            {
                isSingle = false;
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }
                //	return IExternalCommand.Result.Succeeded;
                // more that one object selected
            }

            // if the selection are familyInstance, try to get their existing rotation
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent != null)
                {
                    if (Autodesk.Revit.DB.Structure.StructuralType.Beam == familyComponent.StructuralType ||
                        Autodesk.Revit.DB.Structure.StructuralType.Brace == familyComponent.StructuralType)
                    {
                        // selection is a beam or brace
                        string returnValue = this.FindParameter("Angle", familyComponent);
                        displayForm.rotationTextBox.Text = returnValue.ToString();
                    }
                    else if (Autodesk.Revit.DB.Structure.StructuralType.Column == familyComponent.StructuralType)
                    {
                        // selection is a column
                        Autodesk.Revit.DB.Location      columnLocation = familyComponent.Location;
                        Autodesk.Revit.DB.LocationPoint pointLocation  = columnLocation as Autodesk.Revit.DB.LocationPoint;
                        double temp   = pointLocation.Rotation;
                        string output = (Math.Round(temp * 180 / (Math.PI), 3)).ToString();
                        displayForm.rotationTextBox.Text = output;
                    }
                    else
                    {
                        // other familyInstance can not be rotated
                        MessageBox.Show("Can not deal with it.", "RotateFramingObjects");
                        sel = m_doc.Selection.GetElementIds();
                        sel.Add(familyComponent.Id);
                        m_doc.Selection.SetElementIds(sel);
                        return;
                    }
                }
                else
                {
                    if (isSingle)
                    {
                        MessageBox.Show("It is a Non-FamilyInstance.", "RotateFramingObjects");
                        sel = m_doc.Selection.GetElementIds();
                        sel.Add(e.Id);
                        m_doc.Selection.SetElementIds(sel);
                        return;
                    }
                    // there is some objects is not familyInstance
                    //MessageBox.Show("There is Non-FamilyInstance.", "RotateFramingObjects");
                    sel = m_doc.Selection.GetElementIds();
                    sel.Add(e.Id);
                    m_doc.Selection.SetElementIds(sel);
                    isAllFamilyInstance = false;
                }
            }


            if (isSingle)
            {
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            if (isAllFamilyInstance)
            {
                return;
            }
            else
            {
                //output error information
                return;
            }
        }
        /// <summary>
        /// The function set value to rotation of the beams and braces
        /// and rotate columns.
        /// </summary>
        public void RotateElement()
        {
            ElementSet selection = new ElementSet();

            foreach (ElementId elementid in m_doc.Selection.GetElementIds())
            {
                selection.Insert(m_doc.Document.GetElement(elementid));
            }
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent == null)
                {
                    //is not a familyInstance
                    continue;
                }
                // if be familyInstance,judge the types of familyInstance
                if (Autodesk.Revit.DB.Structure.StructuralType.Beam == familyComponent.StructuralType ||
                    Autodesk.Revit.DB.Structure.StructuralType.Brace == familyComponent.StructuralType)
                {
                    // selection is a beam or Brace
                    ParameterSetIterator j = familyComponent.Parameters.ForwardIterator();
                    j.Reset();

                    bool jMoreAttribute = j.MoveNext();
                    while (jMoreAttribute)
                    {
                        object    a = j.Current;
                        Parameter objectAttribute = a as Parameter;
                        //set generic property named ¡°Angle¡±
                        int p = objectAttribute.Definition.Name.CompareTo("Angle");
                        if (0 == p)
                        {
                            Double temp         = objectAttribute.AsDouble();
                            double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
                            if (!m_isAbsoluteChecked)
                            {
                                // absolute rotation
                                rotateDegree += temp;
                            }
                            objectAttribute.Set(rotateDegree);
                            // relative rotation
                        }

                        jMoreAttribute = j.MoveNext();
                    }
                }
                else if (Autodesk.Revit.DB.Structure.StructuralType.Column == familyComponent.StructuralType)
                {
                    // rotate a column
                    Autodesk.Revit.DB.Location columnLocation = familyComponent.Location;
                    // get the location object
                    Autodesk.Revit.DB.LocationPoint pointLocation = columnLocation as Autodesk.Revit.DB.LocationPoint;
                    Autodesk.Revit.DB.XYZ           insertPoint   = pointLocation.Point;
                    // get the location point
                    double temp = pointLocation.Rotation;
                    //existing rotation
                    XYZ directionPoint = m_doc.Document.Application.Create.NewXYZ(0, 0, 1);
                    // define the vector of axis
                    Autodesk.Revit.DB.Line rotateAxis = Line.CreateBound(insertPoint, directionPoint);
                    double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
                    // rotate column by rotate method
                    if (m_isAbsoluteChecked)
                    {
                        rotateDegree -= temp;
                    }
                    bool rotateResult = pointLocation.Rotate(rotateAxis, rotateDegree);
                    if (rotateResult == false)
                    {
                        MessageBox.Show("Rotate Failed.");
                    }
                }
            }
        }