Send Message to GIS or Revit from a Terminal using RabbitMQ, Python, Pika and C#

19 Apr

I have been playing with messaging in software applications. Using RabbitMQ, C# and Python, I got the bright idea to send messages to GIS from a python console – which will later be another program or windows form, but for demo purposes I just needed to verify the possibility. The SDK for my GIS is in C#, and so is the SDK for Revit.
I will show you what I did in GIS and then explain how this would work in Revit.
First, I sent a message to the GIS software.
The DOS window is my command center that sends the messages. You can see that there are two commands: one has JOE and one has PAUL in it. You can send messages to every listener, or you can specify a keyword or word pattern – in this case PAUL and JOE are the keywords. My GIS app will only receive messages sent to PAUL. When you click the button, it grabs all waiting messages.
If I can send text, I can send data too. What if I send coordinates? I can draw them in the map.
Now it takes the message and does something with it. This example has the sender and receiver on the same machine, but they do not have to be. So for Revit, what if we had a window that could update schedules in Revit with data. A user could input the data and the Revit user could press a button to update the model with the new data. Perfect for additional fields in a schedule. Or you could set it to run as a thread so when a message comes in the box pops up automatically. Here is the Code for the Plugin:
string msg = null;
var connectionFactory = new ConnectionFactory();
IConnection connection = connectionFactory.CreateConnection();
IModel channel = connection.CreateModel();
BasicGetResult result = channel.BasicGet(“GIS”, true);
if (result != null)
msg = Encoding.UTF8.GetString(result.Body);
MessageBox.Show(msg, “Status”);

MessageBox.Show(“No Messages Waiting.”, “Status”);
And the sender in python:
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(
channel =
to = sys.argv[1]
message = ‘ ‘.join(sys.argv[2:])
print “Sent %r:%r” % (to, message)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: