Project 2
Practice: Developing a Natural Language Processing (NLP) Interface for Parametric Modifications in Revit Using Dynamo and Python
The aim of this project was to create a system that allows non-expert users to modify architectural models in Autodesk Revit using natural language queries. By integrating Dynamo scripts with Python code, user inputs could be translated into parametric changes within the architectural design, making the design process more intuitive and accessible.
Step 1: Initial Testing with a Simple Revit Model
Initially, a simple Revit model was created—a basic building featuring windows and doors. Using ChatGPT, the foundational Python code was generated, accounting for about 80% of the script, with manual adjustments made to tailor the remaining 20% to specific needs. Key parameters like window height, width, and quantity were identified for modification. Users could input natural language requests to alter these parameters, such as changing the window height or adjusting the number of windows.
Step 2: Applying the System to a More Complex Model
Encouraged by the success with the simple model, I applied our system to a taller, more complex tower with a rectangular shape.
As the project progressed, challenges arose when attempting to handle different parameter changes through natural language processing (NLP) queries directly in the code. The complexity of parsing various user inputs introduced too many variables at once, making debugging difficult and hindering the ability to pinpoint where the code was not performing as expected. To address this, a decision was made to first utilize Dynamo input nodes for parameter adjustments. By starting with predefined inputs, it became possible to add more parameters incrementally and develop the code accordingly. This step-by-step approach allowed for thorough testing at each stage, making it easier to identify and resolve issues.
For example, the initial focus was on modifying the panel length using the element ID to identify the object. Once this was functioning correctly, sliders for both panel width and length were added, confirming that simultaneous modifications were possible. Parameters like offset (affecting panel depth along the Z-axis) and materials for frames and panels were then incorporated. This methodical progression ensured that each new element worked before moving on to the next, providing a solid foundation for the code.
Step 3: Transitioning from Input Nodes to NLP
After the successful implementation and testing of parameter changes using Dynamo input nodes, the code was modified to accept string queries as input instead of relying on Dynamo components. This transition back to natural language inputs was smoother due to the prior testing and refinement. The practice of building and verifying the code incrementally helped in understanding how each part interacted with the others, making it easier to find and fix problems step by step.
The natural language parser utilized regular expressions to detect these keywords and extract associated values from the user queries. It was designed to be flexible, accommodating various phrasings and orders. For example:
A user might say, "Set the panel length to 3 meters and width to 2 meters."
Alternatively, "I want panels that are 3m by 2m."
Or even, "Make the panels 3 meters long and 2 meters wide."
The parser would identify "panel length" and associate it with "3 meters," and "panel width" with "2 meters," regardless of the phrasing.
Handling numerical inputs required careful consideration. The system was programmed to recognize numbers written in digits or words (e.g., "three meters") and to handle implicit dimensions where only one value was provided. If a user specified "use symmetric panels of 3 meters," the system interpreted this as setting both the length and width to 3 meters.
For materials, since Revit requires exact material names, the code included a mapping of user-friendly material terms to the corresponding material names in Revit. When a user requested a material change using common terms, the system matched it to the appropriate Revit material. For example, if a user said "use glass panels," the system would assign the "Glass" material defined in Revit.
Variations in language and phrasing were addressed by expanding the list of recognized keywords and implementing robust parsing logic. This included:
Conjunctions: Accounting for words like "and" or "also" to process multiple parameters in one query (e.g., "Change the panel size to 3 meters and the frame material to steel").
Units of Measurement: Handling different units such as meters, feet, or inches, and converting them to Revit's internal units. The system recognized abbreviations and symbols (e.g., "m," "ft," "in").
Comparative Language: Recognizing comparative and superlative forms like "increase," "decrease," "bigger," "smaller," "thicker," and "thinner." The parser interpreted phrases like "make the panels bigger" by increasing the current dimensions by a predefined increment.
Implicit Commands: Understanding commands where the parameter is implied rather than explicitly stated (e.g., "Use steel for the frames" implies changing the frame material).
Step 4: Handling Multiple Simultaneous Modifications
The system was further refined to handle multiple parameter changes from a single user query. Complex queries that included several requests simultaneously were parsed, ensuring all specified parameters were modified correctly.
Sep 5: Material Handling
Material specification presented a unique challenge due to Revit's requirement for exact material names. To address this, an Excel file was exported from Revit, listing all available materials, using dynamo python script. This served as a reference for accurate material specification. In future iterations, the code could be improved to map user inputs to the closest matching materials, providing greater flexibility and user-friendliness.
Step 6: Applying the System to a Complex Building Model
To test scalability, I applied our system to a more intricate building model.
Step 7: Rendering with Veras AI Plugins
To enhance visualization, Veras AI were used to render the modified models.For instance, when the tower was requested to serve as an air traffic control tower for an airport, the AI generated an appropriate render reflecting this new function.
Code Explanation
The Dynamo script, enhanced with Python code, modifies specific parameters of Revit elements based on natural language input. The key components of the script are:
Imports and Initialization: The script begins by importing essential Python libraries (sys, clr, re) for system functions, .NET interoperability, and regular expressions. It also imports Revit API modules (RevitServices, Autodesk.Revit.DB) to interact with Revit documents and elements.
Accessing the Revit Document: It retrieves the current active Revit document using DocumentManager, which allows the script to modify elements within the Revit environment.
Input Handling: The script accepts a natural language string as input (e.g., "Set panel length to 3 meters and width to 2 meters"), which it will parse to extract parameter changes.
Initializing Parameter Variables: Variables are initialized to store potential parameter values extracted from the user's query, such as panel length, width, offset, frame thickness, and material specifications.
Defining Keywords for Parsing: A comprehensive list of keywords and their variations is defined for each parameter to help the script recognize different ways users might refer to these parameters in natural language.
Parsing the User Query: The user query is split into parts using regular expressions, and each part is analyzed to extract parameter names and values. The script uses regex patterns to identify and assign values to the appropriate variables.
Handling Variations in User Input: The script accounts for different user input formats, such as implicit dimensions ("3 by 5") without explicitly stating which is length or width, and adjusts accordingly.
Validating Parsed Parameters: If no recognizable parameters are identified in the user query, the script outputs an error message indicating that it couldn't understand the query and prompts the user to specify parameters more clearly.
Modifying Revit Elements: If parameters are successfully parsed, the script starts a transaction to modify the Revit model:
Transaction Management: Ensures that changes are made safely within a transaction context.
Element Identification: Retrieves the specific element to modify using its element ID.
Parameter Modification: Updates parameters like "Panel Length" and "Panel Width" by converting user-provided values to Revit's internal units using UnitUtils.ConvertToInternalUnits.
Unit Conversion: Handles unit conversions to maintain consistency within the Revit model.
Material Assignment: The script collects all materials available in the document and checks if the user-specified materials exist. If they do, it assigns the corresponding material IDs to the element's parameters for panel and frame materials.
Completing the Transaction: After modifications:
Transaction Completion: The script commits the transaction to apply the changes.
Output Handling: Provides a success message indicating how many parameters were modified. If the element isn't found or parameters couldn't be modified, it aborts the transaction and outputs an error message.
Results
In summary, the project successfully demonstrated the feasibility of using natural language queries to modify Revit models through Dynamo and Python scripting. The iterative approach—starting with Dynamo input nodes and gradually transitioning to natural language inputs—proved effective in managing complexity and facilitating debugging. Non-expert users could interact with architectural models by typing simple commands, making the process more accessible. The system handled various parameters and could process multiple changes simultaneously, proving effective on both simple and complex models.
Discussion and Future Work
Through this practice, I realized that the same method could be expanded to include more parameters beyond just the facade. By applying this approach, changing Revit parameters could become much faster and easier. Even non-experts could modify multiple factors in a single request, enabling them to see different design options based on their needs.
For potential further studies, I think it would be beneficial to develop the system to handle a broader range of modifications. Incorporating more advanced natural language processing techniques could allow the system to understand and process even more complex user queries. Additionally, creating a user-friendly interface or plugin for Revit could make the tool more accessible to people without programming experience.
Comments
Post a Comment