__title__ = "Samples - C# to Python"
__doc__ = """Version = 1.0
Date = 15.06.2024
________________________________________________________________
Description:
Link to a reusable FEC Samples library for
FilteredElementCollector Class.
________________________________________________________________
How-To:
1. Click on the button to open the FEC Samples file
in your default IDE (code editor)
2. Master Getting Your Elements!
________________________________________________________________
Author: Erik Frits"""
from Autodesk.Revit.DB import *
import clr
clr.AddReference('System')
from System.Collections.Generic import List
app = __revit__.Application
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
c_sharp_sample = """
// Defined Data Type
int myNum = 50;
// Non-Defined Data Type
var myNum = 50;
"""
my_num = 50
c_sharp_sample = """
FilteredElementCollector collector = new FilteredElementCollector(doc);
"""
collector = FilteredElementCollector(doc)
c_sharp_sample="""
int myNumber = 5;
if (myNumber > 10)
{
Console.WriteLine("Number is more than 10");
}
else if (myNumber == 5)
{
Console.WriteLine("Number is 5");
}
else
{
Console.WriteLine("Number is less than 5");
}"""
my_num = 5
if my_num > 10:
print("Number is more than 5")
elif my_num == 5:
print("Number is 5")
else:
print("Number is less than 5")
c_sharp_sample = """
// for Loop
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
// while Loop
int count = 5;
while (count > 0) {
Console.WriteLine(count);
count--;
}"""
for i in range(10):
print(i)
count = 5
while count > 0:
print(count)
count -= 1
c_sharp_sample = """
void MyFunction()
{
Console.WriteLine('Simple Function')
}"""
def my_function():
print('Simple Function')
c_sharp_sample = """
def my_function(view, x):
# type: (View, int) -> View
print("View Name: {}".format(view.Name))
return view"""
def my_function(view, x):
print("View Name: {}".format(view.Name))
return view
c_sharp_1 = """
public Wall CreateWallUsingCurve1(Autodesk.Revit.DB.Document document, Level level)
{
// Build a location line for the wall creation
XYZ start = new XYZ(0, 0, 0);
XYZ end = new XYZ(10, 10, 0);
Line geomLine = Line.CreateBound(start, end);
// Create a wall using the location line
return Wall.Create(document, geomLine, level.Id, true);
}"""
def CreateWallUsingCurve1(document, level):
"""Function to create a sample wall."""
start = XYZ(0, 0, 0)
end = XYZ(10, 10, 0)
geomLine = Line.CreateBound(start, end)
return Wall.Create(document, geomLine, level.Id, False)
level = doc.ActiveView.GenLevel
with Transaction(doc, 'Create a Wall') as t:
t.Start()
new_wall = CreateWallUsingCurve1(doc, level)
t.Commit()
c_sharp_2 = """
Ceiling CreateCeilingAtElevation(Document document, Level level, double elevation)
{
XYZ first = new XYZ(0, 0, 0);
XYZ second = new XYZ(20, 0, 0);
XYZ third = new XYZ(20, 15, 0);
XYZ fourth = new XYZ(0, 15, 0);
CurveLoop profile = new CurveLoop();
profile.Append(Line.CreateBound(first, second));
profile.Append(Line.CreateBound(second, third));
profile.Append(Line.CreateBound(third, fourth));
profile.Append(Line.CreateBound(fourth, first));
var ceiling = Ceiling.Create(document, new List<CurveLoop> { profile }, ElementId.InvalidElementId, level.Id);
Parameter param = ceiling.get_Parameter(BuiltInParameter.CEILING_HEIGHTABOVELEVEL_PARAM);
param.Set(elevation);
return ceiling;
}"""
def CreateCeilingAtElevation(doc, level, elevation):
"""Function to create a sample Ceiling"""
first = XYZ(0, 0, 0)
second = XYZ(20, 0, 0)
third = XYZ(20, 15, 0)
fourth = XYZ(0, 15, 0)
profile = CurveLoop()
profile.Append(Line.CreateBound(first, second))
profile.Append(Line.CreateBound(second, third))
profile.Append(Line.CreateBound(third, fourth))
profile.Append(Line.CreateBound(fourth, first))
list_curve_loops = List[CurveLoop]()
list_curve_loops.Add(profile)
ceil_type_id = doc.GetDefaultElementTypeId(ElementTypeGroup.CeilingType)
ceiling = Ceiling.Create(doc,
list_curve_loops,
ceil_type_id,
level.Id)
param = ceiling.get_Parameter(BuiltInParameter.CEILING_HEIGHTABOVELEVEL_PARAM)
param.Set(elevation)
return ceiling
level = doc.ActiveView.GenLevel
with Transaction(doc, 'Create a Ceiling') as t:
t.Start()
new_ceil = CreateCeilingAtElevation(doc, level, 10)
t.Commit()
c_sharp_3 = """
public void ElementOverride()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
ElementId id = uidoc.Selection.PickObject(ObjectType.Element,"Select an element").ElementId;
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetProjectionLineColor(new Color(0,255,0));
using (Transaction t = new Transaction(doc,"Set Element Override"))
{
t.Start();
doc.ActiveView.SetElementOverrides(id, ogs);
t.Commit();
}
}"""
from Autodesk.Revit.UI.Selection import ObjectType
def ElementOverride():
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
id = uidoc.Selection.PickObject(ObjectType.Element,"Select an element").ElementId
ogs = OverrideGraphicSettings()
ogs.SetProjectionLineColor( Color(255,0,50))
with Transaction(doc,"Set Element Override") as t:
t.Start()
doc.ActiveView.SetElementOverrides(id, ogs)
t.Commit()
ElementOverride()