Revit Macro: Show rebars in 3D view as solid. Turn on and turn off.
Macro turns on displaying of all rebars in current 3d view as solid:
Macro turns off displaying of all rebars in current 3d view as solid:
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.B | |
* Date: 03.10.2019 | |
* Time: 14:05 | |
* | |
* To change this template use Tools | Options | Coding | Edit Standard Headers. | |
*/ | |
using System; | |
using Autodesk.Revit.UI; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.DB.Structure; | |
using Autodesk.Revit.UI.Selection; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Autodesk.Revit.DB.Macros; | |
namespace ViewAsSolidOn | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.DB.Macros.AddInId("5BDD45EC-5701-4AC5-B84B-81A82077B3A6")] | |
public partial class ThisDocument | |
{ | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
public void ViewAsSolidOn() | |
{ | |
//var uidoc = this.ActiveUIDocument; //использовать данную строку если макрос добавляется в приложении | |
var uidoc = Application.ActiveUIDocument; //использовать данную строку если макрос добавляется в проект | |
Document doc = uidoc.Document; | |
View3D cur3dview = doc.ActiveView as View3D; | |
if (cur3dview==null) | |
{ | |
TaskDialog.Show("Error", "Макрос необходимо запускать при активном 3D виде"); | |
return; | |
} | |
ElementId newViewId = ElementId.InvalidElementId; | |
ICollection<Element> rebars = new FilteredElementCollector(doc, cur3dview.Id).OfCategory(BuiltInCategory.OST_Rebar).ToElements(); | |
List<Rebar> List_Rebar = new List<Rebar>(); | |
List<RebarInSystem> List_RebarInSystem = new List<RebarInSystem>(); | |
foreach( Element rebar in rebars) | |
{ | |
if(rebar.GetType().ToString().Equals("Autodesk.Revit.DB.Structure.Rebar")) | |
{ | |
List_Rebar.Add( rebar as Rebar); | |
} | |
else if(rebar.GetType().ToString().Equals("Autodesk.Revit.DB.Structure.RebarInSystem")) | |
{ | |
List_RebarInSystem.Add( rebar as RebarInSystem); | |
} | |
} | |
using (Transaction t = new Transaction(doc, "ViewAsSolid")) | |
{ | |
t.Start(); | |
foreach( Rebar r in List_Rebar) | |
{ | |
r.SetSolidInView(cur3dview, true); | |
} | |
foreach( RebarInSystem ris in List_RebarInSystem) | |
{ | |
ris.SetSolidInView(cur3dview, true); | |
} | |
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 | |
} | |
} |
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.B | |
* Date: 03.10.2019 | |
* Time: 13:43 | |
* | |
* To change this template use Tools | Options | Coding | Edit Standard Headers. | |
*/ | |
using System; | |
using Autodesk.Revit.UI; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.DB.Structure; | |
using Autodesk.Revit.UI.Selection; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Autodesk.Revit.DB.Macros; | |
namespace ViewAsSolidOff | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.DB.Macros.AddInId("DBD3E699-CFC6-4286-84E0-89FA54CF9989")] | |
public partial class ThisDocument | |
{ | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
public void ViewAsSolidOff() | |
{ | |
//var uidoc = this.ActiveUIDocument; //использовать данную строку если макрос добавляется в приложении | |
var uidoc = Application.ActiveUIDocument; //использовать данную строку если макрос добавляется в проект | |
Document doc = uidoc.Document; | |
View3D cur3dview = doc.ActiveView as View3D; | |
if (cur3dview==null) | |
{ | |
TaskDialog.Show("Error", "Макрос необходимо запускать при активном 3D виде"); | |
return; | |
} | |
ElementId newViewId = ElementId.InvalidElementId; | |
ICollection<Element> rebars = new FilteredElementCollector(doc, cur3dview.Id).OfCategory(BuiltInCategory.OST_Rebar).ToElements(); | |
List<Rebar> List_Rebar = new List<Rebar>(); | |
List<RebarInSystem> List_RebarInSystem = new List<RebarInSystem>(); | |
foreach( Element rebar in rebars) | |
{ | |
if(rebar.GetType().ToString().Equals("Autodesk.Revit.DB.Structure.Rebar")) | |
{ | |
List_Rebar.Add( rebar as Rebar); | |
} | |
else if(rebar.GetType().ToString().Equals("Autodesk.Revit.DB.Structure.RebarInSystem")) | |
{ | |
List_RebarInSystem.Add( rebar as RebarInSystem); | |
} | |
} | |
using (Transaction t = new Transaction(doc, "ViewAsSolid")) | |
{ | |
t.Start(); | |
foreach( Rebar r in List_Rebar) | |
{ | |
r.SetSolidInView(cur3dview, false); | |
} | |
foreach( RebarInSystem ris in List_RebarInSystem) | |
{ | |
ris.SetSolidInView(cur3dview, false); | |
} | |
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