SGread3MF

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Import/Export
Introduced first in SolidGeometry 5.0, Creation date: 2021-01-31, Last change: 2025-09-15

opens and reads a 3mf file with respect to the microsoft specification

Description

the 3mf file is a zip file that contains a directory 3D in which an XML file named '3dmodel.model' is located. This file is read and interpreted in a simple way.


See Also: ms3Dmodel2SG , SGreadSTL

Example Illustration

 missing image of SGread3MF(fname)

Syntax

text=SGread3MF(fname)

Input Parameter

fname: filename

Output Parameter

text: XML text




Copyright 2021-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, SGread3MF, is designed to read a 3MF file, which is a zip file containing a directory named "3D" with an XML file called "3dmodel.model". The function extracts and interprets this XML file.

Input Parameters

Output Results

Algorithm Steps

  1. Retrieve the filename using getfuncparams with a default value of an empty string.
  2. Use tryuigetfile to prompt the user to select a file if fname is not provided.
  3. Ensure the filename ends with ".3mf". If not, append ".3mf" to the filename.
  4. Check if the file exists. If not, attempt to locate it in the desktop directory using desktopdir.
  5. If the file still cannot be found, raise an error indicating "file not found".
  6. Create a temporary directory named "SGread3MF_tmp" using mkdir and change the current directory to this temporary directory.
  7. Unzip the 3MF file into the temporary directory.
  8. Construct the path to the "3dmodel.model" file within the unzipped contents.
  9. Read the XML text from "3dmodel.model" using readtextfile.
  10. Return to the original directory and remove the temporary directory using rmdir.
  11. Convert the XML text to a Solid Geometry class object using ms3Dmodel2SG.
  12. If the output is a single cell, extract the content from the cell.
  13. If no output arguments are specified, plot the geometry using SGfigure and SGplotcell.
Algorithm explaination created using ChatGPT on 2025-08-19 06:47. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21