Save As 3mf macro

Programming and macros
User avatar
SPerman
Posts: 2055
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2226
x 1876
Contact:

Save As 3mf macro

Unread post by SPerman »

I have a macro that I wrote several years ago that saves the model as a .3mf file. It worked fine until I upgraded to windows 11. Now, if I try and open the .3mf file, the slicing software (multiple) says the file does not contain any geometry. I went to my macro and changed the extension from .3mf to .stl and it works fine. Does anyone have any idea what might have changed, or how to fix it? (2022 SP5)

Code: Select all

' Save As
longstatus = Part.SaveAs3(sModelFullName, 0, 2)
SHAddToRecentDocs 2, sModelFullName


End Sub
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: Save As 3mf macro

Unread post by AlexLachance »

SPerman wrote: Thu Jun 01, 2023 3:21 pm I have a macro that I wrote several years ago that saves the model as a .3mf file. It worked fine until I upgraded to windows 11. Now, if I try and open the .3mf file, the slicing software (multiple) says the file does not contain any geometry. I went to my macro and changed the extension from .3mf to .stl and it works fine. Does anyone have any idea what might have changed, or how to fix it? (2022 SP5)

Code: Select all

' Save As
longstatus = Part.SaveAs3(sModelFullName, 0, 2)
SHAddToRecentDocs 2, sModelFullName


End Sub
Sounds like Windows 11 reads the data differently then Windows 10. Maybe you're missing an extension?
mario malic
Posts: 9
Joined: Thu Apr 13, 2023 4:19 am
Answers: 1
Location: Croatia
x 8
x 2

Re: Save As 3mf macro

Unread post by mario malic »

I would suggest to record a macro yourself in which you will save as .3mf format and see if there are any differences between recorded one and yours.
Looking for opportunities related to SolidWorks API usage.
User avatar
Stefan Sterk
Posts: 37
Joined: Tue Aug 10, 2021 2:40 am
Answers: 3
x 51
x 77

Re: Save As 3mf macro

Unread post by Stefan Sterk »

Does using the SaveAs3 method from IModelDocExtension give a different result?
User avatar
JSculley
Posts: 643
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 877

Re: Save As 3mf macro

Unread post by JSculley »

SPerman wrote: Thu Jun 01, 2023 3:21 pm I have a macro that I wrote several years ago that saves the model as a .3mf file. It worked fine until I upgraded to windows 11. Now, if I try and open the .3mf file, the slicing software (multiple) says the file does not contain any geometry. I went to my macro and changed the extension from .3mf to .stl and it works fine. Does anyone have any idea what might have changed, or how to fix it? (2022 SP5)

Code: Select all

' Save As
longstatus = Part.SaveAs3(sModelFullName, 0, 2)
SHAddToRecentDocs 2, sModelFullName


End Sub
Can you upload a sample 3mf file that fails to open?
User avatar
SPerman
Posts: 2055
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2226
x 1876
Contact:

Re: Save As 3mf macro

Unread post by SPerman »

Fails to load:
Bambulab
simplify3d
Windows built in 3dviewer

Successfully loads:
Raise3d Ideamaker
Solidworks

I moved back to the STL format for a couple of reasons. Bambulab saves its files in the 3mf format. So now the 3mf no longer represents the geometry, but the entire build plate. Saving as an STL means I can always go back to the geometry of the part.
Attachments
3mf.zip
(1.64 MiB) Downloaded 83 times
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
JSculley
Posts: 643
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 877

Re: Save As 3mf macro

Unread post by JSculley »

When I try to open this file in Windows10, the BambuStudio error log has this to say:

Code: Select all

2023-06-20 12:06:30.679563[Thread 0x00005778]:Slic3r::_BBS_3MF_Importer::_load_model_from_file:1505extract 4th file Metadata/model_settings.config, total=14
2023-06-20 12:06:30.679563[Thread 0x00005778]:can not find object for assemble item, id= 2
2023-06-20 12:06:30.679563[Thread 0x00005778]:Error (parsing aborted) while parsing xml file at line 31
2023-06-20 12:06:30.679563[Thread 0x00005778]:Archive does not contain a valid model config
The 3MF file format is juts a zip file with various folders/files inside. The model_settings.config file looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <object id="2">
    <metadata key="name" value="CTW-6C-015-000"/>
    <metadata key="extruder" value="1"/>
    <part id="1" subtype="normal_part">
      <metadata key="name" value="CTW-6C-015-000"/>
      <metadata key="matrix" value="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"/>
      <metadata key="source_file" value="CTW-6C-015-000.3mf"/>
      <metadata key="source_object_id" value="0"/>
      <metadata key="source_volume_id" value="0"/>
      <metadata key="source_offset_x" value="0"/>
      <metadata key="source_offset_y" value="-18.033938050270081"/>
      <metadata key="source_offset_z" value="1.9049999713897701"/>
      <mesh_stat edges_fixed="0" degenerate_facets="0" facets_removed="0" facets_reversed="0" backwards_edges="0"/>
    </part>
  </object>
  <plate>
    <metadata key="plater_id" value="1"/>
    <metadata key="locked" value="false"/>
    <metadata key="thumbnail_file" value="Metadata/plate_1.png"/>
    <metadata key="top_file" value="Metadata/top_1.png"/>
    <metadata key="pick_file" value="Metadata/pick_1.png"/>
    <model_instance>
      <metadata key="object_id" value="2"/>
      <metadata key="instance_id" value="0"/>
      <metadata key="identify_id" value="331"/>
    </model_instance>
  </plate>
  <assemble>
   <assemble_item object_id="2" instance_id="0" transform="1 0 0 0 1 0 0 0 1 1 -17.033938050270081 1.9049999713897705" offset="0 0 0" />
  </assemble>
</config>
Line 31 is the assemble_item tag.

The interesting thing is that when I save a part or assembly file to 3MF format using SOLIDWORKS (2022 SP5) directly or via the API, there is no modle_settings.config file generated in the 3MF archive. What is the story of the file you are exporting? Is it a part, assembly, component in an assembly? Was it created in SW or imported from something else? What 3D printer do you have selected in SW?
User avatar
SPerman
Posts: 2055
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2226
x 1876
Contact:

Re: Save As 3mf macro

Unread post by SPerman »

It is a part created in solidworks, exported from the file ( not an assembly.)

This is what is exported out of solidworks.
image.png
image.png (52.7 KiB) Viewed 1720 times
This is what appears in Ideamaker (the only software other than solidworks which will open the file.)
image.png
image.png (22.27 KiB) Viewed 1720 times
I just duplicated the entire process to make sure I didn't do something along the way to cause the problem.

The attached folder contains 2 files. One opens, the other doesn't. I've also included the 2 solidworks files in case you want to check them out.
Attachments
3mf2.zip
(2.69 MiB) Downloaded 96 times
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
JSculley
Posts: 643
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 877

Re: Save As 3mf macro

Unread post by JSculley »

SPerman wrote: Tue Jun 20, 2023 2:13 pm It is a part created in solidworks, exported from the file ( not an assembly.)

This is what is exported out of solidworks.

image.png

This is what appears in Ideamaker (the only software other than solidworks which will open the file.)

image.png

I just duplicated the entire process to make sure I didn't do something along the way to cause the problem.

The attached folder contains 2 files. One opens, the other doesn't. I've also included the 2 solidworks files in case you want to check them out.
Looking at the the files in your 3mf2.zip, the two 3MF files are very different. Specifically the Metadata folder. Here they are side by side:
image.png
The file on the left is typical of a 3MF file exported from SW. Just a thumbnail in the Metadata folder. The file on the right has a lot more information, including G-code, printer specific info, etc. It looks like it has been saved from Bambu studio. If I delete everything inside the Metadata folder, Bambu will load the 3MF file with no problem.
image.png
The fact that Ideamaker shows two instances of the part is another strange thing.

Now, my original thought was that Windows 11 had somehow messed up the file encoding. This is still a possibility. My tests are on a Windows 10 machine, so when I alter the 3MF file, it might be saving it with the correct encoding again. As a test, I edited a file in each 3MF file by adding a couple of new line characters in the [Content_Types].xml file. Then I saved them and attached them below. If you can open them with no problems then this may be an encoding issue. Try it and report back.
Attachments
3mf3.zip
(2.46 MiB) Downloaded 120 times
Post Reply