Hey all,
I was wondering if there is a way to run a python script from a add-in I created? For Example: I push a button on my ribbon and it runs the python version of “Hello World”.
Where I work, I am unable to install PyRevit or any other add-ins unless pre-approved and I could wait years for approval (If I get it)
Hey Nick,
My goal in Revit is to run reports. When the ‘hello world’ button is selected, I just want it to report project information back to me (from the hello world.py script.)
As for running equivalent code, I am assuming your referring to C#? Answer to that my friend is, I am fairly new to coding and Python is the quickest for me to do. Eventually I’ll expand but for now, I’m pushing to learn Python.
If I can write the whole add-in in python, I would be more than happy to do that but again, still learning.
I’m usure if i am not understanding the question(s)? here, but here is my take on this.
First question: Can you run a Python script from an add-in i created?
A: There isn’t sufficient information to answer this question if you made the add-in. You were the creator of the add-in so maybe you tell us if it can run a Python script? (If you were asking if it wis possible to do so…yes is the answer, but not really at a beginner level unless you find a step by step guide out there.)
Second Question: Can you report information back to you if the button is pressed.
A: Yes, @GavinCrump has done a nice video on this with the use of his custom package (Crumple)
If i’m honest, i would be trying to install pyRevit if you want a button. (My company has pretty strict policy on external programs) But for whatever reason pyRevit slips the gaps and i can still install it without administrator privilages.
If you cannot install pyRevit, i wouldn’t be going down the road of making a new add-in for yourself, the countless hours you are going to spend developing it are not going to outweight simply developing scripts for use in the Dynamo player as a comparison and waiting the 10 seconds to open dynamo when you start working in Revit, especially considering its at best a temporary solution as its only a problem at your current company.
Lazy/over secure IT departments are the ruination of many good firms. Escalate this to your BIM managers and org managers if it is a productivity issue for the firm.
All I am asking is if I can use my add-in button on the ribbon to invoke a python script to report back to me. I already use dynamo, player and such. Waiting on the government to approve certain add-ons will not happen.
You could. But you like are sensing that none of the people who’ve replied to the post think you should do so.
If you can’t get another tool approved and you don’t want to use Dynamo Player, then the time it’ll take to write the add-in and the associated UI to have a button to launch whatever Revit tied Python flavor you’re using and run the python will be as bad if not worse than translating the Python over to C# and just running that natively.
One other thing to consider: you’re in the last 18 months or so of Python 2 availability without an additional installation which would have to be approved per govt mandates, and they won’t green light it as it’s officially unsupported for over 2 years now. As such that Python will need to be re-written for Python 3 (with all the non-avoidable bugs that introduces) in the near term. As such I’m firmly in camp “build it all as an add-in and remove the Python dependency entirely.” It doesn’t make sense to build a tool as you’re asking atop the house of cards created by the constraints you’re under.
Jacob and all,
Thank you for the responses and questions/input.
I do have certain workarounds for python I am currently working with Python 3 and converting everything I can from P2 to P3.
The reason I am adamant about writing in python, is because I am also learning python for programming outside of this industry. Eventually I will pickup some more languages but for now I want to be decent in Python.
I did get my button to work this morning. I used the RunPythonScript method.