Exemplo n.º 1
0
        /// <summary>
        /// Tag the beam's start and end.
        /// </summary>
        /// <param name="tagMode">Mode of tag</param>
        /// <param name="tagSymbol">Tag symbol wrapper</param>
        /// <param name="leader">Whether the tag has leader</param>
        /// <param name="tagOrientation">Orientation of tag</param>
        public void CreateTag(TagMode tagMode,
                              FamilySymbolWrapper tagSymbol, bool leader,
                              TagOrientation tagOrientation)
        {
            foreach (FamilyInstance beam in m_beamList)
            {
                //Get the start point and end point of the selected beam.
                Autodesk.Revit.DB.LocationCurve location = beam.Location as Autodesk.Revit.DB.LocationCurve;
                Autodesk.Revit.DB.Curve         curve    = location.Curve;

                Transaction t = new Transaction(m_revitDoc.Document);
                t.Start("Create new tag");
                //Create tag on the beam's start and end.
                Reference      beamRef = new Reference(beam);
                IndependentTag tag1    = IndependentTag.Create(m_revitDoc.Document,
                                                               m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(0));
                IndependentTag tag2 = IndependentTag.Create(m_revitDoc.Document,
                                                            m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Update an elements location curve
 /// </summary>
 /// <param name="element"></param>
 /// <param name="curve"></param>
 public static void UpdateLocationCurve(Revit.Elements.Element element, Curve curve)
 {
     if (element.InternalElement.Location.GetType() == typeof(Autodesk.Revit.DB.LocationCurve))
     {
         Autodesk.Revit.DB.LocationCurve pt = (Autodesk.Revit.DB.LocationCurve)element.InternalElement.Location;
         pt.Curve = curve.ToRevitType(true);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="wall"></param>
        /// <returns></returns>
        private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, Wall wall)
        {
            Revit.LocationCurve locCurve = wall.Location as Revit.LocationCurve;
            bool isStructural            = (wall.StructuralUsage == StructuralWallUsage.NonBearing) ? false : true;
            Wall wallClone = Wall.Create(app.ActiveUIDocument.Document, locCurve.Curve, wall.LevelId, isStructural);

            Utils.ParamUtil.SetParameters(wallClone.Parameters, wall.Parameters);
            return(wallClone);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Update an elements location curve
 /// </summary>
 /// <param name="element"></param>
 /// <param name="curve"></param>
 public static void UpdateLocationCurve(Revit.Elements.Element element, Curve curve)
 {
     if (element.InternalElement.Location.GetType() == typeof(Autodesk.Revit.DB.LocationCurve))
     {
         Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
         TransactionManager.Instance.EnsureInTransaction(document);
         Autodesk.Revit.DB.LocationCurve pt = (Autodesk.Revit.DB.LocationCurve)element.InternalElement.Location;
         pt.Curve = curve.ToRevitType(true);
         TransactionManager.Instance.TransactionTaskDone();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Frame a Wall
        /// </summary>
        /// <param name="rvtApp">Revit application></param>
        /// <param name="wall">Wall as host to place column objects</param>
        /// <param name="spacing">spacing between two columns</param>
        /// <param name="columnType">column type</param>
        private void FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall,
                               double spacing, Autodesk.Revit.DB.FamilySymbol columnType)
        {
            Autodesk.Revit.DB.Document rvtDoc = wall.Document;

            // get wall location
            Autodesk.Revit.DB.LocationCurve loc     = (Autodesk.Revit.DB.LocationCurve)wall.Location;
            Autodesk.Revit.DB.XYZ           startPt = loc.Curve.GetEndPoint(0);
            Autodesk.Revit.DB.XYZ           endPt   = loc.Curve.GetEndPoint(1);

            // get wall's vector
            Autodesk.Revit.DB.UV wallVec = new Autodesk.Revit.DB.UV(
                endPt.X - startPt.X,
                endPt.Y - startPt.Y);

            // get the axis vector
            Autodesk.Revit.DB.UV axis = new Autodesk.Revit.DB.UV(1.0, 0.0);

            Autodesk.Revit.DB.ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
            Autodesk.Revit.DB.ElementId topLevelId  = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

            // get wall length and vector
            double wallLength = wallVec.GetLength();

            wallVec = wallVec.Normalize();

            // get # of column
            int nmax = (int)(wallLength / spacing);

            TaskDialog.Show("Revit", "wallLength = " + wallLength + "\r\nspacing = " + spacing.ToString() + "\r\nnmax = " + nmax.ToString());

            // get angle of wall and axis
            double angle = wallVec.AngleTo(axis);

            // place all column
            Autodesk.Revit.DB.XYZ loc2 = startPt;
            double dx = wallVec.U * spacing;
            double dy = wallVec.V * spacing;

            for (int i = 0; i < nmax; i++)
            {
                PlaceColumn(rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId);

                loc2 = new XYZ(loc2.X + dx,
                               loc2.Y + dy,
                               loc2.Z);
            }

            // place column at end point of wall
            PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId);
        }
Exemplo n.º 6
0
        public static global::Revit.Elements.Element AreaLocation(global::Revit.Elements.Element element)
        {
            //the current document
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //the internal element
            Autodesk.Revit.DB.Element internalElement = element.InternalElement;
            //list to append area locations to
            List <global::Revit.Elements.Element> areaLocations = new List <global::Revit.Elements.Element>();

            //ptlocation to append to
            Autodesk.DesignScript.Geometry.Point ptLocation = null;
            //figure out the location of the given element
            if (internalElement.Location is LocationPoint pt)
            {
                ptLocation = pt.Point.ToPoint(true);
            }
            else if (internalElement.Location is Autodesk.Revit.DB.LocationCurve)
            {
                Autodesk.Revit.DB.LocationCurve curve = internalElement.Location as Autodesk.Revit.DB.LocationCurve;
                ptLocation = curve.Curve.Evaluate(0.5, true).ToPoint(true);
            }
            else
            {
                throw new Exception(@"This element's location is not supported for this operation. ¯\_(ツ)_/¯ ");
            }

            var allViews = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                           .OfClass(typeof(Autodesk.Revit.DB.View))
                           .Cast <Autodesk.Revit.DB.View>()
                           .Where(x => x.ViewType == ViewType.AreaPlan && !x.IsTemplate)
                           .ToList();


            //collect the areas to do some cool stuff
            FilteredElementCollector          areaColl = new FilteredElementCollector(doc);
            IList <Autodesk.Revit.DB.Element> areas    = areaColl.OfCategory(BuiltInCategory.OST_Areas).ToElements();

            foreach (Autodesk.Revit.DB.Element area in areas)
            {
                View        view = allViews.First(v => v.GenLevel.Id.IntegerValue == area.LevelId.IntegerValue);
                BoundingBox bBox = area.get_BoundingBox(view).ToProtoType();
                if (bBox.Contains(ptLocation) && area.LevelId.IntegerValue == internalElement.LevelId.IntegerValue)
                {
                    areaLocations.Add(area.ToDSType(true));
                }
            }

            global::Revit.Elements.Element elem = areaLocations.First(a => a.GetLocation().DistanceTo(ptLocation) == areaLocations.Min(e => e.GetLocation().DistanceTo(ptLocation)));

            return(elem);
        }
Exemplo n.º 7
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);
     }
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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();
        }