Why can't I make a wire from these two edges?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
crobar
Posts: 160
Joined: Fri Aug 29, 2014 1:26 pm

Re: Why can't I make a wire from these two edges?

Post by crobar »

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!
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Why can't I make a wire from these two edges?

Post by NormandC »

Since this topic is exclusively about python scripting I moved it from the Help on using FreeCAD forum to the appropriate forum.
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Re: Why can't I make a wire from these two edges?

Post by Son »

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
<class 'Part.OCCError'>: BRep_API: command not done
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.

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()
Error:
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
FreeCAD version:
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
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Why can't I make a wire from these two edges?

Post by Chris_G »

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.
User avatar
shaise
Posts: 492
Joined: Thu Jun 11, 2015 8:11 am

Re: Why can't I make a wire from these two edges?

Post by shaise »

I think that if you use Part.makeLine it will be compatible both for v0.16 and v0.17
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Re: Why can't I make a wire from these two edges?

Post by Son »

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.
Thank you very much, Chris_G :) My script works again.
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Re: Why can't I make a wire from these two edges?

Post by Son »

shaise wrote:I think that if you use Part.makeLine it will be compatible both for v0.16 and v0.17
Hi shaise,

I tried Part.makeLine and it worked too. Didn't know this before. Thanks. :D
Post Reply