コード例 #1
0
        /// <summary>
        /// Determines whether a view with the provided name already exists.
        /// If a view exists with the provided name, and new view is created with
        /// a unique name. Otherwise, the original view name is returned.
        /// </summary>
        /// <param name="name"></param>
        /// <returns>The original name if it is already unique, or
        /// a unique version of the name.</returns>
        public static string CreateUniqueViewName(string name)
        {
            var collector = new FilteredElementCollector(Document);

            collector.OfClass(typeof(Autodesk.Revit.DB.View));

            // If the name is already unique then return it.
            if (collector.All(x => x.Name != name))
            {
                return(name);
            }

            // Create a unique name by appending a guid to
            // the end of the view name
            var viewName = $"{name}_{Guid.NewGuid()}";

            return(viewName);
        }