Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
Hi Mr.Jeremy Tammik,
I'm trying to connect revit to server nodejs localhost follow the directions of Mr.Jeremy Tammik (roomedit3d).
When i test by Program.cs . Everything seem fine.
But when i test code to Revit listen event from server isn't fine. Nothing happened in Revit
I don't know why.
Please help me if you can.
Many thanks.
#region Namespaces
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Newtonsoft.Json.Linq;
using Quobject.SocketIoClientDotNet.Client;
#endregion
namespace Roomedit3dApp
{
class App : IExternalApplication
{
/// <summary>
/// Caption
/// </summary>
public const string Caption = "Roomedit3d";
/// <summary>
/// Socket broadcast URL.
/// </summary>
const string _url = "http://localhost:3000";
#region External event subscription and handling
/// <summary>
/// Store the external event.
/// </summary>
static ExternalEvent _event = null;
/// <summary>
/// Store the external event.
/// </summary>
//static BimUpdater _bimUpdater = null;
static VisibleData _visibleData = null;
/// <summary>
/// Store the socket we are listening to.
/// </summary>
static Socket _socket = null;
/// <summary>
/// Enqueue a new BIM updater task.
/// </summary>
public static void VisibleData(object data)
{
JObject data2 = JObject.FromObject(data);
_visibleData.Enqueue(data2.ToString());
TaskDialog.Show("abc", data2.ToString());
_event.Raise();
}
/// <summary>
/// Toggle on and off subscription to automatic
/// BIM update from cloud. Return true when subscribed.
/// </summary>
public static bool ToggleSubscription()
{
if ( null != _event )
{
Util.Log( "Unsubscribing..." );
_socket.Disconnect();
_socket = null;
//_bimUpdater = null;
_visibleData = null;
_event.Dispose();
_event = null;
Util.Log( "Unsubscribed." );
//Util.Log("Goodbye Tester !");
}
else
{
Util.Log( "Subscribing..." );
//_bimUpdater = new BimUpdater();
_visibleData = new VisibleData();
var options = new IO.Options()
{
IgnoreServerCertificateValidation = true,
AutoConnect = true,
ForceNew = true
};
_socket = IO.Socket( _url, options );
_socket.On( Socket.EVENT_CONNECT, ()
=> Util.Log( "Connected" ) );
//_socket.On( "transform", data
// => Enqueue( data ) );
_socket.On("send-data-from-server", data
=> VisibleData(data));
//_event = ExternalEvent.Create( _bimUpdater );
_event = ExternalEvent.Create(_visibleData);
Util.Log( "Subscribed." );
//Util.Log("Hello Tester !");
}
//return false;
return null != _event;
}
#endregion // External event subscription and handling
public Result OnStartup( UIControlledApplication a )
{
return Result.Succeeded;
}
public Result OnShutdown( UIControlledApplication a )
{
return Result.Succeeded;
}
}
}
Here is IExternalEventHandler:
#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;
#endregion
namespace Roomedit3dApp
{
/// <summary>
/// BIM updater, driven both via external
/// command and external event handler.
/// </summary>
class VisibleData : IExternalEventHandler
{
/// <summary>
/// The queue of pending tasks consisting
/// of UniqueID and translation offset vector.
/// </summary>
Queue<string> _queue = null;
public VisibleData()
{
_queue = new Queue<string>();
}
/// <summary>
/// Execute method invoked by Revit via the
/// external event as a reaction to a call
/// to its Raise method.
/// </summary>
public void Execute(UIApplication a)
{
Document doc = a.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc))
{
t.Start("Visible data");
TaskDialog.Show("Test", _queue.Dequeue());
t.Commit();
}
}
/// <summary>
/// Required IExternalEventHandler interface
/// method returning a descriptive name.
/// </summary>
public string GetName()
{
return App.Caption + " " + GetType().Name;
}
/// <summary>
/// Enqueue a BIM update action to be performed,
/// consisting of UniqueID and translation
/// offset vector.
/// </summary>
public void Enqueue( string uid)
{
_queue.Enqueue(uid);
}
}
}
Solved! Go to Solution.