Convert solid linear work to json

good morning
I am making a dynamo in which I want to convert the solids exported from the linear work (dwg), convert them to json. I have created all the necessary nodes and I have created the python script with an AI. (because I don’t know PYTHON), but it doesn’t work for me. Does anyone know how to do this because it doesn’t give me any results?
script python

import json
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Supongamos que el input es un sólido de Dynamo

Puede ser un Solid, Surface, PolySurface, etc.

inputSolid = IN[0]

Función para obtener las propiedades del sólido

def get_solid_properties(solid):
properties = {}

# Obtener el tipo de objeto
properties['type'] = type(solid).__name__

# Obtener el volumen si es un sólido
if hasattr(solid, 'Volume'):
    properties['volume'] = solid.Volume

# Obtener el área si es un sólido o superficie
if hasattr(solid, 'Area'):
    properties['area'] = solid.Area

# Obtener la cantidad de caras si es un sólido
if hasattr(solid, 'Faces'):
    properties['num_faces'] = len(solid.Faces)

# Obtener el bounding box
if hasattr(solid, 'BoundingBox'):
    bbox = solid.BoundingBox
    properties['bounding_box'] = {
        'min_point': {'x': bbox.MinPoint.X, 'y': bbox.MinPoint.Y, 'z': bbox.MinPoint.Z},
        'max_point': {'x': bbox.MaxPoint.X, 'y': bbox.MaxPoint.Y, 'z': bbox.MaxPoint.Z}
    }

return properties

Obtener las propiedades del sólido

solid_properties = get_solid_properties(inputSolid)

Convertir a JSON

solid_json = json.dumps(solid_properties, indent=4)

Salida del JSON como string

OUT = solid_json

There is already a node to get a json definition of geometry - Geometry.ToSolidDef

Data.StringifyJSON works better in current builds - more info in a great blog post from @achintya_bhat here: Lost in Translation? Unmasking Data.StringifyJSON and Data.Remember Nodes in Dynamo - Dynamo BIM

2 Likes

Good morning, I have tried it and thank you very much.
What I get is the json with the text type format that is illegible, you can pass the python script that transforms it into a tree

Here you go…

import json
OUT = json.dumps(json.loads(IN[0]), indent=4)

Good morning
I have generated the json as explained to me but I have two questions.

  1. Would I need to convert the UTM coordinates that I get in the json to decimal geodraphic coordinates with an SCR wsg 84?
  2. How do I put the json in tree format inside dynamo to make it more attractive?

    Nuevo documento de texto.txt (57.1 KB)

Maybe, but also maybe not. Will depend on the project.

You don’t need to - exploring the JSON of geometry is of no real use when just using ToSolidDef.

If you are in a current build and use Data.StringifyJSON when you deserialize it back into Dynamo it should be fairly explorable already.