Export 3mf File with Attributes

Hello

I am playing with 3mf filetype export. My goal is to export a mesh with custom attributes attached(not a separate .csv file). There is a nice export dialog window in Rhino, but I was not able to get any information back when re-importing previously exported 3mf object. There are only few information about 3mf file on the forum, so I would like to ask someone for help.

  • Is it possible to use 3mf export fields for some custom additional information (e.g. string with parameters from GH)?
  • Is it possible to re-import 3mf file into Rhino with all additional information attached?

Thank you

image

2 Likes

Nobody? :pray: :sob: :face_holding_back_tears:

I exported a model some time ago and if I had to do this more often than once I would have wished for an option to set the priority of each part in Rhino.

My wish is the possibility to attach a description with some info about who exported the model, which settings were used in grasshopper etc. This is crucial for further procedures down the production line. 3mf should be capable of that.

1 Like

We just implemented a build 8.6 that this might work. The code looks like this:

#! python3

import math
import rhinoscriptsyntax as rs
import System
import System.Collections.Generic
import Rhino
import scriptcontext
import Rhino
import os
 
if scriptcontext.doc is not None:
    options = Rhino.FileIO.File3mfWriteOptions()
    options.Metadata["Title"] = "2578R"
    options.Metadata["Designer"] = "MyDesign"
    options.Metadata["Test"] = "Star"
    options.MoveOutputToPositiveXYZOctant = True;
    options_dictionary = options.ToDictionary()
 
 #Get the filename to create
    filter = "3MF File (*.c3mf)|*.3mf||"
    filename = rs.SaveFileName("Save 3MF as", filter)

    if filename is not None:
        success = scriptcontext.doc.Export(filename, options_dictionary)
    if success:
        print("Successfully exported sample.3mf")
    else:
        print("Error while trying to export sample.3mf")

The Metadata can contain any key and string value

2 Likes

OK, another update today.

The metadata in the header of the 3MF file is read into the Document Userdata Table. In Rhino it looks like this:

image

then it auto populates export:

image

And in a headless doc it looks like this:

for docdata in range(doc.Strings.Count):
    print(doc.Strings.GetKey(docdata) + " is " + doc.Strings.GetValue(docdata))

Results are:

Title is 2578R
Designer is MyDesign

But I need to send another build as this change is a bit larger and we want to make sure it does not mess things up.

3 Likes

I updated this code above to the most recent 8.6 updates including 3MF metadata both on read and write.

1 Like