3

This is my first time posting here. I am making 3D models of houses using python and I would like to visualise the output using FreeCAD. I found the ezdxf interface (https://pypi.org/project/ezdxf/) which writes to dxf format and I ran the below code (this is one of the examples provided there)

import ezdxf

# 8 corner vertices
cube_vertices = [
    (0, 0, 0),
    (1, 0, 0),
    (1, 1, 0),
    (0, 1, 0),
    (0, 0, 1),
    (1, 0, 1),
    (1, 1, 1),
    (0, 1, 1),
]

# 6 cube faces
cube_faces = [
    [0, 1, 2, 3],
    [4, 5, 6, 7],
    [0, 1, 5, 4],
    [1, 2, 6, 5],
    [3, 2, 6, 7],
    [0, 3, 7, 4]
]

doc = ezdxf.new('R2000')  # MESH requires DXF R2000 or later
msp = doc.modelspace()
mesh = msp.add_mesh()
mesh.dxf.subdivision_levels = 0  # do not subdivide cube, 0 is the default value
with mesh.edit_data() as mesh_data:
    mesh_data.vertices = cube_vertices
    mesh_data.faces = cube_faces

doc.saveas("cube_mesh.dxf")

However, when I open the output in FreeCAD nothing is displayed. Freecad doesn't display mesh Perhaps I am making a simple error. FreeCAD is totally new to me so maybe I have to enable something in FreeCAD before I can see the mesh. I could draw each of the edges by drawing lines between vertices but I would prefer to input vertices and faces and draw the mesh that way. Can anyone tell me what I am doing wrong or another way to do what I am trying to do, export meshes from python and open them in FreeCad. Thanks for you help

lukecoburn
  • 31
  • 3

3 Answers3

0

I have no experience using FreeCAD, however, in order to determine whether the source of the issue is the file itself or merely an incompatibility with FreeCAD displaying mesh objects, you could try opening the resulting file using Autodesk's TrueView application, which is also free and will allow you to view (though not edit) 2D or 3D DWG, DWF or DXF files.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • Thank you for your answer. I should have mentioned in my post that I am using a Mac (High Sierra 10.13.6) and TrueView is a windows application. However, I could use [Autocad's Online viewer](https://viewer.autodesk.com/) and nothing appears there so it seems that the problem is with the file itself. – lukecoburn Jan 13 '20 at 20:27
0

The created file can be viewed in TrueView, BricsCAD and Autodesk Online Viewer, BUT you have to zoom to the drawing extends: enter image description here

I haven't installed FreeCAD.

mozman
  • 2,001
  • 8
  • 23
0

Looks like the libraries FreeCAD uses to import DXF don't have a compatible license so they must be activated in FreeCAD manually.

Here's a comprehensive document on how to go about importing DXF files: https://wiki.freecadweb.org/DXF

Daniel
  • 8,655
  • 5
  • 60
  • 87