コード例 #1
0
def RunSingleRevitTask(batchRvtConfig):
    aborted = False

    revitVersion = batchRvtConfig.SingleRevitTaskRevitVersion
    Output()
    Output("Revit Version:")
    Output()
    Output("\t" + RevitVersion.GetRevitVersionText(revitVersion))

    if revitVersion not in RevitVersion.GetInstalledRevitVersions():
        Output()
        Output(
            "ERROR: The specified Revit version is not installed or the addin is not installed for it."
        )
        aborted = True

    if not aborted:
        if batchRvtConfig.ExecutePreProcessingScript:
            aborted = ExecutePreProcessingScript(batchRvtConfig, Output)

    if not aborted:
        Output()
        Output("Starting single task operation...")

        Output()
        Output("Starting Revit " +
               RevitVersion.GetRevitVersionText(revitVersion) + " session...")

        scriptData = ScriptDataUtil.ScriptData()
        scriptData.SessionId.SetValue(batchRvtConfig.SessionId)
        scriptData.TaskScriptFilePath.SetValue(batchRvtConfig.ScriptFilePath)
        scriptData.TaskData.SetValue(batchRvtConfig.TaskData)
        scriptData.EnableDataExport.SetValue(batchRvtConfig.EnableDataExport)
        scriptData.SessionDataFolderPath.SetValue(
            batchRvtConfig.SessionDataFolderPath)
        scriptData.ShowMessageBoxOnTaskScriptError.SetValue(
            batchRvtConfig.ShowMessageBoxOnTaskError)
        scriptData.RevitProcessingOption.SetValue(
            batchRvtConfig.RevitProcessingOption)
        scriptData.ProgressNumber.SetValue(1)
        scriptData.ProgressMax.SetValue(1)

        batchRvtScriptsFolderPath = BatchRvt.GetBatchRvtScriptsFolderPath()

        batch_rvt_monitor_util.RunScriptedRevitSession(
            revitVersion, batchRvtScriptsFolderPath,
            batchRvtConfig.ScriptFilePath, [scriptData], 1,
            batchRvtConfig.ProcessingTimeOutInMinutes,
            batchRvtConfig.ShowRevitProcessErrorMessages,
            batchRvtConfig.TestModeFolderPath, Output)

    if not aborted:
        if batchRvtConfig.ExecutePostProcessingScript:
            aborted = ExecutePostProcessingScript(batchRvtConfig, Output)

    return aborted
コード例 #2
0
def RunBatchRevitTasks(batchRvtConfig):
    aborted = False

    if not aborted:
        if batchRvtConfig.ExecutePreProcessingScript:
            aborted = ExecutePreProcessingScript(batchRvtConfig, Output)

    if not aborted:
        supportedRevitFileList = GetSupportedRevitFiles(batchRvtConfig)
        if supportedRevitFileList is None:
            aborted = True

    if not aborted:
        supportedCount = len(supportedRevitFileList)
        if supportedCount == 0:
            Output()
            Output(
                "ERROR: All specified Revit Files are of an unsupported version or have an unsupported file path."
            )
            aborted = True

    if not aborted:
        Output()
        Output("Revit Files for processing (" + str(supportedCount) + "):")
        for supportedRevitFileInfo in supportedRevitFileList:
            batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                supportedRevitFileInfo, Output)

        if batchRvtConfig.EnableDataExport:
            session_data_exporter.ExportSessionFilesData(
                batchRvtConfig.SessionDataFolderPath, batchRvtConfig.SessionId,
                [
                    supportedRevitFileInfo.GetRevitFileInfo().GetFullPath()
                    for supportedRevitFileInfo in supportedRevitFileList
                ])

    if not aborted:
        Output()
        Output("Starting batch operation...")
        aborted = ProcessRevitFiles(batchRvtConfig, supportedRevitFileList)

    if not aborted:
        if batchRvtConfig.ExecutePostProcessingScript:
            aborted = ExecutePostProcessingScript(batchRvtConfig, Output)

    return aborted
コード例 #3
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#

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

import script_util
from script_util import Output

sessionId = script_util.GetSessionId()

# NOTE: this only make sense for batch Revit file processing mode.
revitFileListFilePath = script_util.GetRevitFileListFilePath()

# NOTE: these only make sense for data export mode.
sessionDataFolderPath = script_util.GetSessionDataFolderPath()
dataExportFolderPath = script_util.GetExportFolderPath()

# TODO: some real work!
Output()
Output("This pre-processing script is running!")

コード例 #4
0
def GetSupportedRevitFiles(batchRvtConfig):
    supportedRevitFileList = None

    revitFileList = batchRvtConfig.ReadRevitFileList(Output)

    if revitFileList is not None:
        supportedRevitFileList = list(
            revit_file_list.SupportedRevitFileInfo(revitFilePath.Trim('"'))
            for revitFilePath in revitFileList)

        nonExistentRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if not RevitFileExists(supportedRevitFileInfo))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if RevitFileExists(supportedRevitFileInfo))

        unsupportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList if
            not HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo))

        unsupportedRevitFilePathRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not HasSupportedRevitFilePath(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (RevitFileExists(supportedRevitFileInfo) and
                HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo)
                and HasSupportedRevitFilePath(supportedRevitFileInfo)
                )).OrderBy(lambda supportedRevitFileInfo: GetRevitFileSize(
                    supportedRevitFileInfo)).ToList()

        nonExistentCount = len(nonExistentRevitFileList)
        unsupportedCount = len(unsupportedRevitFileList)
        unsupportedRevitFilePathCount = len(
            unsupportedRevitFilePathRevitFileList)

        if nonExistentCount > 0:
            Output()
            Output("WARNING: The following Revit Files do not exist (" +
                   str(nonExistentCount) + "):")
            for supportedRevitFileInfo in nonExistentRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files are of an unsupported version ("
                + str(unsupportedCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedRevitFilePathCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files have an unsupported file path ("
                + str(unsupportedRevitFilePathCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFilePathRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

    return supportedRevitFileList
コード例 #5
0
def ProcessRevitFiles(batchRvtConfig, supportedRevitFileList):
    aborted = False

    totalFilesCount = len(supportedRevitFileList)
    progressNumber = 1

    for revitVersion, supportedRevitFiles in GroupByRevitVersion(
            batchRvtConfig, supportedRevitFileList):

        sessionRevitFiles = []
        queuedRevitFiles = list(supportedRevitFiles)

        while queuedRevitFiles.Any():
            scriptDatas = []
            snapshotDataExportFolderPaths = []

            if batchRvtConfig.RevitSessionOption == BatchRvt.RevitSessionOption.UseSameSessionForFilesOfSameVersion:
                sessionRevitFiles = queuedRevitFiles
                queuedRevitFiles = []
            else:
                sessionRevitFiles = [queuedRevitFiles[0]]
                queuedRevitFiles = queuedRevitFiles[1:]

            sessionFilesCount = len(sessionRevitFiles)
            if len(sessionRevitFiles) == 1:
                Output()
                Output("Processing Revit file (" + str(progressNumber) +
                       " of " + str(totalFilesCount) + ")" + " in Revit " +
                       RevitVersion.GetRevitVersionText(revitVersion) +
                       " session.")
            else:
                Output()
                Output("Processing Revit files (" + str(progressNumber) +
                       " to " + str(progressNumber + sessionFilesCount - 1) +
                       " of " + str(totalFilesCount) + ")" + " in Revit " +
                       RevitVersion.GetRevitVersionText(revitVersion) +
                       " session.")

            for supportedRevitFileInfo in sessionRevitFiles:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

            Output()
            Output("Starting Revit " +
                   RevitVersion.GetRevitVersionText(revitVersion) +
                   " session...")

            for index, supportedRevitFileInfo in enumerate(sessionRevitFiles):
                snapshotDataExportFolderPath = str.Empty
                revitFilePath = supportedRevitFileInfo.GetRevitFileInfo(
                ).GetFullPath()

                if batchRvtConfig.EnableDataExport:
                    snapshotDataExportFolderPath = snapshot_data_util.GetSnapshotFolderPath(
                        batchRvtConfig.DataExportFolderPath, revitFilePath,
                        batchRvtConfig.SessionStartTime)
                    path_util.CreateDirectory(snapshotDataExportFolderPath)
                    snapshotDataExportFolderPaths.append(
                        snapshotDataExportFolderPath)

                revitFilePath = supportedRevitFileInfo.GetRevitFileInfo(
                ).GetFullPath()
                scriptData = ScriptDataUtil.ScriptData()
                scriptData.SessionId.SetValue(batchRvtConfig.SessionId)
                scriptData.TaskScriptFilePath.SetValue(
                    batchRvtConfig.ScriptFilePath)
                scriptData.RevitFilePath.SetValue(revitFilePath)
                scriptData.TaskData.SetValue(batchRvtConfig.TaskData)
                scriptData.OpenInUI.SetValue(batchRvtConfig.OpenInUI)
                scriptData.EnableDataExport.SetValue(
                    batchRvtConfig.EnableDataExport)
                scriptData.SessionDataFolderPath.SetValue(
                    batchRvtConfig.SessionDataFolderPath)
                scriptData.DataExportFolderPath.SetValue(
                    snapshotDataExportFolderPath)
                scriptData.ShowMessageBoxOnTaskScriptError.SetValue(
                    batchRvtConfig.ShowMessageBoxOnTaskError)
                scriptData.RevitProcessingOption.SetValue(
                    batchRvtConfig.RevitProcessingOption)
                scriptData.CentralFileOpenOption.SetValue(
                    batchRvtConfig.CentralFileOpenOption)
                scriptData.DeleteLocalAfter.SetValue(
                    batchRvtConfig.DeleteLocalAfter)
                scriptData.DiscardWorksetsOnDetach.SetValue(
                    batchRvtConfig.DiscardWorksetsOnDetach)
                scriptData.ProgressNumber.SetValue(progressNumber + index)
                scriptData.ProgressMax.SetValue(totalFilesCount)
                scriptDatas.append(scriptData)

            batchRvtScriptsFolderPath = BatchRvt.GetBatchRvtScriptsFolderPath()

            while scriptDatas.Any():
                nextProgressNumber = batch_rvt_monitor_util.RunScriptedRevitSession(
                    revitVersion, batchRvtScriptsFolderPath,
                    batchRvtConfig.ScriptFilePath, scriptDatas, progressNumber,
                    batchRvtConfig.ProcessingTimeOutInMinutes,
                    batchRvtConfig.TestModeFolderPath, Output)

                if nextProgressNumber is None:
                    Output()
                    Output(
                        "WARNING: The Revit session failed to initialize properly! No Revit files were processed in this session!"
                    )
                    progressNumber += len(scriptDatas)
                    break
                else:
                    progressNumber = nextProgressNumber

                scriptDatas = (scriptDatas.Where(
                    lambda scriptData: scriptData.ProgressNumber.GetValue(
                    ) >= progressNumber).ToList())

                if batchRvtConfig.EnableDataExport:
                    Output()
                    Output("Consolidating snapshots data.")
                    for snapshotDataExportFolderPath in snapshotDataExportFolderPaths:
                        snapshot_data_util.ConsolidateSnapshotData(
                            snapshotDataExportFolderPath, Output)
                        # NOTE: Have disabled copying of journal files for now because if many files were processed
                        #       in the same Revit session, too many copies of a potentially large journal file
                        #       will be made. Consider modifying the logic so that the journal file is copied only
                        #       once per Revit seesion. Perhaps copy it to the BatchRvt session folder.
                        if False:
                            try:
                                snapshot_data_util.CopySnapshotRevitJournalFile(
                                    snapshotDataExportFolderPath, Output)
                            except Exception, e:
                                Output()
                                Output(
                                    "WARNING: failed to copy the Revit session's journal file to snapshot data folder:"
                                )
                                Output()
                                Output("\t" + snapshotDataExportFolderPath)
                                exception_util.LogOutputErrorDetails(e, Output)
コード例 #6
0
            if batchRvtConfig.RevitProcessingOption == BatchRvt.RevitProcessingOption.BatchRevitFileProcessing:
                aborted = RunBatchRevitTasks(batchRvtConfig)
            else:
                aborted = RunSingleRevitTask(batchRvtConfig)
        except Exception, e:
            sessionError = exception_util.GetExceptionDetails(e)
            raise
        finally:
            if batchRvtConfig.EnableDataExport:
                sessionEndTime = time_util.GetDateTimeNow()

                session_data_exporter.ExportSessionData(
                    batchRvtConfig.SessionId, batchRvtConfig.SessionStartTime,
                    sessionEndTime, batchRvtConfig.SessionDataFolderPath,
                    sessionError)

    Output()
    if aborted:
        Output("Operation aborted.")
    else:
        Output("Operation completed.")
    Output()
    return


try:
    Main()
except Exception, e:
    exception_util.LogOutputErrorDetails(e, Output)
    raise
コード例 #7
0
                aborted = RunBatchRevitTasks(batchRvtConfig)
            else:
                aborted = RunSingleRevitTask(batchRvtConfig)
        except Exception, e:
            sessionError = exception_util.GetExceptionDetails(e)
            raise
        finally:
            if batchRvtConfig.EnableDataExport:
                sessionEndTime = time_util.GetDateTimeNow()

                session_data_exporter.ExportSessionData(
                    batchRvtConfig.SessionId, batchRvtConfig.SessionStartTime,
                    sessionEndTime, batchRvtConfig.SessionDataFolderPath,
                    sessionError)

    Output()
    if aborted:
        Output("Operation aborted.")
    else:
        Output("Operation completed.")

        plainTextLogFilePath = logging_util.DumpPlainTextLogFile()
        if not str.IsNullOrWhiteSpace(plainTextLogFilePath):
            Output()
            Output()
            Output("A plain-text copy of the Log File has been saved to:")
            Output()
            Output("\t" + plainTextLogFilePath)

    Output()
    return
コード例 #8
0
def GetSupportedRevitFiles(batchRvtConfig):
    supportedRevitFileList = None

    revitFileListData = batchRvtConfig.ReadRevitFileListData(Output)

    if revitFileListData is not None:
        supportedRevitFileList = list(
            revit_file_list.SupportedRevitFileInfo(revitFilePathData)
            for revitFilePathData in revitFileListData)

        nonExistentRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not supportedRevitFileInfo.IsCloudModel()
                and not RevitFileExists(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (supportedRevitFileInfo.IsCloudModel()
                or RevitFileExists(supportedRevitFileInfo)))

        unsupportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList if
            not HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo))

        unsupportedRevitFilePathRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not supportedRevitFileInfo.IsCloudModel()
                and not HasSupportedRevitFilePath(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if ((supportedRevitFileInfo.IsCloudModel()
                 or RevitFileExists(supportedRevitFileInfo)) and
                (HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo)
                 ) and (supportedRevitFileInfo.IsCloudModel()
                        or HasSupportedRevitFilePath(supportedRevitFileInfo)))
        ).OrderBy(lambda supportedRevitFileInfo: GetRevitFileSize(
            supportedRevitFileInfo) if not supportedRevitFileInfo.IsCloudModel(
            ) else System.Int64(0)  # dummy file size value for Cloud models
                  ).ToList()

        nonExistentCount = len(nonExistentRevitFileList)
        unsupportedCount = len(unsupportedRevitFileList)
        unsupportedRevitFilePathCount = len(
            unsupportedRevitFilePathRevitFileList)

        if nonExistentCount > 0:
            Output()
            Output("WARNING: The following Revit Files do not exist (" +
                   str(nonExistentCount) + "):")
            for supportedRevitFileInfo in nonExistentRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files are of an unsupported version ("
                + str(unsupportedCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedRevitFilePathCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files have an unsupported file path ("
                + str(unsupportedRevitFilePathCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFilePathRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

    return supportedRevitFileList