.stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Post here for help on using FreeCAD's graphical user interface (GUI).
Syres
Posts: 137
Joined: Thu Aug 09, 2018 11:14 am

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby Syres » Tue Feb 05, 2019 11:42 am

@James2406, the first thing you will need to ensure this process works is version 0.18 using Python 2.7 so please download FreeCAD_0.18.15nnn_x64_dev_win.7z from https://github.com/FreeCAD/FreeCAD/releases and unpack it. You can run both versions side by side so you don't have to de-install 0.17.

Run FreeCAD 0.18 and import the Step file.



If the single mesh is your requirement then @NormandC's option of Collada export is probably best but you need to check what the Tessellation size is in Edit > Preferences > Import-Export > DAE tab, I used 0.1 for a result of 4.7 million faces, I believe the default is 1.0.



If individual shapes to meshes is your requirement then I've taken a different approach and used 3 macros (2 for FreeCAD and one for Blender).

First thing you need to do is save the FreeCAD file with an apprapriate name as this is used in the stl filenames later and there will be an export subfolder created by the macro so it needs a place marker to start from.

Copy the attached LabelShapesAsstl.FCMacro and exportProject.FCMacro (thanks to @jonnor) to your Macro directory.

Ensure View > Panels > Report View is ticked and click the Report View tab at the bottom of the screen so you can see the results of the macros.

Execute the LabelShapesAsstl macro and you should see a large list of part numbers with the last one being 5265035001, that shows that only shapes have had a suffix of [stl] added.

Now execute the exportProject macro which will select the shapes and export them as stl files to the export folder using a name FreeCADfilename-shapename.stl, don't worry if the message box is unreadable when it completes, just close it.

Create a Blend file in the export folder containing all the STLs and in the Text Editor copy the following Python script (I used 2.79b with Metric Units set for this). Note don't use an existing file as the script clears the scene to start with.

Code: Select all

import bpy
import glob
import os


def process(stl_fname):
    print('Processing %r' % stl_fname)

    bpy.ops.import_mesh.stl(filepath=stl_fname)
# bpy.ops.object.modifier_add(type='SOLIDIFY')
# bpy.context.object.modifiers["Solidify"].thickness = 0.03
# print('Writing to %r' % out_fname)
# bpy.ops.export_mesh.stl(filepath=out_fname)
# bpy.ops.object.delete()

# Start with nothing in the scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# Process *.stl
here = bpy.path.abspath('//')
for stl_fname in glob.glob(os.path.join(here, '*.stl')):
    if '-imported.stl' in stl_fname:
        print('Skipping %r' % stl_fname)
        continue

    process(stl_fname)


C = bpy.context
scene = C.scene

C.tool_settings.mesh_select_mode = (True, False, False)

for ob in C.selected_objects:
    if ob.type == 'MESH':
        scene.objects.active = ob #set active object
        bpy.ops.object.mode_set(mode='EDIT') #switch to edit mode
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.remove_doubles() #remove doubles
        bpy.ops.mesh.tris_convert_to_quads() #tris to quads
        bpy.ops.mesh.customdata_custom_splitnormals_clear() #remove custom normals
        bpy.ops.object.mode_set(mode='OBJECT') #switch to object mode
Run the script which will not only bring each STL file in but clean the meshes also. This resulted in 5.2 million faces in my tests.

None of the steps took longer than 5 minutes on my old i5, 24 Gb RAM and NVidia GTX 670 so your hardware should be quicker.
Attachments
exportProject.FCMacro
(3.04 KiB) Not downloaded yet
LabelShapesAsstl.FCMacro
(679 Bytes) Not downloaded yet
User avatar
NormandC
Posts: 18134
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby NormandC » Tue Feb 05, 2019 12:26 pm

Syres wrote:
Tue Feb 05, 2019 11:42 am
If the single mesh is your requirement then @NormandC's option of Collada export is probably best
COLLADA does not export a single mesh. It exports a single file containing separate meshes that can be moved individually in Blender.
Syres
Posts: 137
Joined: Thu Aug 09, 2018 11:14 am

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby Syres » Tue Feb 05, 2019 12:40 pm

NormandC wrote:
Tue Feb 05, 2019 12:26 pm
Syres wrote:
Tue Feb 05, 2019 11:42 am
If the single mesh is your requirement then @NormandC's option of Collada export is probably best
COLLADA does not export a single mesh. It exports a single file containing separate meshes that can be moved individually in Blender.
Humble apologies, the Collada export is a single DAE file with each individual mesh contained as a node which can be joined together if so required in Blender.
User avatar
NormandC
Posts: 18134
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby NormandC » Wed Feb 06, 2019 4:34 am

Sorry for asking, but what is the purpose of your macro, apart from cleaning the meshes (which I'm not sure what it means), as opposed to the simple file export? Keep in mind that I can barely use Blender, I just import stuff, rotate the view and move parts, that's about it!

Thanks.
Syres
Posts: 137
Joined: Thu Aug 09, 2018 11:14 am

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby Syres » Wed Feb 06, 2019 9:19 am

The cleaning of the meshes is highly recommended to reduce the number of faces by as much as 40%, having a significant impact on performance. The other reason for the macros is I like to have the ability to remove STL files before import, in this case all the conrods, bearing shells, valves etc that are internal and therefore I'm guessing for a game aren't required, which again reduces impact on performance. It's OK to bring the whole engine into Blender and then remove items at that stage but this gives an alternative strategy. There's no right or wrong way but I'm giving not only the OP but others who stumble across the thread in the future who have older hardware something to try.
User avatar
NormandC
Posts: 18134
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: .stp imports to FeeCad fine. Exporting to .stl or .obj gives issues upon import to Blender.

Postby NormandC » Sat Feb 16, 2019 5:38 pm

Thanks for the explanation, I appreciate it.