Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/json export ipy #639

Merged
merged 3 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,7 @@ def test_09_non_linear_materials(self):
app.materials.export_materials_to_file(os.path.join(self.local_scratch.path, "non_linear.json"))
os.path.exists(os.path.join(self.local_scratch.path, "non_linear.json"))
app.materials.remove_material("myMat")
# Need to edit json file since the dumping doesn't work when embedded in unittest in IPY
with open(os.path.join(self.local_scratch.path, "non_linear.json"), 'r') as file:
filedata = file.read()
filedata = filedata.replace('True', 'true')
filedata = filedata.replace('False', 'false')
with open(os.path.join(self.local_scratch.path, "non_linear2.json"), 'w') as file:
file.write(filedata)
app.materials.import_materials_from_file(os.path.join(self.local_scratch.path, "non_linear2.json"))
app.materials.import_materials_from_file(os.path.join(self.local_scratch.path, "non_linear.json"))
assert app.materials["myMat"].permeability.value == [[0, 0], [1, 12], [10, 30]]
assert app.materials["myMat"].permittivity.value == [[0, 0], [2, 12], [10, 30]]
assert app.materials["myMat"].conductivity.value == [[0, 0], [3, 12], [10, 30]]
Expand Down
21 changes: 17 additions & 4 deletions pyaedt/modules/MaterialLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import json
import copy
import os

from pyaedt.generic.DataHandlers import _arg2dict
from pyaedt.generic.general_methods import aedt_exception_handler, _retry_ntimes, generate_unique_name
from pyaedt.generic.general_methods import aedt_exception_handler, _retry_ntimes, generate_unique_name, is_ironpython
from pyaedt.modules.Material import Material, SurfaceMaterial, MatProperties, OrderedDict


Expand Down Expand Up @@ -550,9 +552,20 @@ def find_datasets(d, out_list):
json_dict["materials"] = output_dict
if datasets:
json_dict["datasets"] = datasets

with open(full_json_path, "w") as fp:
json.dump(json_dict, fp, indent=4)
if not is_ironpython:
with open(full_json_path, "w") as fp:
json.dump(json_dict, fp, indent=4)
else:
temp_path = full_json_path.replace(".json", "_temp.json")
with open(temp_path, "w") as fp:
json.dump(json_dict, fp, indent=4)
with open(temp_path, 'r') as file:
filedata = file.read()
filedata = filedata.replace('True', 'true')
filedata = filedata.replace('False', 'false')
with open(full_json_path, 'w') as file:
file.write(filedata)
os.remove(temp_path)
return True

@aedt_exception_handler
Expand Down