Right, so on closer investigation, the main problem is in fact down to me. I was importing points from a file to create my geometry. I had written these values to the file with what turned out to be insufficient precision. This was the root cause of my issue.
Thanks for helping me find this!
Why can't I make a wire from these two edges?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Why can't I make a wire from these two edges?
Since this topic is exclusively about python scripting I moved it from the Help on using FreeCAD forum to the appropriate forum.
Re: Why can't I make a wire from these two edges?
I have a script that works fine in 0.16 but doesn't when I switched to 0.17 (I know the current 0.17 is not a stable version but I needed the Part Slice tool https://www.freecadweb.org/wiki/Part_Slice). It showed the error
Since the data are simple numbers input directly in the script, I don't think it has anything to do with tolerance but have no idea how to get pass this point. Any help is appreciated.
Error:
In order to rule out mistakes in my script, I tested the problem with the basic example here (my very first lesson in FreeCAD scripting ) https://www.freecadweb.org/wiki/Manual: ... ic_objects. Again, it works fine in 0.16 but fails in 0.17.<class 'Part.OCCError'>: BRep_API: command not done
Since the data are simple numbers input directly in the script, I don't think it has anything to do with tolerance but have no idea how to get pass this point. Any help is appreciated.
Code: Select all
import FreeCAD,Part
class ParametricRectangle:
def __init__(self,obj):
obj.Proxy = self
obj.addProperty("App::PropertyFloat","Length").Length = 10.0
obj.addProperty("App::PropertyFloat","Width").Width = 5.0
def execute(self,obj):
# first we need to make sure the values of Length and Width are not 0
# otherwise the Part.Line will complain that both points are equal
if (obj.Length == 0) or (obj.Width == 0):
# if yes, exit this method without doing anything
return
# we create 4 points for the 4 corners
v1 = FreeCAD.Vector(0,0,0)
v2 = FreeCAD.Vector(obj.Length,0,0)
v3 = FreeCAD.Vector(obj.Length,obj.Width,0)
v4 = FreeCAD.Vector(0,obj.Width,0)
# we create 4 edges
e1 = Part.Line(v1,v2).toShape()
e2 = Part.Line(v2,v3).toShape()
e3 = Part.Line(v3,v4).toShape()
e4 = Part.Line(v4,v1).toShape()
# we create a wire
w = Part.Wire([e1,e2,e3,e4])
# we create a face
f = Part.Face(w)
# All shapes have a Placement too. We give our shape the value of the placement
# set by the user. This will move/rotate the face automatically.
f.Placement = obj.Placement
# all done, we can attribute our shape to the object!
obj.Shape = f
# MAIN SCRIPT: Create a parametric object
myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Rectangle")
ParametricRectangle(myObj)
myObj.ViewObject.Proxy = 0 # this is mandatory unless we code the ViewProvider too
App.ActiveDocument.recompute()
FreeCAD version:Traceback (most recent call last):
File "C:/Users/Son/Desktop/FreeCAD 0.17/Macro/ParamRectangle.py", line 30, in execute
w = Part.Wire([e1,e2,e3,e4])
<class 'Part.OCCError'>: BRep_API: command not done
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10460 (Git)
Build type: Release
Branch: master
Hash: 91c59c7910436c44ede608e29d9a90a287121a11
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
Re: Why can't I make a wire from these two edges?
Hi,
There has been a change in 0.17 about Part.Line.
Part.Line is now an infinite line.
Part.LineSegment is ... a line segment.
There has been a change in 0.17 about Part.Line.
Part.Line is now an infinite line.
Part.LineSegment is ... a line segment.
Re: Why can't I make a wire from these two edges?
I think that if you use Part.makeLine it will be compatible both for v0.16 and v0.17
Re: Why can't I make a wire from these two edges?
Thank you very much, Chris_G My script works again.Chris_G wrote:Hi,
There has been a change in 0.17 about Part.Line.
Part.Line is now an infinite line.
Part.LineSegment is ... a line segment.
Re: Why can't I make a wire from these two edges?
Hi shaise,shaise wrote:I think that if you use Part.makeLine it will be compatible both for v0.16 and v0.17
I tried Part.makeLine and it worked too. Didn't know this before. Thanks.