RPS 2017 - ExternalEvents

100 views
Skip to first unread message

Callum

unread,
Nov 6, 2016, 4:02:18 PM11/6/16
to RevitPythonShell
Hey everyone, has anyone been able to successfully Raise() an ExternalEvent in R2017? Im finding code that worked well in previous versions isnt working in worked in R2017:

- The result of the ExternalEvent.Raise() call is 'Accepted'
- Have tried from the modal and non-modal versions of RPS console with no success
- Have looked in 'Whats New in the R2017 API' list and cant see anything relevant to External Events

Im loving 2017 version of RPS by the way, when code fails in the console it no longer throws an exception and crashes the console, rather it prints out the stack traceback in the console and you can carry on fine. Awesome!

Daren Thomas

unread,
Nov 8, 2016, 10:20:33 AM11/8/16
to revitpyt...@googlegroups.com
Hey Callum,

could you post an example of using ExternalEvent here? I'd like to test it out...

Best,
Daren

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshell+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Callum

unread,
Nov 9, 2016, 3:07:48 PM11/9/16
to RevitPythonShell
Sure Daren, here is a simple example to create some files on your desktop;


# this script should create three files on your desktop, however the last file isnt created because the external event is not executed.
 
# external event set up.txt (correctly set up extrernal event)
# external event rasied - Accepted.txt (extrernal event was successfully raised by Revit)
# external event executing.txt (extrernal event is being Executed by Revit)

__window__
.Close() # External events are only Executed when Revit is idle, so we need to close the shell

import clr
import os

clr
.AddReference('RevitAPI')
clr
.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

def makeFile(name):
     path
= os.path.expanduser('~')+'\\Desktop\\'
     file
= open (path+str(name)+'.txt', 'w+')
     file
.close()
 
class extEventHandle(IExternalEventHandler):
 
     def __init__(self):
          makeFile
('external event set up')
 
     def Execute(self, __revit__): # run after external event is raised, then when Revit is idle
         
makeFile('external event executing')
 
eventHandler
= extEventHandle()
externalEvent
= ExternalEvent.Create(eventHandler)
result
= externalEvent.Raise()


makeFile
('external event rasied - '+str(result))

To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.

Callum

unread,
Nov 28, 2016, 2:01:30 PM11/28/16
to RevitPythonShell
Has anyone else had this problem / been able to verify this bug?

prmo...@gmail.com

unread,
Dec 2, 2016, 11:07:41 AM12/2/16
to RevitPythonShell
Hi Callum,

I tried your script in R2016 and R2017 with the same results,
In fact, you have to implement the GetName method in Revit2017 to return an event name :

class extEventHandle(IExternalEventHandler):
 
     
def __init__(self):
         
          makeFile
('1 external event set up')
         
     
def GetName(self):
         
return 'eventHandlerName'

     
     
def Execute(self, __revit__): # run after external event is raised, then when Revit is idle

          makeFile
('3 external event executing')
this class works fine with my setup... got the 3 files ! :))

Daren Thomas

unread,
Dec 5, 2016, 4:11:21 AM12/5/16
to revitpyt...@googlegroups.com
It seems @PMoureu is onto something: Adding the `GetName` method to the `ExternalEvent` fixes the problem!

I have updated the sample for the RpsHttpServer to reflect this.

Best,
Daren

To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshell+unsubscribe@googlegroups.com.

Callum

unread,
Dec 5, 2016, 2:26:06 PM12/5/16
to RevitPythonShell
Awesome @PMoureu, that worked perfectly all the way back to R2014

Thanks!
Reply all
Reply to author
Forward
0 new messages