# Objects in compas\_cloud

**URL:** <https://forum.compas-framework.org/t/objects-in-compas-cloud/380>\
**Category:** compas\
**Created:** [August 28, 2020, 4:29pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380 "2020-08-28T16:29:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![arpastrana](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@arpastrana](https://forum.compas-framework.org/u/arpastrana)\
**Post date:** [August 28, 2020, 4:29pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/1 "2020-08-28T16:29:49Z")

</div>

Does `compas_cloud.Proxy` already support sending and receiving objects? If not, are there any plans to support this?

AFAIR, the good ol’ `compas_rpc.Proxy` deals only with python native datatypes which, for example, makes users have to use `force.data`, `form.data` instead of `FormDiagram`, `ForceDiagram` with `compas_tna` when in Rhino.

Thanks!

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [August 28, 2020, 5:24pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/2 "2020-08-28T17:24:49Z")

</div>

good old RPC now supports all COMPAS objects without the need for explicit conversion…

```python
import json
import compas
from compas.geometry import Point, Frame
from compas.datastructures import Mesh
from compas.utilities import DataEncoder, DataDecoder

point = Point(0, 0, 0)
frame = Frame.worldXY()
mesh = Mesh.from_obj(compas.get('faces.obj'))

data1 = [point, frame, mesh]

jsondata = json.dumps(data1, cls=DataEncoder)

data2 = json.loads(jsondata, cls=DataDecoder)

data1[0] == data2[0]
data1[1] == data2[1]
data1[2] == data2[2] # this comparison will not work because there is not comparison method implemented for meshes, but you get the point...

```

does that solve your problem or are you looking for something else?

---

<div class="post-metadata">

**Author:** ![arpastrana](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@arpastrana](https://forum.compas-framework.org/u/arpastrana)\
**Post date:** [August 28, 2020, 7:09pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/3 "2020-08-28T19:09:44Z")

</div>

Thanks. I tried translating a `Mesh` in Rhino passing it directly to a `Proxy`.  
What the it returns though is a dictionary, not a mesh. Is this how it should be?  
I tried `mesh.data = thing` to update the original mesh but it didn’t work.

```python
from compas.rpc import Proxy
from compas.geometry import Translation
from compas_rhino.geometry import RhinoMesh

mesh = RhinoMesh.from_guid(rhino_mesh).to_compas()
T = Translation.from_vector([2, 0, 0])

with Proxy("compas.datastructures") as dt:
    thing = dt.mesh_transformed_numpy(mesh, T)

assert type(thing) == Mesh, "thing type is {}".format(type(thing)) # it's a dict

```

However, I made this post originally thinking of doing numpy operations on custom-made objects, i.e. a child class of `Mesh`. Based on what you wrote before, I guess that this is not currently possible unless one defines a dedicated `DataEncoder` and `DataDecoder` for the json serialization. Would `compas_cloud` help here to not have to deal with the dedicated encoding/decoding?

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [August 28, 2020, 8:33pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/4 "2020-08-28T20:33:24Z")

</div>

i am not sure i understand. this doesn’t work for you?

```python
from math import radians
from compas.geometry import Rotation
from compas.datastructures import Mesh
from compas.rpc import Proxy
from compas_rhino.artists import MeshArtist

proxy = Proxy('compas.datastructures')

m1 = Mesh.from_polyhedron(6)
R = Rotation.from_axis_and_angle([0, 0, 1], radians(45))

m2 = proxy.mesh_transformed_numpy(m1, R)

print(type(m2)) # <class 'compas.datastructures.mesh._mesh.Mesh'>

artist = MeshArtist(None)

artist.mesh = m1
artist.layer = "Before"

artist.clear_layer()
artist.draw_vertices()
artist.draw_edges()

artist.mesh = m2
artist.layer = "After"

artist.clear_layer()
artist.draw_faces(join_faces=True)

```

i get this…

 ![Screenshot 2020-08-28 at 22.31.47](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/e755ac756551ae8ef341a33de4305918ee5f120e.jpeg)

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [August 28, 2020, 8:42pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/5 "2020-08-28T20:42:19Z")

</div>

the only functionality that is not supported yet by RPC without a wrapper are functions that update the input data(structures) instead of returning new data(structures)

---

<div class="post-metadata">

**Author:** ![arpastrana](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@arpastrana](https://forum.compas-framework.org/u/arpastrana)\
**Post date:** [August 28, 2020, 9:06pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/6 "2020-08-28T21:06:34Z")

</div>

My issue was that I was on `compas==0.16.1` (conda). I updated to `0.16.2` and now it works as shown.  
With RPC, could a quick fix to update a datastructure in-place with numpy be to return a copy of it (new object in memory)? Thanks.

---

<div class="post-metadata">

**Author:** ![arpastrana](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@arpastrana](https://forum.compas-framework.org/u/arpastrana)\
**Post date:** [August 28, 2020, 9:09pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/7 "2020-08-28T21:09:48Z")

</div>

Btw, would sending/receiving objects would work the same way on either proxy (`compas_rpc.Proxy` and `compas_cloud.Proxy`)?

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [August 29, 2020, 7:03am UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/8 "2020-08-29T07:03:30Z")

</div>

> [@arpastrana](#):
>
> Btw, would sending/receiving objects would work the same way on either proxy ( `compas_rpc.Proxy` and `compas_cloud.Proxy` )?

the latest changes in the serialisation mechanism have not made their way into cloud yet, but will soon.

> [@arpastrana](#):
>
> With RPC, could a quick fix to update a datastructure in-place with numpy be to return a copy of it (new object in memory)? Thanks.

well a quick fix would be to provide a wrapper and have the caller take care of the update

```python
# lib
def mesh_transform_numpy_proxy(meshdata, T):
    mesh = Mesh.from_data(meshdata)
    mesh_transform_numpy(mesh, T)
    return mesh.data

# caller
mesh.data = proxy.mesh_transform_numpy_proxy(mesh.data, T)

```

but ideally the proxy can detect this (or we mark the function with a decorator) such that this is handled implicitly and the wrapper is not necessary…

something like

```python
# lib
@rpc(True, False)
def mesh_transform_numpy(mesh, T):
    ...

# caller
proxy.mesh_transform_numpy(mesh, T)

```

---

<div class="post-metadata">

**Author:** ![arpastrana](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@arpastrana](https://forum.compas-framework.org/u/arpastrana)\
**Post date:** [August 29, 2020, 2:52pm UTC](https://forum.compas-framework.org/t/objects-in-compas-cloud/380/9 "2020-08-29T14:52:52Z")

</div>

This solves my issue. Thanks, @tomvanmele.  
Looking forward to more updates on rpc!
