# Howto convert Step(*.stp) to AutoCAD(*.fbx) with python Script (and also decimate the face ratio)

Hello to every one who is reading this,

I know how to convert and decimate files in Blender. Now I would like to safe me some time and get a litle in to the scripting.

So I checked here for some Questions/Answers, @wiki.blender.ord for documentations and scripts. Like here https://docs.blender.org/api/blender_python_api_2_76_1/bpy.ops.import_mesh.html

Also ich have copyed and changed this little Script:

import bpy
import sys

argv = sys.argv
argv = argv[argv.index("--")+1:]

stl_in = argv[0]
fbx_out = argv[1]

bpy.ops.import_mesh.stl(filepath=stl_in)
bpy.ops.export_scene.obj(filepath=fbx_out)


As there is no import's for *.stp the exported fbx file by this script is garbage, if I convert a stl file with this.

Question 1: Is there a way to import *.stp File in to blender, with out converting the *.stp file in to *.stl or other by Blender acceptable type with external tools?

For the part of decimate of faces i found this script: https://gist.github.com/wooddar/0a5f409dc67cc045c421

I have tryed following:

bpy.ops.import_mesh.stl(filepath=stl_in)
bpy.ops.object.modifier_add(type='DECIMATE')

bpy.context.object.modifiers["Decimate"].ratio = number_of_faces_in_stl_obj/max_faces


Here I have two problems, the first it didn't worked at all. The second on is how can i get the number_of_faces_in_stl_obj so I can calculate the ratio.

Question 2: After I've imported an object with 'bpy.ops.import_mesh.stl(filepath=stl_in)' do I get with 'bpy.context.object' to some thing like number_of_surfaces/polygons?

In andvence thank you for you help.

EDIT: Added my Questions

• i think there's a typo in here: you request to convert step data to fbx, but in fact in your script you're converting stl data to fbx. Step data mainly contains NURBs surface patches, stl contains polygons. Please edit the question to clarify what you're after. – aliasguru Mar 23 '17 at 11:32
• i want to convert stp files in to fbx. The only option i've found on the net is to use freecad and convert with it the *.stp file in to *.stl file. – akr Mar 23 '17 at 13:58

## 1 Answer

Is there a way to import *.stp File in to blender, with out converting the *.stp file in to *.stl or other by Blender acceptable type with external tools?

Unfortunately no. The current import tools available in Blender do not allow (to my knowledge) to read and / or interpret NURBS input data. Some way or another, this always has to be processed by an external application first, and then be brought into Blender in a second step.

There are a few tools out there which can assist in this, you already mentioned FreeCAD which does a good job on less complicated input files. Many times however you're stuck with proprietary commercial software. A solution that works well is Autodesk Showcase. It reads many industry standard formats, allows for dynamic tessellation of parts / files, gives you a nice visual representation, and exports well to .fbx, which is the preferred format (for me) to bring stuff into Blender. Main advantage: With this pipeline, custom split normals are generated and imported correctly.

After I've imported an object with 'bpy.ops.import_mesh.stl(filepath=stl_in)' do I get with 'bpy.context.object' to some thing like number_of_surfaces/polygons?

Of course. You can use len(bpy.context.object.data.polygons) to get the polycount of the active object. len(bpy.context.object.data.vertices) and len(bpy.context.object.data.edges) are the vertex and edge counterparts. In essence, bpy.context.object.data.polygons and the like are Python lists, where you can access each individual face / edge / vertex.