Revit Macro: Switch all grids on current view from 3d to 2d or from 2d to 3d
This macro allow to switch all grids on current view from 3d to 2d or from 2d to 3d.
This file contains hidden or 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.B | |
* Date: 03.10.2019 | |
* Time: 14:52 | |
* | |
* 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 Grids3dTo2d | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.DB.Macros.AddInId("3535C271-5122-437D-8331-4B4D6E28EF98")] | |
public partial class ThisDocument | |
{ | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
//переключить все оси на 2D | |
public void Grids3dTo2d() | |
{ | |
//var uidoc = this.ActiveUIDocument; //использовать данную строку если макрос добавляется в приложении | |
var uidoc = Application.ActiveUIDocument; //использовать данную строку если макрос добавляется в проект | |
Document doc = uidoc.Document; | |
View curView = doc.ActiveView; | |
ICollection<Element> grids = new FilteredElementCollector(doc, curView.Id).OfCategory(BuiltInCategory.OST_Grids).ToElements(); | |
using (Transaction t = new Transaction(doc, "Grids3dTo2d")) | |
{ | |
t.Start(); | |
foreach (Grid gridelement in grids) | |
{ | |
gridelement.SetDatumExtentType(DatumEnds.End0, curView, DatumExtentType.ViewSpecific); //2d | |
gridelement.SetDatumExtentType(DatumEnds.End1, curView, DatumExtentType.ViewSpecific); //2d | |
} | |
t.Commit(); | |
} | |
} | |
//переключить все оси на 3D | |
public void Grids2dTo3d() | |
{ | |
//var uidoc = this.ActiveUIDocument; //использовать данную строку если макрос добавляется в приложении | |
var uidoc = Application.ActiveUIDocument; //использовать данную строку если макрос добавляется в проект | |
Document doc = uidoc.Document; | |
View curView = doc.ActiveView; | |
ICollection<Element> grids = new FilteredElementCollector(doc, curView.Id).OfCategory(BuiltInCategory.OST_Grids).ToElements(); | |
using (Transaction t = new Transaction(doc, "Grids3dTo2d")) | |
{ | |
t.Start(); | |
foreach (Grid gridelement in grids) | |
{ | |
gridelement.SetDatumExtentType(DatumEnds.End0, curView, DatumExtentType.Model); //3d | |
gridelement.SetDatumExtentType(DatumEnds.End1, curView, DatumExtentType.Model); //3d | |
} | |
t.Commit(); | |
} | |
} | |
#region Revit Macros generated code | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(Module_Startup); | |
this.Shutdown += new System.EventHandler(Module_Shutdown); | |
} | |
#endregion | |
} | |
} |
Comments
Post a Comment