Hi @Mariam.EmadLHT4U
I wrote a custom method which will create multiple views, I have done it in Generic way. You can modify it according to your input. Kindly check the below code snippet for additional reference.
Custom Method for View Creation
public List<ViewPlan> CreateMultipleViewPlan(Document doc,int numberOfView, ElementId levelId, ElementId viewFamilyTypeId,out string errorMessage)
{
errorMessage = string.Empty;
List<ViewPlan>views=new List<ViewPlan>();
Transaction createViews = new Transaction(doc, "Create Multiple View");
createViews.Start();
try
{
for (int i = 0; i < numberOfView; i++)
{
views.Add(ViewPlan.Create(doc, viewFamilyTypeId, levelId));
}
createViews.Commit();
createViews.Dispose();
}
catch (Exception ex)
{
errorMessage=ex.Message;
createViews.RollBack();
createViews.Dispose();
views = null;
}
return views;
}
Complete Implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Architecture;
namespace Forum_Answering
{
[Transaction(TransactionMode.Manual)]
public class MultipleViewCreation : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
ElementId viewFamilyTypeId = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.FirstElementId();
ElementId levelId= new FilteredElementCollector(doc)
.OfClass(typeof(Level))
.FirstElementId();
CreateMultipleViewPlan(doc, 3, levelId, viewFamilyTypeId, out string errorMessage);
return Result.Succeeded;
}
public List<ViewPlan> CreateMultipleViewPlan(Document doc,int numberOfView, ElementId levelId, ElementId viewFamilyTypeId,out string errorMessage)
{
errorMessage = string.Empty;
List<ViewPlan>views=new List<ViewPlan>();
Transaction createViews = new Transaction(doc, "Create Multiple View");
createViews.Start();
try
{
for (int i = 0; i < numberOfView; i++)
{
views.Add(ViewPlan.Create(doc, viewFamilyTypeId, levelId));
}
createViews.Commit();
createViews.Dispose();
}
catch (Exception ex)
{
errorMessage=ex.Message;
createViews.RollBack();
createViews.Dispose();
views = null;
}
return views;
}
}
}
Plugin Demo Video
Hope this will Helps 🙂
Mohamed Arshad K
Software Developer (CAD & BIM)