Stenotype is a helper class library for working with the Revit API. It consists of .NET helper/extension wrapper classes and methods for writing modular Revit API code faster, and keeping a record. The main code library to reference is the compiled .dll from the C# Stenotype library in this repository.
API documentation for authors is included as .chm help-file: API Documentation. Documentation created with Sandcastle Help File Builder.
Typical usage within a C# Revit environment (Visual Studio - Revit External Command or Revit Add-In).
using ST = Stenotype;
Options geomOption = ST.FilledRegionsST.CreateGeometryOption() // static usage, returns a .NET object
UtilST.GetSingleUserSelection(uidoc) // static usage, gets a single selected item by the user's mouse
Wrapper classes are instantiated by taking a corresponding Revit API class as a constructor (use a Viewport Class as a constructor to pass in a for a ViewportST class). They offer shortcut methods, and the opportunity to seralize to JSON of the public exposed wrapper class members and store/export the data. Uploading the same information to a databse is currently WIP.
using Newtonsoft.Json;
using Stenotype;
// Create logging JSON object for export or upload
JObject parentJson = new JObject();
// Define Revit document objects (varies depending on implementation)
RevitDoc = this.ActiveUIDocument.Document;
RevitUiDoc = this.ActiveUIDocument;
// Instantiate a Stenotype wrapper class by passing in the Revit API Object as a constructor`
DocumentST docST = new DocumentST(RevitDoc); // Stenotype classes correspond to the Revit API class of the same name + "ST"
Debug.Write(docST.Serialized); // Returns a JSON string
parentJson.Add("Document", docST.JsonObject); // Add the JSON to the parent
// Line Styles
JObject lineStylesJson = new JObject(); // Create a nested JSON object
Category lineStylesCategory = RevitDoc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines); // Get Document line styles
CategoryNameMap lineStyleSubTypes = lineStylesCategory.SubCategories; // Iterate over the SubCategories
foreach (Category subCatLineStyle in lineStyleSubTypes)
{
LinestyleST lsST = new LinestyleST(RevitDoc, subCatLineStyle); // Instantiate a Stenotype wrapper class (this one also needs the document as a constructor)
Debug.Write(lsST.Serialized); // Returns a JSON string
lineStylesJson.Add(lsST.LineStyleName, lsST.JsonObject); // Add the JSON to the parent
}
parentJson.Add("Line Styles", lineStylesJson); // Add the JSON to the parent
// EXPORT LOGGING JSON
string dirPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Set the output directory to the desktop
File.WriteAllText(dirPath + "\\UnitTestData.json", parentJson.ToString()); // Export the parent JSON as a static file
TaskDialog.Show("Export Success", "JSON Exported to Desktop"); // Success
Typical usage within an IronPython Revit environment (RevitPythonShell, pyRevit).
# IronPython is a .NET lanaguage and != Python/CPython/Python 3
import clr
import sys
# Add the IronPython path to the system path variable
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
# Add a .NET reference to the compiled Stenotype .dll
clr.AddReferenceToFileAndPath(r'C:\Users\USERNAME\Documents\Folder\Stenotype.dll')
# Import all classes from the library
from Stenotype import *
Following the import statements above, the class library can used as shown below. For Intellinse/documentaiton, refer to the XML docstrings in the C# source, or complete the imports above in the Interactive Revit Python Shell's console environment (top half of the window).
from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document # Define the Document
filled_region_collection = FilteredElementCollector(doc).OfClass(FilledRegion).WhereElementIsNotElementType().ToElements() # Collect all Filled Regions in the document
filled_region_object = filled_region_collection[0] # Take the first Filled Region as an example
docST = ST.DocumentST(doc) # Instantiate Document class with Document object constructor
frST = ST.FilledRegionsST(doc, filled_region_object) # Instantiate Filled Region class with Filled Region object constructor
print (frST.graphicsStyles) # Some (most) properties hold .NET objects which also have a serializable value
print (docST.title) # Others hold a string/int representation
print (docST.Serialized) # Returns a JSON string of the public properties - can be exported, or written to a database.
# Assuming the user has clicked on a single room in Revit
selectedObjectInRevit = ST.UtilST.GetSingleUserSelection(uidoc)
roomObj = ST.RoomST(selectedObjectInRevit) # Create a Stenotype wrapper class with the Room Class as the constructor
roomPoint = roomObj.GetRoomLocation() # Get the location of a room as an XYZ point.
roomElements = roomObj.GetElementsInRoom(doc.ActiveView) # Return all elements in the Room's bounding box