# 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.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.

• 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. 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

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.