Michelle
Michelle

Reputation: 93

Is there a way when starting Revit Python Shell to have init.py print extra status info?

It looks I need to clarify my intent for this posting. I am looking to display information when starting the interactive Revit Python Shell. I am not looking to run a script at Revit startup or any other time. I am not looking to create a script to run as a utility.

Non-Modal Shell

I have seen this statement in the RPS configuration dialog:

"The InitScript is a python script run everytime an interactive shell is opened. It is commonly used to performe initialization of helper functions and variables."

Ok...so I modify this file to do things like "import pyrevit". All of this I have working. However, I want to print a message to the interactive shell stating that pyrevit has been loaded into this RPS session.

For example, I have these lines in the init.py file:

MJM_Notes = "\n==== MJM Notes ====\n"
MJM_Notes = MJM_Notes + "Some Preloaded Varibles:\n"
MJM_Notes = MJM_Notes + "   selection (user selected elements at startup\n"
MJM_Notes = MJM_Notes + "   selection (user selected elements at startup\n"
MJM_Notes = MJM_Notes + "   UIApplication\n"
MJM_Notes = MJM_Notes + "   doc = __revit__.ActiveUIDocument.Document\n"
MJM_Notes = MJM_Notes + "   lookup() - Database explorer tool\n"

MJM_Notes = MJM_Notes + "\nPreloaded Modules:\n"
MJM_Notes = MJM_Notes + "  CLR loaded (It is part of .NET)\n"

import pyrevit
MJM_Notes = MJM_Notes + "  PyRevit Loaded. Version: " + pyrevit.VERSION_STRING + "\n"

import rpw
MJM_Notes = MJM_Notes + "  Revit Python Wrapper Loaded. Version: " + rpw.__version__ + "\n"

None of the above causes an error. But adding the print statement below causes the RPS to "hang"

print MJM_Notes

Here is a screen shot of RPS - note the missing ">>>": Hung RPS

At this point, I am not sure if RPS allows print statements in the init.py file, or if this is a bug in RPS, or if there is a different way to accomplish what I wish to do, or if I what I want is even possible.

I did not see anything on this webpage RPS Readme to address this issue.

Sincerely; Michelle

------ Original Post ---------- When I start Revit Python Shell it displays the message shown below before the command prompt.

IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.

I would like to display additional info like this:

==== MJM Notes ====
Some Preloaded Varibles:
   selection (user selected elements at startup
   selection (user selected elements at startup
   UIApplication
   doc = __revit__.ActiveUIDocument.Document
   lookup() - Database explorer tool

Preloaded Modules:
  CLR loaded (It is part of .NET)
  PyRevit Loaded. Version: 4.8.9.21361+0320
  Revit Python Wrapper Loaded. Version: 1.7.4

==== MJM Notes ====

What would be the best way to do this? I have tried adding a print statement to init.py with less than perfect results. (Basically, it prints the message and then "hangs" - no command prompt.)

Sincerely; Michelle

Upvotes: 1

Views: 426

Answers (2)

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

I would suggest forking and cloning the RPS repository, then globally searching it for the string that is printed by default, to see where it comes from and how it is generated. At that point, determine whether and how you can add functionality to enhance the string according to your wishes.

Upvotes: 0

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

Yes, this is definitely possible. Look at the RPS repository readme; it clearly states: Features: ... run scripts at Revit startup. So, the next step I would recommend you take is to read the RPS documentation and see how to run a script at startup. Such a script can almost certainly achieve the task you describe. Please always be aware that a lot of work has been put into writing, publishing and maintaining the RPS documentation and samples. It is a shame to waste it by not even looking up basic questions.

Upvotes: 1

Related Questions