HI Ralf

Interesting I hadn't tried that, I found out what was causing the script to fail on the second attempt (after the first try failed)

it hadn't failed completely the first time as the geometry was placed at Z-1 (the setting I had in the script).

When I put the geometry back at Z = 0 it worked again.

I also made this change to the script, but forgot to mention it in the previous post.

I had a look at an old textbook of vector math to swat up a bit as I've forgotten a lot of the details.

The divide by zero error I was sometimes getting was caused by the cross product calc.

what happens is the cross product is a magnitude and an angle between them and if the two vectors lay on top of each other

the angle = 0 , so I added these two lines to the script.

#### Remaining Segments - Calculate Cut Points (C1,C2) and Cut Segment Bulge (C1B)

C1 = Point2F(P1X+V1.X*KnifeTipOffset,P1Y+V1.Y*KnifeTipOffset)

if seg.GetType().Name == "XPolySegLine":

C1B = 0

C2 = Point2F(P2X+V2.X*KnifeTipOffset, P2Y+V2.Y*KnifeTipOffset)

elif seg.GetType().Name == "XPolySegArc":

C1B = Math.Tan(seg.Sweep/4)

** if V2.X == 0:**

Vector2F.X.SetValue(V2,1) C2X = P2X+KnifeTipOffset/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)

C2Y = P2Y+(KnifeTipOffset*V2.Y/V2.X)/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)

C2 = Point2F(C2X,C2Y)

I also found this script at the DXF2Gode site, it's originally Bill's script from here, where they also had to modify the script

to get it to work for them.

So might provide some clues for us.

def make_swivelknife_move(self):

"""

Set these variables for your tool and material

@param offset: knife tip distance from tool centerline. The radius of the

tool is used for this.

"""

offset =self.shape.LayerContent.tool_diameter/2

dragAngle = self.shape.dragAngle

startnorm = offset*Point(1,0,0)

prvend, prvnorm = Point(0,0),Point(0,0)

first = 1

#start = self.startp

#Use The same parent as for the shape

self.parent=self.shape.parent

for geo in self.shape.geos:

if geo.type == 'LineGeo':

geo_b = deepcopy(geo)

if first:

first = 0

prvend = geo_b.Pa + startnorm

prvnorm = startnorm

norm = offset*geo_b.Pa.unit_vector(geo_b.Pe)

geo_b.Pa += norm

geo_b.Pe += norm

if not prvnorm == norm:

swivel = ArcGeo(Pa=prvend, Pe=geo_b.Pa, r=offset,direction=prvnorm.cross_product(norm).z)

swivel.drag = dragAngle < abs(swivel.ext)

self.geos.append(swivel)

self.geos.append(geo_b)

prvend = geo_b.Pe

prvnorm = norm

elif geo.type == 'ArcGeo':

geo_b = deepcopy(geo)

if first:

first = 0

prvend = geo_b.Pa + startnorm

prvnorm = startnorm

if geo_b.ext > 0.0:

norma = offset*Point(cos(geo_b.s_ang+pi/2),sin(geo_b.s_ang+pi/2))

norme = Point(cos(geo_b.e_ang+pi/2), sin(geo_b.e_ang+pi/2))

else:

norma = offset*Point(cos(geo_b.s_ang-pi/2), sin(geo_b.s_ang-pi/2))

norme = Point(cos(geo_b.e_ang-pi/2), sin(geo_b.e_ang-pi/2))

geo_b.Pa += norma

if norme.x > 0:

geo_b.Pe = Point(geo_b.Pe.x+offset/(sqrt(1+(norme.y/norme.x)**2)),geo_b.Pe.y+(offset*norme.y/norme.x)/(sqrt(1+(norme.y/norme.x)**2)))

elif norme.x ==0:

geo_b.Pe = Point(geo_b.Pe.x,

geo_b.Pe.y)

else:

geo_b.Pe = Point(geo_b.Pe.x-offset/(sqrt(1+(norme.y/norme.x)**2)), geo_b.Pe.y-(offset*norme.y/norme.x)/(sqrt(1+(norme.y/norme.x)**2)))

if not prvnorm == norma:

swivel = ArcGeo(Pa=prvend, Pe=geo_b.Pa, r=offset, direction=prvnorm.cross_product(norma).z)

swivel.drag = dragAngle < abs(swivel.ext)

self.geos.append(swivel)

prvend = geo_b.Pe

prvnorm = offset*norme

if -pi<geo_b.ext<pi:

self.geos.append(ArcGeo(Pa=geo_b.Pa, Pe=geo_b.Pe, r=sqrt(geo_b.r**2+offset**2), direction=geo_b.ext))

else:

geo_b = ArcGeo(Pa=geo_b.Pa, Pe=geo_b.Pe, r=sqrt(geo_b.r**2+offset**2), direction=-geo_b.ext)

geo_b.ext = -geo_b.ext

self.geos.append(geo_b)

else:

self.geos.append(copy(geo))

if not prvnorm == startnorm:

self.geos.append(ArcGeo(Pa=prvend, Pe=prvend-prvnorm+startnorm, r=offset, direction=prvnorm.cross_product(startnorm).z))

self.geos.insert(0,self.geos[0].Pa)

Why I originally removed the Arc's was that the code as is was sometimes adding the geometry to the wrong end of the Arc.

I'm subed to 3Blue1brown where he has a series of Math videos, and I know he did Vectors, so on the weekend I'll look at a few jog my memory.

Dave