General Standards
Use the following to train your LLM on the general coding standards for Launchpad scripts.
Coding Standards for Launchpad Scripts
Script Organization
Logical Flow Structure
Place the main execution code at the top of the script
Define classes and data models in the middle
Place helper methods at the end of the file
Avoid declaring methods within the main execution flow
Transaction Management
Define a transaction name at the beginning of the script
Use a descriptive name for the transaction
Do not create transactions in the script. Launchpad will wrap the code in a transaction automatically
Naming Conventions
Variables and Methods
Use camelCase for local variables and method parameters:
wallTypeNameUse PascalCase for methods:
FindOrCreateLevel()Use meaningful, descriptive names that explain purpose
Avoid abbreviations unless universally understood
Always set the protection level of methods to be private
UI Elements
Create a string variable for all tool labels. Use the variable to create the control
Use descriptive label names with "Label" suffix:
wallTypeLabelUse consistent naming for form result retrieval:
results.GetStringResult(myLabel)
Error Handling
Validation
Validate user input before processing
Check for null references when accessing document elements
Validate selections before proceeding with operations
Use early returns for invalid conditions
Exception Handling
Use try-catch blocks for potentially risky operations
Provide informative error messages to users
Log detailed error information to the console using
Console.WriteLine()Handle specific exceptions where appropriate
UI Design
Forms and Controls
Create logical groupings of related controls
Use consistent padding and spacing
Add descriptive labels and headers
Include help links where appropriate
Limit form size to reasonable dimensions (e.g., 800x700 max)
DataGrids
Define column widths proportionally
Make read-only columns visually distinct
Use appropriate controls for editing (e.g., ComboBox for selection)
Add sorting and filtering capabilities where helpful
Performance Considerations
Collection Management
Use LINQ queries for filtering and sorting
Use appropriate collection types (
List<T>for ordered collections,Dictionary<K,V>for lookups)Avoid redundant collectors where possible
Efficient Data Access
Cache frequently accessed data instead of repeated lookups
Use batch operations where possible instead of modifying elements one by one
Consider using transactions with manual commit to improve performance
Comments and Documentation
Code Comments
Add header comments explaining script purpose
Document complex logic or algorithms
Explain parameters for non-obvious methods
Comment on "why" more than "what" (the code should explain what)
Region Organization
Use regions to organize related code sections in large scripts
Group helper methods by functionality
Keep regions focused and not too lengthy
Revit-Specific Best Practices
Element Access
Use
FilteredElementCollectorefficiently with appropriate filtersApply
WhereElementIsNotElementType()orWhereElementIsElementType()early in collector chainsCast to specific element types after collection
Parameter Management
Check parameters for null before accessing values
Handle read-only parameters appropriately
Use the correct parameter access method (e.g.,
AsDouble(),AsString(), etc.)Be aware of unit conversions for numerical parameters
Linked Document Handling
Check if linked documents are loaded before accessing them
Use appropriate coordinate transforms when working across documents
Handle versioning differences between host and linked documents
Geometry Operations
Be mindful of coordinate systems (model vs family coordinates)
Ensure created geometry is valid (e.g., non-zero length curves)
Handle special cases like curved elements properly
Selection
Always specify the full Autodesk.Revit.UI.Selection path when using Revit API selection methods such as PickPoint
Use the Autodesk.Revit.UI.Selection.PickPoint method to allow the user to select points
By following these standards, Launchpad scripts will be more maintainable, robust, and user-friendly.
Last updated