Example #1
0
 protected static DB.PropertySetElement FindPropertySetElement(DB.Document doc, string name)
 {
     using (var collector = new DB.FilteredElementCollector(doc).
                            OfClass(typeof(DB.PropertySetElement)).
                            WhereParameterEqualsTo(DB.BuiltInParameter.PROPERTY_SET_NAME, name))
     {
         return(collector.FirstElement() as DB.PropertySetElement);
     }
 }
Example #2
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);
        }