Using SpeckleCore in Python Nodes


#1

Hi Tom and Izzy,
I’m having trouble with the very installation of PySpeckle.

I downloaded from https://github.com/speckleworks/PySpeckle and am importing SpeckleClient.py as a module into a GhPython component. However, it’s complaining about missing modules, namely requests. So I’m guessing I need some more installation.

You mention pip install Speckle, is that what I should be doing? In that case, how can I pip?

Since this post is about getting started, I hope my complete-noob question is adequate :slight_smile:
Thanks in advance,
Eduardo


Getting Started Using the API in Python
#2

I’m not sure compatibility between Rhino’s IronPython and requests… They seem not to work together from a quick search, but maybe you can find a workaround.

You’re better off using using a C# component and using the .NET Speckle libraries. They are more up-to-date and feature-complete anyway.

Is there any particular functionality that you are looking to use?


#3

Thanks Tom for the prompt reply. I’ll go for C# then - should I try to move this to another category?

Again, (please bear with me), how can I use it? I downloaded SpeckleCommon to a particular folder, but how can I have the C# GH component refer to the API on that folder? Do I need to compile what I downloaded into a dll and then manage assemblies? If there is a good tutorial online for this I’ll be happy to take it!

About the purpose, I’m aiming at a component that acts as a receiver for (a variable number of) multiple streams (3 or more). The overarching goal is to setup a simple multi user collaboration tool for Rhino - at this stage only for visualization…
For prototyping I’m using Grasshopper, but eventually I’d like to incorporate this functionality in a different C++ plugin I’m developing.


#4

hey Eduardo,

I don’t know much about GH but just wanted to throw out that if you want to use IronPython, you won’t be able to get requests as I believe one of its dependencies (think it’s six) is not compatible with IronPython. however, you can use WebRequest (from System.Net import WebRequest, WebHeaderCollection). here’s an example from the IronPython wiki.

I’ve been using this to talk to the Speckle API from Revit and it’s been working great! it’s a bit more code than the simple requests library, but it works :slight_smile:

edit: this doesn’t use PySpeckle so you won’t need to install anything extra


#5

You could also implement these directly in GHPython/IronPython.


#6

Good call! I actually remember referencing SpeckleCore.dll in a python node and starting to have fun in there.

I just gave it a very amateurish shot:

@Eduardo_Castro_e_Cos to avoid confusion: SpeckleCommon is an ancient name from speckle’s puberty, so to make sure you are on the right track, the speckle core is here. If you don’t want to build stuff yourself, install speckle via the “official” installer (download the .exe) and then reference things from the installation folder (to find it, go to plugin options in rhino and click on details, the path will be visible in the dialog that pops up for speckle).


#7

The two methods I’ve been going with for implementing .NET assemblies in GHPython (Kangaroo2, Plankton etc) has been:

  1. Assuming the path where the .dll file lives is already in the Rhino Python path. Which can be either hardcoded through the editpythonscripteditor options menu, or defined in the code using the sys.path.append() method.

  2. Assuming the .dll file lives in the default Grasshopper libraries folder. Get this path, append the assembly name onto it and reference the full path plus filename (this is neat in that it should work across all systems and requires no fiddling with the editpythonscripteditor or manual referencing like with the C# script editor).

Example 1:

import clr
clr.AddReferenceToFile("KangarooSolver.dll")
import KangarooSolver as ks

Example 2:

import clr
import Grasshopper as gh
clr.AddReferenceToFileAndPath(gh.Folders.DefaultAssemblyFolder + "KangarooSolver.dll")
import KangarooSolver as ks

Both these methods should circumvent any .dll hellishness, especially the latter as it can only point to one unique file.


#8

Thanks guys!
I followed Dimitri’s suggestion: it works but didn’t know what to do after :stuck_out_tongue:
I followed Anders’ Example 1: it works and can access the class YAY

I might be coming back with more questions…
Thanks again!