Coder Social home page Coder Social logo

pyrevit's Introduction

pyRevit for Autodesk Revit®

##What is pyRevit:

  • In it's simplest form, it's a folder filled with .py IronPython scripts for Revit.
  • There is also an IronPython script __init__.py that creates UI buttons for your IronPython scripts at Revit startup. Creating a button is as easy as adding a python script file to the pyRevit folder and reloading pyRevit. See below on how to add your scripts.

Installation:

package
DOWNLOAD SETUP PACKAGE

  • Download the setup package, extract to your machine and place under a folder of your choice.
  • Run Setup.bat and all scripts will be downloaded to this folder.
  • Setup script will create the necessary .addin file for Revit 2015 and 2016 to load the scripts at Revit startup.
  • Run Revit and pyRevit will automatically load.

This package installs a tiny addin on your Revit that its sole purpose in life is to run the __init__.py at Revit startup. This addin is named RevitPythonLoader and is a fork of RevitPythonShell. How does it find the __init__.py you ask? Through a windows environment variable called %pyRevit% that it also automatically creates at installation. This variable points to the folder containing the __init__.py file.

Neil Reilly has prepared a handy video taking you through the installation and showing some of the more useful tools. Click here to go to his Youtube page and watch the video.

NeilReillyVideo

About Versioning: I'm using semantic versioning with MAJOR.MINOR.PATCH format. (MAJOR: incompatible API changes, MINOR: add functionality and scripts in a backwards-compatible manner, PATCH: backwards-compatible bug fixes). You can see your pyRevit version under Settings -> aboutPyRevit

Using the scripts:

After you installed pyRevit and launched Revit, the startup script will find all the individual scripts and creates the UI buttons for the commands.

Just click on the pyRevit tab and click on the command you'd like run. Most command names are self-explanatory but there is a tooltip on the more complicated commands that describes the function. This tooltip is created from __doc__ string inside each .py file.

Adding your own scripts:

The __init__.py startup script will setup a ribbon panel named 'pyRevit' (After the folder name that contains the scripts). There are 5 ways to add buttons to this ribbon panel and categorize them under sub-panels.

####All the methods listed below, require a 32x32 pixel .png image file that will be used as the icon for the button or button group.


###Creating Pull Down Buttons: PulldownDemo

  • Step 1: Create a .png file, with this naming pattern: <00 Panel Order><00 Button Order>_<Panel Name>_PulldownButton_<Button Group Name>.png

    Example:
    1003_Selection_PulldownButton_Filter.png
    This .png file, defines a sub-panel under pyRevit ribbon panel named Selection, and a PulldownButton named Filter under this panel. Startup script will use the order numbers to sort the panels and buttons and later to create them in order.

  • Step 2: All .py script under the home directory should have the below name pattern: <Button Group Name>_<Script Command Name>.py.
    For the example above, any script that its name starts with Filter_ will be added to this PullDown button.

Scripts will be organized under the group button specified in the source file name. For example a script file named Filter_filterGroupedElements.py will be placed under group button Filter (defined by the .png above) and its command name will be filterGroupedElements. The .png file defining the Pulldown Button will be used as button icon by default, however, if there is a .png file with a matching name to a script, that .png file will override the default image and will be used as the button icon.

###Split Buttons: Creating Pull Down buttons that remember the last clicked button Same as Method 1 except it will create Split Buttons (The last selected sub-item will be the default active item).

For a SplitButton, create a .png file, with this naming pattern: <00 Panel Order><00 Button Order>_<Panel Name>_SplitButton_<Button Group Name>.png

SplitDemo


###Creating Push Buttons:
PushbuttonDemo

  • Step 1: Create a .png file, with this naming pattern: <00 Panel Order><00 Button Order>_<Panel Name>_PushButton_<Button Name>.png

    Example:
    1005_Revit_PushButton_BIM.png defines a sub-panel under pyRevit named Revit, and a simple Push Buttons in this panel named BIM. The startup script will expect to find only one script with name pattern similar to Method 1, and will assign it to this push button.

  • Step 2: All .py script under the home directory should have the below name pattern: <Button Group Name>_<Script Command Name>.py.
    For the example above, BIM_getCentralPath.py will be assigned to the push button described above. The button name will be getCentralPath.

####Link Buttons: Creating Push Buttons that Run other Addin's Commands This button is very similar to a PushButton except that it creates a link to a command of any other addin.
Create a .png file, with the same naming pattern as Method 1, but also add <Assembly Name> and <C# Class Name> to the filename separated by _.

Example:
0000_RPS_PushButton_RPS_RevitPythonShell_IronPythonConsoleCommand.png

This defines a sub-panel under pyRevit, named RPS, and a simple Push Buttons in this panel, named RPS. But then the startup script will use the <Assembly Name> and <C# Class Name> and will look for the referenced addin and class. If this addin has been already loaded into Revit, the startup script will assign the <C# Class Name> to this button. In this example, startup script will create a button that opens the 'Interactive Python Shell' from RevitPythonShell addin.

Another example of this method is 0005_RL_PushButton_Lookup_RevitLookup_CmdSnoopDb.png that will create a button calling the 'Snoop DB' command of the RevitLookup addin.

Notice that this type of button does not need any external scripts. This single .png file has all the necessary information for this link button.


###Creating Stack of Push Buttons: Stack3Demo

  • Step 1: Create a .png file, with this naming pattern: <00 Panel Order><00 Button Order>_<Panel Name>_Stack3_<Stack Name>.png

    Example:
    1005_Selection_Stack3_Inspect.png defines a sub-panel under pyRevitnamed Selection, and 3 Stacked Buttons in this panel. For a Stack3 button group, the startup script will expect to find exactly 3 scripts to be categorized under this stack. The actual stack name will be ignored since the stack doesn't have any visual representation other then the 3 buttons stacked in 3 rows.

  • Step 2: All .py script under the home directory should have the below name pattern: <Button Group Name>_<Script Command Name>.py.
    In this example the 3 scripts below will be used to create 3 buttons in this stack (sorted alphabetically):

    Inspect_findLinkedElements.py
    Inspect_findListOfViewsShowingElement.py
    Inspect_findPaintedSurfacesOnSelected.py

Reloading the scripts library:

ReloadScripts

pyRevit commands only keep a link to the actual IronPython script file. Revit reads and runs the script file any time the user clicks on the corresponding button. This means you can edit any script while Revit is running and the next time you click on the corresponding script button, Revit will run the modified script file.

If you added scripts or panels while Revit is running, use the reloadScripts button from the Settings group to reload the changes. It'll search for the scripts and will update the buttons, disabling the missing and adding the newly found.

Keeping your library up to date:

Use the downloadUpdates button under the Settings pull down to fetch all the recent changes from the github repository.

DownloadUpdates

pyRevit will open a window and will fetch the most recent changes from the github repository. Keep in mind that the changes you have made to the original scripts included in the library will be overwritten. Any extra scripts and file will remain intact. After the update, click on Reload Scripts to get buttons for any newly added script.

FetchingUpdates

Reinstall / Uninstall:

Run Setup.bat and it'll prompt you that the pyRevit or RevitPythonLoader folders already exist and if you want to Reinstall pyRevit. If you answer yes, it'll delete the folders and re-clones the github repositories just like a fresh install.

Reinstall

If you answer No, It'll ask you if you want to uninstall the tool. The setup script will remove the .addin files and %pyrevit% environment variable when uninstalling pyRevit.

Reinstall

Contribute

And please feel free to fork, modify and add your own scripts, and send me pull requests. I'd be thrilled to add more tools and scripts to this for everyone to use.

Support

stackoverflow (Note: use pyRevit tag)

License

This package is licensed under GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007. See LICENSE.md for full license text. See this page for more help on licensing your work.

Credits

I'd like to thank people listed here for their great contributions:

NOTE: If you are not on this list, but believe you should be, please contact me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.