Part.Line has no StartPoint and no EndPoint in 0.17

Need help, or want to share a macro? Post here!
User avatar
bernd
Posts: 8414
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Part.Line has no StartPoint and no EndPoint in 0.17

Postby bernd » Mon Jul 03, 2017 8:40 pm

from wiki Part_Module

Code: Select all

Part.Line()
l.StartPoint=(0.0,0.0,0.0)
l.EndPoint=(1.0,1.0,1.0) 

Code: Select all

>>>
>>> l=Part.Line()
>>> l.StartPoint=(0.0,0.0,0.0)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'Part.Line' object has no attribute 'StartPoint'
>>> l.EndPoint=(1.0,1.0,1.0) 
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'Part.Line' object has no attribute 'EndPoint'
>>> 
OS: Debian GNU/Linux 8.8 (jessie)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.11478 (Git)
Build type: Debug
Branch: master
Hash: c806e4529e54b93cb22b1ed096c1d8cb37aa00ff
Python version: 2.7.9
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.0.0
triplus
Posts: 8706
Joined: Mon Dec 12, 2011 4:45 pm

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby triplus » Mon Jul 03, 2017 8:50 pm

Yes that is correct as the API changed.

P.S. You need to use Part.LineSegment() now.
User avatar
bernd
Posts: 8414
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby bernd » Mon Jul 03, 2017 8:59 pm

and the other way around, if I have and edge

I have an old script ...

Code: Select all

l1 = edges[0]
l2 = edges[1]
assert(l1.Curve.EndPoint == l2.Curve.StartPoint)
dir1 =l1.Curve.EndPoint - l1.Curve.StartPoint
dir2 =l2.Curve.EndPoint - l2.Curve.StartPoint
normal = dir1.cross(dir2)
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby damian » Mon Jul 03, 2017 10:10 pm

Code: Select all

l1 = edges[0]
l2 = edges[1]
assert(l1.lastVertex(True).Point == l2.firstVertex(True).Point)
dir1 =l1.lastVertex(True).Point - l1.firstVertex(True).Point
dir2 =l2.lastVertex(True).Point - l2.firstVertex(True).Point
normal = dir1.cross(dir2)
User avatar
bernd
Posts: 8414
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby bernd » Mon Jul 03, 2017 11:15 pm

Code: Select all

l = Part.LineSegment()
l.StartPoint=(0.0,0.0,0.0)
l.EndPoint=(1.0,1.0,1.0)

Code: Select all

l.toShape()
I still have problems, tried for nearly two hours ... https://github.com/berndhahnebach/BOLTS ... py#L25-L74

I solved it the lazy way ATM ... https://github.com/berndhahnebach/BOLTS ... #L218-L223
mlampert
Posts: 1326
Joined: Fri Sep 16, 2016 9:28 pm

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby mlampert » Mon Jul 03, 2017 11:51 pm

Code: Select all

Part.Edge(Part.LineSegment(FreeCAD.Vector(0,0,0), FreeCAD.Vector(1,1,1)))
I've been using this construct to create edges - does that work for you?
User avatar
bernd
Posts: 8414
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby bernd » Wed Jun 12, 2019 12:57 pm

played once again with this ... The aim ist to make a fillet between two lines by Python. I had no success, but may be this is beause I do not have enought patience for the math stuff ... May be some other would like to give it a try. This is needed for filleting the lines for BOLTS profiles. The code attached seams to have worked with FreeCAD 0.16

Code: Select all

import Part, math

box = Part.makeBox(10, 10, 10)
l1 = box.Edges[0]
l2 = box.Edges[1]
radius = 5

Part.show(box)
Part.show(l1)
Part.show(l2)

assert(l1.Curve.EndPoint == l2.Curve.StartPoint)
dir1 =l1.Curve.EndPoint - l1.Curve.StartPoint
dir2 =l2.Curve.EndPoint - l2.Curve.StartPoint

normal = dir1.cross(dir2)

raw_angle = math.asin(normal[2]/dir1.Length/dir2.Length)
# This is the smaller angle enclosed by the two lines in radians
angle = math.pi - abs(raw_angle)

# to find the transition points of the fillet, we consider a rectangular
# triangle with one kathete equal to the radius and the other one lying on
# one of the input lines with length a
a = radius/math.tan(0.5*angle)
# parameter per length
ppl1 = (l1.Curve.LastParameter-l1.Curve.FirstParameter)/l1.Curve.length()
ppl2 = (l2.Curve.LastParameter-l2.Curve.FirstParameter)/l2.Curve.length()

t1 = l1.Curve.value(l1.Curve.LastParameter - a*ppl1)
t2 = l2.Curve.value(l1.Curve.FirstParameter + a*ppl2)

# to fine the center of the fillet radius, we construct the angle bisector
# between the two input lines, and get the distance of the center from the
# common point by a trigonometric consideration
bis = Part.makeLine(l1.Curve.EndPoint,(t1+t2).scale(0.5,0.5,0.5))
pplb = (bis.Curve.LastParameter-bis.Curve.FirstParameter)/bis.Curve.length()
d = radius/math.sin(0.5*angle)
center = bis.Curve.value(bis.Curve.FirstParameter + d*pplb)

# to construct the circle we need start and end angles
r1 = t1 - center
r2 = t2 - center
if raw_angle > 0:
    alpha1 = math.atan2(r1[1],r1[0])*180/math.pi
    alpha2 = math.atan2(r2[1],r2[0])*180/math.pi
else:
    alpha2 = math.atan2(r1[1],r1[0])*180/math.pi
    alpha1 = math.atan2(r2[1],r2[0])*180/math.pi
    normal *= -1

fli1 = Part.makeLine(l1.Curve.StartPoint,t1)
fcir = Part.makeCircle(radius,center,normal,alpha1,alpha2)
fli2 = Part.makeLine(t2,l2.Curve.EndPoint)

Part.show(fli1)
Part.show(fcir)
Part.show(fli2)
https://github.com/boltsparts/BOLTS/blo ... #L415-L467
openBrain
Posts: 2119
Joined: Fri Nov 09, 2018 5:38 pm

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby openBrain » Wed Jun 12, 2019 1:31 pm

Hi bernd, at this point this isn't clear what a "fillet between 2 lines" means (I admit that I didn't have the patience to read the code yet). ;)
Could you explain what you want with a (hand) sketch ?
And maybe also provide a base file where the macro can be tested on ?
carlopav
Posts: 290
Joined: Mon Dec 31, 2018 1:49 pm

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby carlopav » Wed Jun 12, 2019 2:07 pm

Draft module DraftGeomUtils.py have a fillet function, but I've never played with it...
User avatar
bernd
Posts: 8414
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Part.Line has no StartPoint and no EndPoint in 0.17

Postby bernd » Wed Jun 12, 2019 2:09 pm