Creating faces from a DXF file

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Creating faces from a DXF file

Post by shoogen »

usually you should be able to call OpenSCAD2Dgeom.edgestofaces(edges) without the algo parameter.
mario52
Veteran
Posts: 4674
Joined: Wed May 16, 2012 2:13 pm

Re: Creating faces from a DXF file

Post by mario52 »

hi
I do not know how to operate with or without algo

Code: Select all

import FreeCAD,FreeCADGui,Part,OpenSCAD2Dgeom
edges=sum((obj.Shape.Edges for obj in FreeCADGui.Selection.getSelection() if hasattr(obj,'Shape')),[])
faces=OpenSCAD2Dgeom.edgestofaces(edges,algo=None)
#Part.show(faces[0]) #problematic face to ommit
faces2=faces[1:9]+faces[10:15]+faces[16:]
face1=OpenSCAD2Dgeom.Overlappingfaces(faces2).makeshape()
#face2=face1.cut(faces[15]).cut(faces[9])#.fuse(faces[0])
Part.show(face2)
Part.show(faces[0])
Part.show(faces[9])
Part.show(faces[15])
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Creating faces from a DXF file

Post by shoogen »

Code: Select all

import FreeCAD,FreeCADGui,Part,OpenSCAD2Dgeom
edges=sum((obj.Shape.Edges for obj in FreeCADGui.Selection.getSelection() \
    if hasattr(obj,'Shape')),[])
Part.show(OpenSCAD2Dgeom.edgestofaces(edges))
mario52
Veteran
Posts: 4674
Joined: Wed May 16, 2012 2:13 pm

Re: Creating faces from a DXF file

Post by mario52 »

hi
same
Traceback (most recent call last):
File "C:/Program Files/FreeCAD 0.14/Macro_Creating faces from a DXF file.FCMacro", line 11, in <module>
Part.show(OpenSCAD2Dgeom.edgestofaces(edges))
File "C:\Program Files\FreeCAD 0.14\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 393, in edgestofaces
return Overlappingfaces(facel).makeshape()
File "C:\Program Files\FreeCAD 0.14\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 212, in makeshape
return fusefaces(faces)
File "C:\Program Files\FreeCAD 0.14\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 349, in fusefaces
return reduce(lambda p1,p2: p1.fuse(p2),faces)
<type 'exceptions.TypeError'>: reduce() of empty sequence with no initial value

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Creating faces from a DXF file

Post by shoogen »

And what did you select in the gui?
mario52
Veteran
Posts: 4674
Joined: Wed May 16, 2012 2:13 pm

Re: Creating faces from a DXF file

Post by mario52 »

hi
shoogen wrote:And what did you select in the gui?
forget it !!!!
with select,
DxfToShape01.png
DxfToShape01.png (6.8 KiB) Viewed 1749 times
give this error
Traceback (most recent call last):
File "C:/Program Files/FreeCAD 0.14/Macro_Creating faces from a DXF file.FCMacro", line 16, in <module>
faces2=faces[1:9]+faces[10:15]+faces[16:]
<type 'exceptions.TypeError'>: 'Part.TopoShape' object is unsubscriptable

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
jdabbs003
Posts: 26
Joined: Thu Oct 23, 2014 6:23 pm

Re: Creating faces from a DXF file

Post by jdabbs003 »

shoogen is there a way to work on shapes by DXF file layer? For each layer, I want to extrude the shapes differently to create different depth pockets. E.g., Mechanical30 is for holes all the way through the part, Mechanical31 is for pockets 1mm deep, Mechanical is for pockets 4mm deep, etc.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Creating faces from a DXF file

Post by shoogen »

You could try to select the objects by group.

Code: Select all

objectlist=App.ActiveDocument.Mechanical30.Group
edges=sum((obj.Shape.Edges for obj in objectlist \
    if hasattr(obj,'Shape')),[])
But the file you attached to this topic only contained one group.
jdabbs003
Posts: 26
Joined: Thu Oct 23, 2014 6:23 pm

Re: Creating faces from a DXF file

Post by jdabbs003 »

Hi shoogen -- thanks! Yes, the original file had only one layer. We've subsequently broken it up into layers to help automate part generation in OpenSCAD for printing prototypes (attached). We're trying to use FreeCAD to make the CNC data though, since it can output STEP files.
Attachments
PCB7001-shieldtop1.dxf
(133.57 KiB) Downloaded 103 times
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Creating faces from a DXF file

Post by shoogen »

Code: Select all

import FreeCAD,Part,OpenSCAD2Dgeom
doc=App.ActiveDocument
for group in doc.findObjects('App::DocumentObjectGroup'):
    try:
        edges=sum((obj.Shape.Edges for obj in group.Group \
                if hasattr(obj,'Shape')),[])
        face = OpenSCAD2Dgeom.edgestofaces(edges)
        faceobj=doc.addObject('Part::Feature','face_%s' % group.Name)
        faceobj.Label = 'face_%s' % group.Label
        faceobj.Shape = face
    except Part.OCCError:
        FreeCAD.Console.PrintError('Error in Group %s (%s)' % (group.Name,group.Label))
The script fails for Layer Mechnaical29, as there are lines missing.
Post Reply