Connecting to Ecotect using DDE and VB.NET

When Ecotect is launched, it automatically creates a Dynamic Data Exchange server which allows the program to be accessed by remote applications. By accessing the DDE server, you can send commands to Ecotect as well as request information. Ecotect must always be running in the background for this to work. While DDE is older technology (in dotNet, it was replaced by "remoting"), it works quite well in this context.

A fine example of using DDE and Ecotect are uto's custom GH to Ecotect components

A special thanks to Thomas from uto for cluing me in on Ecotect's use of DDE!

WHAT you will need…

1. Ecotect Analysis software
2. A VB.NET or C# application (in Grasshopper, you can use the scripting components)
3. A DDE class library (VB.NET needs the binary dll referenced): http://ndde.codeplex.com/

The Code:

To create a "client" connection to Ecotect's "server" you can use the following code.

  • Ecotect needs to be running in the background for this code to work.
  • Be sure the NDde.dll is referenced in your application so you can access it within VB.NET

EXECUTE A COMMAND

Imports System
Imports NDde.Client

Sub EcotectCommand()

    'create an Ecotect command string.  
    Dim ecotectCommand As String = "weather.load.all, <file location>"

    Try
        ' Create a client that connects to 'Ecotect'.
        Using client As ndde.Client.DdeClient = New ndde.Client.DdeClient("Ecotect", "execute")

        ' Connect to the server.
        client.Connect()

        ' Execute remote command in Ecotect
        client.Execute(ecotectCommand, 6000)

End Using

    Catch e As Exception
    Print(e.message)

    End Try

End Sub

REQUEST INFORMATION

Imports System
Imports NDde.Client

Sub EcotectRequest()

    'create an Ecotect request string.  
    Dim ecotectRequest As String = "get.node.pos 22 8"

    Try
        ' Create a client that connects to 'Ecotect'.
        Using client As ndde.Client.DdeClient = New ndde.Client.DdeClient("Ecotect", "request")

        ' Connect to the server.
        client.Connect()

        ' Request information from Ecotect
        client.request(ecotectRequest, 6000)

End Using

    Catch e As Exception
    Print(e.message)

    End Try

End Sub
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License