Read Json file

Read Json file

Anonymous
Not applicable
17,488 Views
5 Replies
Message 1 of 6

Read Json file

Anonymous
Not applicable

Hey there,

 

I'm using 3ds Max 2017 and want to read a json file in my maxscript and be able to access items in the json.

 

Is this supported by max or will I have to download some third party library to achieve this?

 

Thanks.

Accepted solutions (1)
17,489 Views
5 Replies
Replies (5)
Message 2 of 6

RGhost77
Advisor
Advisor
0 Likes
Message 3 of 6

Swordslayer
Advisor
Advisor
Accepted solution

Since 2017 you can also use the python-maxscript interop, simply do  json = python.import #json   MAXScript side and you can call all its methods as if you were in python. Doesn't get much easier than that.

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hi, I need exactly the same thing - reading-writing json files from/to maxscript data (dictionary of strings, floats and arrays)

 

 

I could read/write using python only:

 

 

import json

fileIN = open ("D:\\TMP2\\original.json", "r")
pythonData = json.loads(fileIN.read())
fileIN.close()

fileOUT = open ("D:\\TMP2\\new.json", "w")
fileOUT.write(json.dumps(pythonData, indent=4))
fileOUT.close()

 

 

But this would result in a python dictionary; my question is how to have this as maxscript data.

 

I am trying to use

json = python.import #json 

 

but unfortunately I have no knowledge of python. 

It would be awesome if someone could help me get this working inside maxscript!

 

 

 

 

MANY THANKS!

 

 

 

 

 

 

PS this is the json file I am trying to read/write as maxscript dictionary / arrays

{
  "NumTextures": 2,
  "Positions": [
    [-0.19283, 0.00000, 26.94215],
    [0.19282, 0.00000, -26.94215]
  ],
  "Cameras": [
    [360, 180, [-0.19283, 0.00000, 26.94215], [-0.19283, 0.00000, 25.94215], [0.00000, 1.00000, 0.00000], "color0", "enabled"],
    [360, 180, [0.19282, 0.00000, -26.94215], [0.19282, 0.00000, -27.94215], [0.00000, 1.00000, 0.00000], "color1", "enabled"]
  ],
  "InitialPosition":  [-70.14005, 0.00000, 53.26647],
  "InitialRotation":  0,
  "NumNearCameras": 2,
  "NumWideCameras": 2,
  "BackColorFactorA": 20.0,
  "BackColorFactorB": 0.1,
  "BackRotation": 0
} 
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi, I tried to convert my .obj file to json to load it with three.js. I've done that with MaxScript and the result is the following:

 

{

"metadata":
{
"sourceFile": "",
"generatedBy": "3ds max ThreeJSExporter",
"formatVersion": 3,
"vertices": 0,
"normals": 0,
"colors": 0,
"uvs": 0,
"triangles": 0,
"materials": 0
},

"materials": [
],

"vertices": [],

"normals": [],

"colors": [],

"uvs": [[]],

"faces": []

}

It returns empty [], what can I do?

0 Likes
Message 6 of 6

daniel_fernandezZJSKU
Explorer
Explorer

Pretty late to the game, but I just found out how to use dictionaries with the python json library. You need to use Python data structures from the "builtins" library:

bi = Python.Import "builtins"

tp = bi.tuple(#(1,2,3)) --(1, 2, 3)
d = bi.dict one:1 two:2 three:3 -- {'one': 1, 'two': 2, 'three': 3}

3ds Max 2025 Developer Help | Executing Python from MAXScript | Autodesk

Maxscript arrays are no problem, you can use them even within a dictionary.

Hope this helps somebody 🙂