Ejemplo n.º 1
0
        public static Revit.Elements.Element GetStartingView()
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;
            StartingViewSettings startingViewSettings = StartingViewSettings.GetStartingViewSettings(doc);
            View finalView = doc.GetElement(startingViewSettings.ViewId) as View;

            Revit.Elements.Element view = finalView.ToDSType(true);
            return(view);
        }
Ejemplo n.º 2
0
        public static object SetStartingView(Revit.Elements.Element View)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            if (doc.IsFamilyDocument)
            {
                return(new Exception("This node cannot be used on a Family Document. It may only be used on Projects or Project Templates."));
            }
            ElementId            searcher             = Spring.Elements.UnwrapElement(View);
            View                 finalView            = doc.GetElement(searcher) as View;
            StartingViewSettings startingViewSettings = StartingViewSettings.GetStartingViewSettings(doc);

            if (finalView.Id == startingViewSettings.ViewId)
            {
                return("Starting View is the same as input.");
            }
            else
            {
                try
                {
                    if (startingViewSettings.ViewId.Equals(ElementId.InvalidElementId))
                    {
                        throw new Exception("The Document's existing Starting View is invalid.");
                    }
                    else if (finalView.ViewType != ViewType.ThreeD &&
                             finalView.ViewType != ViewType.FloorPlan &&
                             finalView.ViewType != ViewType.AreaPlan &&
                             finalView.ViewType != ViewType.CeilingPlan &&
                             finalView.ViewType != ViewType.Detail &&
                             finalView.ViewType != ViewType.DraftingView &&
                             finalView.ViewType != ViewType.Elevation &&
                             finalView.ViewType != ViewType.EngineeringPlan &&
                             finalView.ViewType != ViewType.Section &&
                             finalView.ViewType != ViewType.Schedule
                             )
                    {
                        throw new Exception("The View passed in to the node is not a valid type of view to set as a Starting View.");
                    }
                    else if (finalView.IsTemplate)
                    {
                        throw new Exception("The View passed in to the node is a View Template. This is not a valid view.");
                    }
                    else
                    {
                        // If valid, then set the viewId
                        startingViewSettings.ViewId = searcher;
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 3
0
 public static string SetStartingView(Autodesk.Revit.DB.Document sourceDocument, global::Revit.Elements.Element view)
 {
     try
     {
         TransactionManager.Instance.EnsureInTransaction(sourceDocument);
         StartingViewSettings.GetStartingViewSettings(sourceDocument).ViewId = view.InternalElement.Id;
         TransactionManager.Instance.TransactionTaskDone();
         return("Success");
     }
     catch
     {
         return("Failure");
     }
 }
Ejemplo n.º 4
0
        public static bool SetStartingView(this Document doc, View view)
        {
            var startViewSettings = StartingViewSettings.GetStartingViewSettings(doc);

            if (startViewSettings.IsAcceptableStartingView(view.Id))
            {
                using (var transaction = new Transaction(doc, "Установка стартового вида"))
                {
                    transaction.Start();
                    startViewSettings.ViewId = view.Id;
                    transaction.Commit();
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This node will set the starting view of the document, given the view element.
        /// </summary>
        /// <param name="sourceDocument">The background opened document object, (preferably this is the title as obtained with Applications.OpenDocumentFile from Rhythm).</param>
        /// <param name="view">The view to set.</param>
        /// <returns name="result">The result.</returns>
        /// <search>
        /// startingView
        /// </search>
        public static string SetStartingView(object sourceDocument, global::Revit.Elements.Element view)
        {
            string   result    = null;
            Document sourceDoc = DocumentUtils.RetrieveDocument(sourceDocument);

            try
            {
                TransactionManager.Instance.EnsureInTransaction(sourceDoc);
                StartingViewSettings.GetStartingViewSettings(sourceDoc).ViewId = view.InternalElement.Id;
                TransactionManager.Instance.TransactionTaskDone();
                result = "Success";
            }
            catch
            {
                result = "Failure";
            }
            return(result);
        }
Ejemplo n.º 6
0
        public bool ValidateModel(Document doc, ref string report, IEnumerable <AddInsParameter> parameters)
        {
            report += "Проерка начального вида";
            if (!VerifyValidationParameters(parameters))
            {
                report += $"\nПараметры проверки не прошли проверку";
                return(false);
            }

            var onServerFamily = new FileInfo(Settings.PathToFamilyIntoServer);
            var familyName     = onServerFamily.Name.Replace(".rfa", string.Empty);
            var family         = doc.GetFirstClassAndNameRelatedInstance <Family>(familyName);
            var views          = doc.GetClassAndNameRelatedInstance <View>(Settings.ViewName);

            if (views.Count() > 1)
            {
                report += $"\n В проекте существуется больше одного вида с именем \"{Settings.ViewName}\", удалите ненужные виды";
                HaveViewWithSameName = true;
                return(false);
            }
            var view = views.Count() == 1 ? views.First() : null;

            FamilyLoaded    = !(family == null);
            ViewExist       = !(view == null);
            ViewTypeCorrect = ((view is ViewSheet) && Settings.ViewType == "Лист" || ((view is ViewPlan) && Settings.ViewType == "Вид"));
            var startViewSettings = StartingViewSettings.GetStartingViewSettings(doc);

            StartingViewSettedCorrect = (ViewExist && view.Id == startViewSettings.ViewId);

            if (FamilyLoaded && ViewExist)
            {
                var collector = (new FilteredElementCollector(doc)).OwnedByView(view.Id).OfClass(typeof(FamilyInstance)).Cast <FamilyInstance>().Where(c => c.Symbol.Family.Id == family.Id);
                FamilyExistOnView = collector.Count() > 0;
            }

            report          += $"\n\t Семество найдено - {FamilyLoaded}";
            report          += $"\n\t Вид создан - {ViewExist}";
            report          += $"\n\t Тип вида соответствует требованиям - {ViewTypeCorrect}";
            report          += $"\n\t Семейство размещено на виде - {FamilyExistOnView}";
            report          += $"\n\t Начальный вид установлен верно -{StartingViewSettedCorrect}";
            IsModelValidated = true;
            return(FamilyLoaded && ViewExist && ViewTypeCorrect && FamilyExistOnView && StartingViewSettedCorrect);
        }