Revit macro: Create copies of current view with applying different filters and view templates
This macro creates copies of the current view with automatic renaming and assignment of filters and templates. In this particular case, it creates 2 reinforcement layout plans, showing only the top or bottom reinforcement in the slab on each sheet.
Before use, it is necessary to correct the names of the filters and the view template in accordance with existing in the current project.
Macro:
Using of macro:
Open the view that you want to copy, run the macro and get 2 copies of this view with new names and the applied filters of visibility and the view template.
Before use, it is necessary to correct the names of the filters and the view template in accordance with existing in the current project.
Macro:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Created by SharpDevelop. | |
* User: Nikolai | |
* Date: 28-Sep-19 | |
* Time: 13:46 | |
* | |
* To change this template use Tools | Options | Coding | Edit Standard Headers. | |
*/ | |
using System; | |
using Autodesk.Revit.UI; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.UI.Selection; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace DublicateView | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.DB.Macros.AddInId("478D7406-4536-430D-94AE-C02BDD106075")] | |
public partial class ThisDocument | |
{ | |
//Переопределить названия в соответствии с шаблоном: | |
string topRebarFilter = "Rebar Layer Top"; //название существующего фильтра для верхнего слоя армирования | |
string topRebarPrefix = "-Top Reinforcement"; | |
string bottomRebarFilter = "Rebar Layer Bottom"; //название существующего фильтра для нижнего слоя армирования | |
string bottomRebarPrefix = "-Bottom Reinforcement"; | |
string newViewsTemplate = "70 - Sh - R.C. Plan (Full Profile Rebar)"; //название шаблона вида для новых видов | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
public void Dublicateview() | |
{ | |
//var uidoc = this.ActiveUIDocument; //использовать данную строку если макрос добавляется в приложении | |
var uidoc = Application.ActiveUIDocument; //использовать данную строку если макрос добавляется в проект | |
Document doc = uidoc.Document; | |
View view = doc.ActiveView; | |
using (Transaction t = new Transaction(doc, "Dublicate View")) | |
{ | |
t.Start(); | |
//первая копия вида: | |
CreateCopy(doc,view,topRebarFilter,topRebarPrefix, newViewsTemplate, false); | |
//вторая копия вида: | |
CreateCopy(doc,view,bottomRebarFilter,bottomRebarPrefix, newViewsTemplate, false); | |
TaskDialog.Show("ok", "2 вида создано"); | |
t.Commit(); | |
} | |
} | |
private void CreateCopy (Document doc,View curView, string filterName, string viewNamePrefix, string newViewsTemplate, bool withDetalisation) | |
{ | |
ParameterFilterElement filter = null; | |
FilteredElementCollector coll = new FilteredElementCollector(doc).OfClass(typeof(ParameterFilterElement)); | |
foreach (Element element in coll) | |
{ | |
if (element.Name.Equals(filterName)) | |
{ | |
filter = element as ParameterFilterElement; | |
} | |
} | |
//создание копии вида | |
ViewDuplicateOption opt=new ViewDuplicateOption(); | |
if (withDetalisation) | |
{ | |
opt=ViewDuplicateOption.Duplicate; | |
} | |
else | |
{ | |
opt=ViewDuplicateOption.WithDetailing; | |
} | |
View newView = curView.Document.GetElement(curView.Duplicate(opt)) as View; | |
//применение фильтра к созданному виду: | |
if (filter==null) | |
{ | |
TaskDialog.Show("Error", "Фильтр "+filterName+" не найден"); | |
} | |
else | |
{ | |
OverrideGraphicSettings ogs = new OverrideGraphicSettings(); | |
newView.SetFilterOverrides(filter.Id, ogs); | |
newView.SetFilterVisibility(filter.Id, false); | |
} | |
//применить фильтр вида | |
View template=null; | |
coll = new FilteredElementCollector(doc).OfClass(typeof(View)); | |
foreach (Element element in coll) | |
{ | |
if (element.Name.Equals(newViewsTemplate)) | |
{ | |
template = element as View; | |
} | |
} | |
if (template==null) | |
{ | |
TaskDialog.Show("Error", "Шаблон "+newViewsTemplate+" не найден"); | |
} | |
else { | |
newView.ViewTemplateId = template.Id; | |
} | |
//переименование вида | |
newView.Name = curView.Name+viewNamePrefix; | |
} | |
#region Revit Macros generated code | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(Module_Startup); | |
this.Shutdown += new System.EventHandler(Module_Shutdown); | |
} | |
#endregion | |
} | |
} |
Open the view that you want to copy, run the macro and get 2 copies of this view with new names and the applied filters of visibility and the view template.
Comments
Post a Comment