bvn-architecture / RevitBatchProcessor

Fully automated batch processing of Revit files with your own Python or Dynamo task scripts!
GNU General Public License v3.0
299 stars 81 forks source link

Feature Request: Allow custom settings to be sent with each file #43

Closed RyanSchw closed 5 years ago

RyanSchw commented 5 years ago

A few of my scripts have some variables that were given by the user as a form input. I want to automate the task, but still enable the user to be able to provide those custom settings.

Off the top of my head, I think the easiest way to do this would be allowing the user to add additional columns in their file list. The python script the user writes (sorry, not sure how Dynamo would work) could reference an import that RBP creates and exports with the python file. Another option would be to do this in conjunction with #36 that manages communication between all of the processes as well.

Example: CSV file

path type
filepath\Multiple_Doors.rvt doors

Python script

import clr
import System
clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.DB import *

import revit_script_util
from revit_script_util import Output

# Typical things copied from template
revitFilePath = revit_script_util.GetRevitFilePath()

# TODO: some real work!
Output()
Output("This task script is running!")

# Custom part for issue 43 example
from file_settings import file_settings
settings = file_settings[revitFilePath] # Get the settings for the specific document based on the file path
if settings['type'] == 'door':
  TaskDialog.Show('Revit', 'Door type selected')

file_settings.py (created by RBP when it parsed the CSV)

settings = {
  'filepath\\Multiple_Doors.rvt': {
    'type': 'door'
  }
}
RyanSchw commented 5 years ago

Any progress on this @DanRumery ? I have some time to contribute. If you have a branch with changes I can add on to that. Not sure how you envisioned this being implemented but I'll try to follow along with your current structure.

DanRumery commented 5 years ago

@RyanSchw

Sorry I've been away for a while. I've just pushed some commits relating to this but the code is currently untested so there are likely some bugs in there. Will do some testing then let you know so you can try it out.

The function you'll use in the task script is revit_script_util.GetAssociatedData() which is intended to return a list of text values that were found in the same row (and to the right) of the Revit file path.

RyanSchw commented 5 years ago

@DanRumery

Where can I find these commits? I'll try to follow your line of thinking as closely as possible since you're much better versed in how this should be implemented. Is there a branch on RBP?

Do you have any ideas on how the settings can be better transferred to the python files? Perhaps we use a function call like settings.get('SETTING NAME') so that the function can throw a useful error if the setting is not found. Otherwise, I'll continue with the structure that was initially proposed.

DanRumery commented 5 years ago

@RyanSchw I pushed three commits to master several hours ago. You should be able to see them.

the function is revit_script_util.GetAssociatedData() but if you look under the hood the actual "transfer" of the data is via ScriptData class which is serialized/deserialized to/from json so the task script can get at the settings data. Most of the functions simply wrap access to this object.

(Note that this class is instantiated per Revit file and carries the associated data for that file, so there is no need for an explicit mapping elsewhere.)

RyanSchw commented 5 years ago

I've taken a look at the code -- very nice implementation. I've tested the following items and so far it's been working as expected:

main_use_case.csv

xxx\Multiple_Doors.rvt,setting_1,setting_2,setting_3

test_file_path_missing.csv

xxx\Multiple_Doors.rvt,setting_1,setting_2,setting_3
,setting_1,setting_2,setting_3         # Note this one is skipped

test_blank_setting.csv

xxx\Multiple_Doors.rvt,setting_1,,setting_3

test_multiple_revit_files_on_same_line.csv

xxx\Multiple_Doors.rvt,xxx\Multiple_Doors.rvt,setting_2,setting_3       # the first associated data should be xxx\Multiple_Doors.rvt
DanRumery commented 5 years ago

Cool! I did some regression testing too and all seems to be working. This will be in the next release...