"""Hops default HTTP server example""" import ghhops_server as hs import rhino3dm hops = hs.Hops() @hops.component( "/add", name="Add", nickname="Add", description="Add numbers with CPython", category="Maths", subcategory="CPython", inputs=[ hs.HopsNumber("A", "A", "First number"), hs.HopsNumber("B", "B", "Second number"), ], outputs=[hs.HopsNumber("Sum", "S", "A + B")], ) def add(a, b): # testing error report f = 12 / 0 return a + b @hops.component( "/pointat", name="PointAt", nickname="PtAt",
from flask import Flask import ghhops_server as hs from ghhops_server.params import HopsCurve, HopsInteger, HopsNumber import rhino3dm as rh from owlready2 import * # register hops app as middleware app = Flask(__name__) hops: hs.HopsFlask = hs.Hops(app) # flask app can be used for other stuff drectly @app.route("/help") def help(): return "Welcome to Grashopper Hops for CPython!" #-- Point At component --# @hops.component( "/pointat", name="PointAt", description="Get a point along a curve", inputs=[ hs.HopsCurve("Curve", "C", "Curve to evaluate"), hs.HopsNumber("t", "t", "Parameter on Curve to evaluate.") ], outputs=[ hs.HopsPoint("P", "P", "Point on Curve at parameter t") ] ) def pointat(curve: rh.Curve, t: float=0): pt = curve.PointAt(t)
from flask import Flask import ghhops_server as hs app = Flask(__name__) hops = hs.Hops(app) import meshpath as mp import meshutils as mu import kmeans #MESH WALKER COMPONENT --------------------- #global variables for meshwalker component walkerGraph = None @hops.component( "/meshwalker", name = "meshwalker", inputs=[ hs.HopsBoolean("reset","R","reset button"), hs.HopsMesh("Input Mesh", "M", "Mesh"), hs.HopsInteger("face Index 1","f1","Face index one"), hs.HopsInteger("face Index 2","f2","Face index two") ], outputs=[ hs.HopsPoint("list of points","P","shortest path points", hs.HopsParamAccess.LIST), hs.HopsInteger("list of faces indexes","F","shortest path face indexes", hs.HopsParamAccess.LIST) ] ) def meshwalker(reset, mesh, f1, f2):
import rhinoinside import ghhops_server as hs rhinoinside.load(r"C:\Program Files\Rhino 7\System") import Rhino import Rhino.Geometry as rg hops = hs.Hops(app=rhinoinside) import networkx as nx import MeshPaths as mp @hops.component( "/MeshPathWalker", name="MeshPathWalker", description= " Make a networkx graph with mesh vertices as nodes and mesh edges as edges ", inputs=[ hs.HopsMesh("Mesh", "M", "Mesh to make networkx graph for"), hs.HopsString("WeightMode ", "W", "Weight Mode"), hs.HopsString("GraphType", "T", "Mesh Graph Type"), hs.HopsLine("SLine", "L", "Line to process"), hs.HopsString("mode", "m", "Shortest Path Mode") ], outputs=[ hs.HopsPoint("ShortestPath", "SP", "Shortest Path", hs.HopsParamAccess.LIST), hs.HopsString("FacesIndex", "I", "Faces indexes", hs.HopsParamAccess.LIST) ]) def MeshPathWalker(mesh, weightMode, GraphType, SLine, mode):