Skip to content

Commit 136e3dc

Browse files
committed
ADD Http Listener
1 parent a73bc9d commit 136e3dc

File tree

6 files changed

+149
-3
lines changed

6 files changed

+149
-3
lines changed

deps/eigen

Submodule eigen updated from 8b4efc8 to 171bd08

deps/pybind11

Submodule pybind11 updated 191 files
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#! python3
2+
3+
from ghpythonlib.componentbase import executingcomponent as component
4+
import os
5+
import tempfile
6+
import requests
7+
import threading
8+
import Rhino
9+
import Rhino.Geometry as rg
10+
import scriptcontext as sc
11+
12+
13+
class DFHTTPListener(component):
14+
15+
def RunScript(self,
16+
i_load: bool,
17+
i_ply_url: str):
18+
19+
sc.sticky.setdefault('ply_url', None)
20+
sc.sticky.setdefault('imported_geom', None)
21+
sc.sticky.setdefault('status_message','Idle')
22+
sc.sticky.setdefault('prev_load', False)
23+
sc.sticky.setdefault('thread_running', False)
24+
25+
def _import_job(url):
26+
try:
27+
if not url.lower().endswith('.ply'):
28+
raise ValueError("URL must end in .ply")
29+
30+
resp = requests.get(url, timeout=30); resp.raise_for_status()
31+
fn = os.path.basename(url)
32+
tmp = os.path.join(tempfile.gettempdir(), fn)
33+
with open(tmp, 'wb') as f:
34+
f.write(resp.content)
35+
36+
doc = Rhino.RhinoDoc.ActiveDoc
37+
before_ids = {o.Id for o in doc.Objects}
38+
39+
opts = Rhino.FileIO.FilePlyReadOptions()
40+
ok = Rhino.FileIO.FilePly.Read(tmp, doc, opts)
41+
if not ok:
42+
raise RuntimeError("Rhino.FilePly.Read failed")
43+
44+
after_ids = {o.Id for o in doc.Objects}
45+
new_ids = after_ids - before_ids
46+
47+
geom = None
48+
for guid in new_ids:
49+
g = doc.Objects.FindId(guid).Geometry
50+
if isinstance(g, rg.PointCloud):
51+
geom = g.Duplicate()
52+
break
53+
elif isinstance(g, rg.Mesh):
54+
geom = g.DuplicateMesh()
55+
break
56+
57+
for guid in new_ids:
58+
doc.Objects.Delete(guid, True)
59+
doc.Views.Redraw()
60+
61+
sc.sticky['imported_geom'] = geom
62+
count = geom.Count if isinstance(geom, rg.PointCloud) else geom.Vertices.Count
63+
if isinstance(geom, rg.PointCloud):
64+
sc.sticky['status_message'] = f"Done: {count} points"
65+
else: sc.sticky['status_message'] = f"Done: {count} vertices"
66+
ghenv.Component.Message = sc.sticky.get('status_message')
67+
68+
except Exception as e:
69+
sc.sticky['imported_geom'] = None
70+
sc.sticky['status_message'] = f"Error: {e}"
71+
finally:
72+
try: os.remove(tmp)
73+
except: pass
74+
sc.sticky['thread_running'] = False
75+
ghenv.Component.ExpireSolution(True)
76+
77+
if sc.sticky['ply_url'] != i_ply_url:
78+
sc.sticky['ply_url'] = i_ply_url
79+
sc.sticky['status_message'] = "URL changed. Press Load"
80+
sc.sticky['thread_running'] = False
81+
sc.sticky['prev_load'] = False
82+
83+
if i_load and not sc.sticky['prev_load'] and not sc.sticky['thread_running']:
84+
sc.sticky['status_message'] = "Loading..."
85+
sc.sticky['thread_running'] = True
86+
threading.Thread(target=_import_job, args=(i_ply_url,), daemon=True).start()
87+
88+
sc.sticky['prev_load'] = i_load
89+
ghenv.Component.Message = sc.sticky.get('status_message', "")
90+
91+
# output
92+
o_geometry = sc.sticky.get('imported_geom')
93+
94+
return [o_geometry]
4.24 KB
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "DFHTTPListener",
3+
"nickname": "HTTPIn",
4+
"category": "diffCheck",
5+
"subcategory": "IO",
6+
"description": "This component reads a ply file from the internet.",
7+
"exposure": 4,
8+
"instanceGuid": "ca4b5c94-6c85-4bc5-87f0-132cc34c4536",
9+
"ghpython": {
10+
"hideOutput": true,
11+
"hideInput": true,
12+
"isAdvancedMode": true,
13+
"marshalOutGuids": true,
14+
"iconDisplay": 2,
15+
"inputParameters": [
16+
{
17+
"name": "i_load",
18+
"nickname": "i_load",
19+
"description": "Button to import ply from url.",
20+
"optional": true,
21+
"allowTreeAccess": true,
22+
"showTypeHints": true,
23+
"scriptParamAccess": "item",
24+
"wireDisplay": "default",
25+
"sourceCount": 0,
26+
"typeHintID": "bool"
27+
},
28+
{
29+
"name": "i_ply_url",
30+
"nickname": "i_ply_url",
31+
"description": "The url where to get the pointcloud",
32+
"optional": true,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "str"
39+
}
40+
],
41+
"outputParameters": [
42+
{
43+
"name": "o_geometry",
44+
"nickname": "o_geo",
45+
"description": "The mesh or pcd that was imported.",
46+
"optional": false,
47+
"sourceCount": 0,
48+
"graft": false
49+
}
50+
]
51+
}
52+
}

src/gh/diffCheck/diffCheck.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: diffCheck
3-
Version: 0.0.37
3+
Version: 1.3.0
44
Summary: DiffCheck is a package to check the differences between two timber structures
55
Home-page: https://github.com/diffCheckOrg/diffCheck
66
Author: Andrea Settimi, Damien Gilliard, Eleni Skevaki, Marirena Kladeftira, Julien Gamerro, Stefana Parascho, and Yves Weinand

0 commit comments

Comments
 (0)