compas
compas copied to clipboard
Problem while loading with Mesh.from_json()
Describe the bug Mesh.from_json() does not work if the the file is saved using a different COMPAS version.
To Reproduce The following error shows up in Ipython:
Message: malformed string
Traceback:
line 79, in _convert, “C:\Program Files\Rhino 6\Plug-ins\IronPython\Lib\ast.py”
line 80, in literal_eval, “C:\Program Files\Rhino 6\Plug-ins\IronPython\Lib\ast.py”
line 302, in data, “C:\Users\msalma\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\compas\datastructures\mesh\core\halfedge.py”
line 376, in from_json, “C:\Users\msalma\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\compas\datastructures\mesh\core\halfedge.py”
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Python version [e.g. 2.7]
- Python package manager [e.g. macports, pip, conda]
@salmamzfr do you remember which version was it saved with? and which version are you reading it with now?
@gonzalocasas recent versions of the mesh data structure use exclusively int keys. therefore it is no longer necessary to use repr
and literal_eval
. the current version of the mesh uses str
and int
instead...
@gonzalocasas i get the same error saving the mesh from compas 0.16.1
and reading in compas 0.15.6
recent versions of the mesh data structure use exclusively int keys. therefore it is no longer necessary to use
repr
andliteral_eval
. the current version of the mesh usesstr
andint
instead...
which reminds me we should prioritize #520
@gonzalocasas do you remember which version was it saved with? and which version are you reading it with now? I think it was saving with 0.16.0 and reading with 0.15.6 or the other way around!
could you make the JSON available somewhere? i will try to add a fix for this, but i would like to make sure i am fixing the correct problem...
here is the mesh saved from compas 0.16.1
mesh_NT.zip
Thanks
@salmamzfr in recent versions this compatibility problem should be solved. can you check if this issue can be closed?
Hi Tom,
I am working with the latest compas version from compas source: '0.17.2-c422420c', when I save a mesh, mesh.to_json, in python, I cannot load the mesh, mesh.from_json, in Ironpython, it gives me the following error, which I believe is similar to the previous error:
Message: attributes
Traceback: line 174, in data, "C:\Users...\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\compas\datastructures\mesh\core\halfedge.py" line 275, in from_json, "C:\Users...\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\compas\datastructures\mesh\core\halfedge.py"
Also, I have been trying a similar process with network.to_json in python and loading it in Ironpython (network.from_json), I am able to load it, but it gives me the an empty network.
Here is the print of the network in Ironpython: { "adjacency": {}, "attributes": { "name": "Network" }, "edge": {}, "edge_attributes": {}, "max_int_key": null, "node": {}, "node_attributes": { "x": 0.0, "y": 0.0, "z": 0.0 } }
Here is the print of the same network in python: { "compas": "0.17.2", "data": { "adjacency": { "0": { "1": null, "5": null }, "1": { "0": null, "2": null }, "10": { "11": null, "13": null }, "11": { "10": null, "2": null }, "12": { "13": null, "16": null, "4": null, "8": null }, "13": { "10": null, "12": null, "17": null, "9": null }, "14": { "15": null, "17": null }, "15": { "14": null, "2": null }, "16": { "12": null, "17": null, "3": null, "4": null, "8": null }, "17": { "13": null, "14": null, "16": null, "5": null, "9": null }, "2": { "1": null, "11": null, "15": null, "4": null, "7": null }, "3": { "16": null, "4": null, "5": null, "8": null }, "4": { "12": null, "16": null, "2": null, "3": null, "8": null }, "5": { "0": null, "17": null, "3": null, "9": null }, "6": { "7": null, "9": null }, "7": { "2": null, "6": null }, "8": { "12": null, "16": null, "3": null, "4": null, "9": null }, "9": { "13": null, "17": null, "5": null, "6": null, "8": null } }, "attributes": { "name": "Network" }, "edge": { "0": { "1": {} }, "1": {}, "10": { "11": {} }, "11": {}, "12": { "4": {}, "8": {} }, "13": { "10": {}, "12": {}, "9": {} }, "14": { "15": {} }, "15": {}, "16": { "12": {}, "4": {}, "8": {} }, "17": { "13": {}, "14": {}, "16": {}, "9": {} }, "2": { "1": {}, "11": {}, "15": {}, "7": {} }, "3": { "16": {}, "4": {} }, "4": { "2": {} }, "5": { "0": {}, "17": {}, "3": {} }, "6": { "7": {} }, "7": {}, "8": { "3": {}, "4": {} }, "9": { "5": {}, "6": {}, "8": {} } }, "edge_attributes": {}, "max_int_key": 17, "node": { "0": { "x": -58.5177956144543, "y": 2.9626727851152808, "z": -17.73058341811962 }, "1": { "x": -58.5177956144543, "y": 2.9626727851152808, "z": 17.73058341811962 }, "10": { "x": -58.5177956144543, "y": 32.962672785115274, "z": -17.73058341811962 }, "11": { "x": -58.5177956144543, "y": 32.962672785115274, "z": 17.73058341811962 }, "12": { "x": -58.5177956144543, "y": 25.462672785115274, "z": -11.260332543417316 }, "13": { "x": -58.5177956144543, "y": 25.462672785115274, "z": -17.73058341811962 }, "14": { "x": -43.5177956144543, "y": 17.962672785115274, "z": -17.73058341811962 }, "15": { "x": -43.5177956144543, "y": 17.962672785115274, "z": 17.73058341811962 }, "16": { "x": -51.0177956144543, "y": 17.962672785115274, "z": -11.260332543417316 }, "17": { "x": -51.0177956144543, "y": 17.962672785115274, "z": -17.73058341811962 }, "2": { "x": -58.5177956144543, "y": 17.962672785115274, "z": 17.73058341811962 }, "3": { "x": -58.5177956144543, "y": 10.462672785115274, "z": -11.260332543417316 }, "4": { "x": -58.5177956144543, "y": 17.962672785115274, "z": 6.470250874702305 }, "5": { "x": -58.5177956144543, "y": 10.462672785115274, "z": -17.73058341811962 }, "6": { "x": -73.5177956144543, "y": 17.962672785115274, "z": -17.73058341811962 }, "7": { "x": -73.5177956144543, "y": 17.962672785115274, "z": 17.73058341811962 }, "8": { "x": -66.0177956144543, "y": 17.962672785115274, "z": -11.260332543417316 }, "9": { "x": -66.0177956144543, "y": 17.962672785115274, "z": -17.73058341811962 } }, "node_attributes": { "x": 0.0, "y": 0.0, "z": 0.0 } }, "datatype": "compas.datastructures/Network" }
Also, tried network.to_data in python and loaded the data dictionary in Ironpython, which the correct dictionary, when it is loaded in Ironpython. Still get an empty network, while trying network.from_data
not sure if this is the source of the problem, but on the CPython side you seem to be loading a Mesh
and on the IronPython side a Network
. could you check if this is correct? it would make sense that this results in the errors you describe...
In case of the mesh datastructure: I making the mesh in Python using Mesh.from_vertices_and_faces, save it with Mesh.to_json and load it in Ironpython with Mesh.from_json and get the mentioned error.
In case of the network datastructure: I making the network in Python using Network.from_nodes_and_edges, save it with Network.to_json and load it in Ironpython with Network.from_json and get an empty network.
not sure if this is the source of the problem, but on the CPython side you seem to be loading a
Mesh
and on the IronPython side aNetwork
. could you check if this is correct? it would make sense that this results in the errors you describe...
Sorry! I pasted the wrong print, just corrected it!
could you send me the json file(s) that you have been using?
import os
from compas.datastructures import Network
from compas_rhino.artists import NetworkArtist
HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, 'Datastructures', 'pr_net')
net = Network.from_json(FILE)
artist = NetworkArtist(net)
artist.draw()
import os
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist
HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, 'Datastructures', 'pr_mesh')
mesh = Mesh.from_json(FILE)
artist = MeshArtist(mesh)
artist.draw()
@salmamzfr i can't really reproduce the problem. as you can see from the snippets and corresponding screenshots, for me these files just work...
Are you using the latest compas version in Rhino? I am saving to json with 0.17.2-c422420c and drawing with 0.16.1.
If I save to json and load json in version 0.16.1 it works fine and I can plot both.
@salmamzfr i can't really reproduce the problem
@tomvanmele irreproducible issues, is noise to an issue tracker, pls close