Export customization

By inheriting from DessiaObject or PhysicalObject, the created class includes exports.

Exports included with DessiaObject

  • json: save_to_stream
  • xlsx: to_xlsx_stream

Exports included with PhysicalObject

  • json: save_to_stream
  • xlsx: to_xlsx_stream
  • step: to_step_stream
  • stl: to_stl_stream
  • html: to_html_stream

These exports can be customized by overwriting the corresponding method.

Methods ending in "_stream" are used by the platform, while others are used for local testing.

class Bearing(PhysicalObject):
    _standalone_in_db = True
 
    def __init__(self, ball: Ball,
                 internal_diameter: float,
                 external_diameter: float,
                 height: float,
                 name: str = ""):
        self.ball = ball
        self.internal_diameter = internal_diameter
        self.external_diameter = external_diameter
        self.height = height
        PhysicalObject.__init__(self, name=name)
 
		def to_txt(self, file_path: str):
        if not file_path.endswith('.md'):
            file_path += '.md'
        with open(file_path, 'w', encoding='utf-8') as file:
            self.to_txt_stream(file)
 
    def to_txt_stream(self, stream: dcf.StringFile):
        stream.write(self.to_markdown())
 
		def to_html(self, file_path: str):
        if not file_path.endswith('.html'):
            file_path += '.html'
        with open(file_path, 'w', encoding='utf-8') as file:
            self.to_html_stream(file)
 
    def to_html_stream(self, stream: dcf.StringFile):
        model = self.volmdlr_volume_model()
        babylon_data = model.babylon_data()
        script = model.babylonjs_script(babylon_data)
        stream.write(script)
 

We are working on new export formats using decorators. This will be available shortly.