Revit connected and disconnected continuity nodejs server.

Revit connected and disconnected continuity nodejs server.

mr.engineer.aec
Advocate Advocate
731 Views
2 Replies
Message 1 of 3

Revit connected and disconnected continuity nodejs server.

mr.engineer.aec
Advocate
Advocate

 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.
1.png

2.png

 

 

#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);
    }
  }
}

 

 

0 Likes
Accepted solutions (1)
732 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Please start from scratch with a simpler sample.

  

Roomedit3d is far too complex for anyone else to help you with.

 

Sorry, but that is a sample you will have to handle yourself or not at all, as far as I can judge.

  

If you want to start working with Revit Design Automation and Forge, I would suggest starting our from one of the more recent official samples:

 

https://forge.autodesk.com/api/design-automation-cover-page/

  

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

mr.engineer.aec
Advocate
Advocate

 Thank you for the advice. I'll do it.
I'll comeback roomedit3d later.

0 Likes