import Mesh
import MeshPart
import Import
data=Import.open("C:/ACE TANK.STEP")
shape = data[0][0].Shape
shape_colors = data[0][1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
# len(shape_colors) must be equal to mesh.countSegments()
#
face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_colors[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j] = color
mesh.write(Filename="C:/test.obj", Material=face_colors, Format="obj")
wmayer wrote: ↑Fri Jul 05, 2019 9:21 am
For total GUI-less solution try this:
import Mesh
import MeshPart
import Import
data=Import.open("C:/ACE TANK.STEP")
shape = data[0][0].Shape
shape_colors = data[0][1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
# len(shape_colors) must be equal to mesh.countSegments()
#
face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_colors[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j] = color
mesh.write(Filename="C:/test.obj", Material=face_colors, Format="obj")
wmayer wrote: ↑Fri Jul 05, 2019 9:21 am
For total GUI-less solution try this:
import Mesh
import MeshPart
import Import
data=Import.open("C:/ACE TANK.STEP")
shape = data[0][0].Shape
shape_colors = data[0][1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
# len(shape_colors) must be equal to mesh.countSegments()
#
face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_colors[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j] = color
mesh.write(Filename="C:/test.obj", Material=face_colors, Format="obj")
Hello Wmayer,
I am using the code mentioned as it is mentioned for converting the STEP to OBJ file but its always result in error with mentioned packages like Mesh, MeshPart, Import.
I have recently started looking in this area of file types and related conversions. I am using Python-3.6.5 and list of needed packages as below.
import Mesh
ModuleNotFoundError: No module named 'Mesh'
Depending on your OS your FreeCAD installation should have a file Mesh.pyd (Windows) or Mesh.so (Linux or macOS). Can you find the file?
Hello wmayer, Thanks for the inputs i was able to resolve this issue. However the using FreeCAD to convert a step file to an .obj file still has a issue as i do not get the complete attributes out from a step file. Here i just get the .obj file having only ‘v’ & ‘f’ , whereas vt and vn are missing. Below is two sample code. Request your input.
data = Import.open("C:/Sample.stp")
shape = Part[0][0].Shape()
shape_colors = data[0][1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
face_colors=[(0,0,0)]*mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_color[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j]=color
mesh.write(Filename="C:/sample.obj", Material=face_color,Format="obj")
I used your script and it works like a charm.
But in my case i have a step file with multiple shapes and would need to export them into a single .obj file.
Which changes would be neccessary to make that possible?
wmayer wrote: ↑Fri Jul 05, 2019 9:21 am
For total GUI-less solution try this:
import Mesh
import MeshPart
import Import
data=Import.open("C:/ACE TANK.STEP")
shape = data[0][0].Shape
shape_colors = data[0][1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
# len(shape_colors) must be equal to mesh.countSegments()
#
face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_colors[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j] = color
mesh.write(Filename="C:/test.obj", Material=face_colors, Format="obj")
import Mesh
import MeshPart
import Import
data=Import.open("C:/ACE TANK.STEP")
compound = Mesh.Mesh()
compound_colors = []
for d in data:
shape = d[0].Shape
shape_colors = d[1]
mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)
num_facets = compound.CountFacets
compound.addMesh(mesh)
# len(shape_colors) must be equal to mesh.countSegments()
#
face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
color = shape_colors[i]
segm = mesh.getSegment(i)
for j in segm:
face_colors[j] = color
segm = [k + num_facets for k in segm]
compound.addSegment(segm)
compound_colors.extend(face_colors)
compound.write(Filename="C:/test.obj", Material=compound_colors, Format="obj")