-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add ability to run custom cli commands
- Loading branch information
Showing
13 changed files
with
217 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from cli.command import * | ||
from cli.app import * | ||
from cli.config import * | ||
from cli.environment import * | ||
from cli.log import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pyrevit import HOST_APP | ||
from cli.config import Config | ||
|
||
|
||
class App(): | ||
|
||
@staticmethod | ||
def open(detach=True): | ||
config = Config(detach) | ||
|
||
return HOST_APP.uiapp.Application.OpenDocumentFile( | ||
config.modelPath, config.openOptions | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,13 @@ | ||
import sys | ||
import os | ||
from os.path import dirname | ||
from pyrevit import HOST_APP | ||
|
||
sys.path.append(dirname(dirname(dirname(__file__)))) | ||
|
||
import revitron | ||
from cli import getEnv, getLogFromEnv | ||
from cli.config import Config | ||
from cli import App, getLogFromEnv | ||
|
||
env = getEnv() | ||
log = getLogFromEnv().write | ||
config = Config(detach=False) | ||
|
||
revitron.DOC = HOST_APP.uiapp.Application.OpenDocumentFile( | ||
config.modelPath, config.openOptions | ||
) | ||
revitron.DOC = App.open(False) | ||
|
||
try: | ||
syncOptions = revitron.DB.SynchronizeWithCentralOptions() | ||
syncOptions.Compact = True | ||
syncOptions.Comment = 'Compact model' | ||
syncOptions.SaveLocalAfter = False | ||
syncOptions.SaveLocalBefore = False | ||
revitron.DOC.SynchronizeWithCentral( | ||
revitron.DB.TransactWithCentralOptions(), syncOptions | ||
) | ||
if revitron.Document().synchronize(compact=True, comment='Compact model'): | ||
log('Synching finished successfully') | ||
except Exception as e: | ||
else: | ||
log('Synching failed') | ||
log(str(e)) | ||
|
||
revitron.DOC.Close(False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sys | ||
from os.path import dirname | ||
|
||
sys.path.append(dirname(dirname(__file__))) | ||
|
||
from cli import getEnv, getLogFromEnv | ||
|
||
env = getEnv() | ||
log = getLogFromEnv().write | ||
|
||
log('Running task {}'.format(env.task)) | ||
|
||
execfile(env.task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
Command Line | ||
============ | ||
|
||
Revitron ships its own little wrapper for the *pyRevit* CLI that includes some additional features such as the | ||
ability to handle cloud models and to pass configuration files. | ||
|
||
.. code-block:: | ||
revitron [command] "path\to\config.json" | ||
Standard Commands | ||
----------------- | ||
|
||
Revitron ships with two default commands. | ||
|
||
=============== ===================================================================================== | ||
Command Description | ||
=============== ===================================================================================== | ||
``analyze`` Creates analytical snapshots from models. More `here <analyze.html>`_. | ||
``compact`` Compacts a model. The configuration JSON file only has to include `model` and `revit` | ||
fields. | ||
=============== ===================================================================================== | ||
|
||
Compact Example | ||
~~~~~~~~~~~~~~~ | ||
|
||
The configuration for the ``compact`` command operating on cloud models looks as follows: | ||
|
||
.. code-block:: json | ||
{ | ||
"model": { | ||
"type": "cloud", | ||
"projectGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | ||
"modelGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | ||
"region": "EMEA" | ||
}, | ||
"revit": "2022" | ||
} | ||
Alternatively local models have a slightly different configuration: | ||
|
||
.. code-block:: json | ||
{ | ||
"model": { | ||
"type": "local", | ||
"path": "C:\\path\\to\\model.rvt" | ||
}, | ||
"revit": "2022" | ||
} | ||
The compacting can be started with the following command. Manually or as a command used in a task scheduler. | ||
|
||
.. code-block:: | ||
revitron compact "path\to\config.json" | ||
Custom Commands | ||
--------------- | ||
|
||
Revitron supports custom commands as well to be used with the CLI. In order to be used as a command, | ||
a command has to meet the following requirements for its location and its content. | ||
|
||
Location | ||
~~~~~~~~ | ||
|
||
In order to be picked up as a valid command, a custom command file must have the ``.cli.py`` extension | ||
and be located somewhere subdirectory tree of the main extension directory of pyRevit. It is strongly recommended | ||
to ship commands as Revitron packages that will be installed automatically in the correct location by the Revitron | ||
package manager. | ||
|
||
Anatomy | ||
~~~~~~~ | ||
|
||
You can use one of the following example commands below in order to quickly get a custom command up and running: | ||
|
||
.. code-block:: python | ||
import revitron | ||
from cli import App, Config, getLogFromEnv | ||
# Get the config dictionary from the JSON file. | ||
config = Config().get() | ||
# Get a log handle to use for logging. | ||
log = getLogFromEnv().write | ||
log('Hello') | ||
# Open the model that is configured in the JSON file. | ||
# Use App.open(True) in order to open and detach the file. | ||
revitron.DOC = App.open(True) | ||
# Implement your functionality here. | ||
# Use the config dict in order to access your configuration stored | ||
# in the JSON file that is passed as CLI argument. | ||
revitron.DOC.Close(False) | ||
In order to sync changes that have been applied by your command, you can use the following boiler plate | ||
that includes synching as well. | ||
|
||
.. code-block:: python | ||
import revitron | ||
from cli import App, Config, getLogFromEnv | ||
config = Config().get() | ||
log = getLogFromEnv().write | ||
revitron.DOC = App.open(False) | ||
# Implement your functionality here before synching ... | ||
if revitron.Document().synchronize(compact=True, comment='Some comment'): | ||
log('Synching finished successfully') | ||
else: | ||
log('Synching failed') | ||
revitron.DOC.Close(False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ Revitron | |
|
||
get-started | ||
revitron | ||
cli | ||
analyze | ||
cheat-sheet | ||
genindex | ||
|
Oops, something went wrong.