Making a Face from makeWire()

Need help, or want to share a macro? Post here!
greg_b
Posts: 21
Joined: Sat Oct 01, 2016 11:53 pm

Making a Face from makeWire()

Postby greg_b » Fri Sep 21, 2018 11:41 pm

This is my first FreeCAD python script, but I'm having trouble getting a face made from a closed wire. Here is the script in question:

Code: Select all

import FreeCAD, Draft, Part

wall_thickness = 4.0
length = 40.0
diameter = 100.0

verts = [(0,0,0),(0,wall_thickness,0),(length,wall_thickness,0),(length,0,0)]
outline = Draft.makeWire(verts,closed=True)
profile = Part.Face(outline)  # Things die here

solid = profile.revolve((0,diameter/2,0),(1,0,0),360)
But that dies on the line where I try to make a Face from a Wire, so that I can revolve it (eventually). The output in the "Report view" is:

Traceback (most recent call last):
File "C:/stuff/revolve_test.py", line 10, in <module>
profile = Part.Face(outline)
<class 'Part.OCCError'>: Argument list signature is incorrect.

Supported signatures:
(face)
(wire)
(face, wire)
(surface, wire)
(list_of_wires)
(wire, facemaker_class_name)
(list_of_wires, facemaker_class_name)
(surface, list_of_wires)


...which would seem to indicate that I could feed Part.Face with a wire, which I would have thought would have been the output of makeWire. But I must be missing something. When I try type(outline), I get <type 'FeaturePython'>, which isn't real informative. The Python console prints it out as a <Part::Part2DObject>. I can take the output of the makeWire(), and use the "Revolve" button on the Part workbench to get the ultimate revolution I'm after, so the wire seems like it must be valid and closed. I'm probably missing something very basic.

FWIW, I was trying to steal ideas from: https://forum.freecadweb.org/viewtopic. ... 792#p37621 in my search for how to programmatically make a revolution.

Thanks!

Greg

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13515 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: e17b340949b75a226cc7d89989b0aa238ccfc75f
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
User avatar
Chris_G
Posts: 1502
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Making a Face from makeWire()

Postby Chris_G » Sat Sep 22, 2018 7:25 am

Draft.makeWire() is a high-level tool, that creates a FreeCAD object : this is the DWire that appears in the Tree-View.
Its shape can be a Wire or a Face :

Code: Select all

o1 = Draft.makeWire(verts,closed=False)
o1.Shape # is a wire
o2 = Draft.makeWire(verts,closed=True)
o2.Shape # is a face
So you have 2 options :
- you can keep on using Draft.makeWire() and use the "Shape" property of the object

Code: Select all

profile = outline.Shape
solid = profile.revolve(FreeCAD.Vector(0,diameter/2,0),FreeCAD.Vector(1,0,0),360)
- or you can create only the wire (not a whole FreeCAD object) :

Code: Select all

vecs = [FreeCAD.Vector(t) for t in verts] # convert tuples to vectors
vecs.append(vecs[0]) # to close the wire
wire = Part.makePolygon(vecs)
face = Part.Face(wire)
solid = face.revolve(FreeCAD.Vector(0,diameter/2,0),FreeCAD.Vector(1,0,0),360)
Part.show(solid)
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: Making a Face from makeWire()

Postby damian » Sat Sep 22, 2018 7:54 am

Good morning:
Chris_G wrote:
Sat Sep 22, 2018 7:25 am
or you can create only the wire (not a whole FreeCAD object)
To make a face is the most frequent OCCT operation for me. I'm doing

Code: Select all

face=Part.makeFace(wireList, "Part::FaceMakerBullseye")
Where wireList is a list of wires, and in consequence, the face could have holes.
greg_b wrote:
Fri Sep 21, 2018 11:41 pm
(list_of_wires, facemaker_class_name)
Others FaceMaker available are "Part::FaceMakerSimple" and "Part::FaceMakerChesse"
greg_b
Posts: 21
Joined: Sat Oct 01, 2016 11:53 pm

[SOLVED] Re: Making a Face from makeWire()

Postby greg_b » Sat Sep 22, 2018 3:13 pm

Thanks everyone. I've now got a working script! It looks like I need to start diving into the difference between "high" level and "low" level commands/objects and how to tell one from the other (and figuring out what the difference between a line, edge, wire, and segment are, etc.).

Thanks,

Greg