All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
ef997f2259
commit
9fe130cd73
@@ -10,13 +10,26 @@ __author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
class DistanceBolt:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Length, Edges, Radius, Height '''
|
||||
obj.addProperty("App::PropertyInteger","Edges","Bolt","Number of edges of the outline", locked=True).Edges=6
|
||||
obj.addProperty("App::PropertyLength","Length","Bolt","Length of the edges of the outline", locked=True).Length=10.0
|
||||
obj.addProperty("App::PropertyLength","Radius","Bolt","Radius of the inner circle", locked=True).Radius=4.0
|
||||
obj.addProperty("App::PropertyLength","Height","Bolt","Height of the extrusion", locked=True).Height=20.0
|
||||
"""Add the properties: Length, Edges, Radius, Height"""
|
||||
obj.addProperty(
|
||||
"App::PropertyInteger", "Edges", "Bolt", "Number of edges of the outline", locked=True
|
||||
).Edges = 6
|
||||
obj.addProperty(
|
||||
"App::PropertyLength",
|
||||
"Length",
|
||||
"Bolt",
|
||||
"Length of the edges of the outline",
|
||||
locked=True,
|
||||
).Length = 10.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Radius", "Bolt", "Radius of the inner circle", locked=True
|
||||
).Radius = 4.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Height", "Bolt", "Height of the extrusion", locked=True
|
||||
).Height = 20.0
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
@@ -31,12 +44,12 @@ class DistanceBolt:
|
||||
radius = fp.Radius
|
||||
height = fp.Height
|
||||
|
||||
m=Base.Matrix()
|
||||
m.rotateZ(math.radians(360.0/edges))
|
||||
m = Base.Matrix()
|
||||
m.rotateZ(math.radians(360.0 / edges))
|
||||
|
||||
# create polygon
|
||||
polygon = []
|
||||
v=Base.Vector(length,0,0)
|
||||
v = Base.Vector(length, 0, 0)
|
||||
for i in range(edges):
|
||||
polygon.append(v)
|
||||
v = m.multiply(v)
|
||||
@@ -44,20 +57,21 @@ class DistanceBolt:
|
||||
wire = Part.makePolygon(polygon)
|
||||
|
||||
# create circle
|
||||
circ=Part.makeCircle(radius)
|
||||
circ = Part.makeCircle(radius)
|
||||
|
||||
# Create the face with the polygon as outline and the circle as hole
|
||||
face=Part.Face([wire,Part.Wire(circ)])
|
||||
face = Part.Face([wire, Part.Wire(circ)])
|
||||
|
||||
# Extrude in z to create the final solid
|
||||
extrude=face.extrude(Base.Vector(0,0,height))
|
||||
extrude = face.extrude(Base.Vector(0, 0, height))
|
||||
fp.Shape = extrude
|
||||
|
||||
|
||||
def makeDistanceBolt():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
bolt=doc.addObject("Part::FeaturePython","Distance_Bolt")
|
||||
bolt = doc.addObject("Part::FeaturePython", "Distance_Bolt")
|
||||
bolt.Label = "Distance bolt"
|
||||
DistanceBolt(bolt)
|
||||
bolt.ViewObject.Proxy=0
|
||||
bolt.ViewObject.Proxy = 0
|
||||
|
||||
@@ -2,67 +2,84 @@
|
||||
# (c) 2011 Werner Mayer LGPL
|
||||
#
|
||||
|
||||
from __future__ import division # allows floating point division from integers
|
||||
from __future__ import division # allows floating point division from integers
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
class Epitrochoid:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Radius1, Radius2, Distance, Segments '''
|
||||
obj.addProperty("App::PropertyLength","Radius1","Epitrochoid","Interior radius", locked=True).Radius1=60.0
|
||||
obj.addProperty("App::PropertyLength","Radius2","Epitrochoid","Exterior radius", locked=True).Radius2=20.0
|
||||
obj.addProperty("App::PropertyLength","Distance","Epitrochoid","Distance", locked=True).Distance=10.0
|
||||
obj.addProperty("App::PropertyInteger","Segments","Epitrochoid","Number of the line segments", locked=True).Segments=72
|
||||
"""Add the properties: Radius1, Radius2, Distance, Segments"""
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Radius1", "Epitrochoid", "Interior radius", locked=True
|
||||
).Radius1 = 60.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Radius2", "Epitrochoid", "Exterior radius", locked=True
|
||||
).Radius2 = 20.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Distance", "Epitrochoid", "Distance", locked=True
|
||||
).Distance = 10.0
|
||||
obj.addProperty(
|
||||
"App::PropertyInteger",
|
||||
"Segments",
|
||||
"Epitrochoid",
|
||||
"Number of the line segments",
|
||||
locked=True,
|
||||
).Segments = 72
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Radius1" or prop == "Radius2" or prop == "Distance" or prop == "Segments": #if one of these is changed
|
||||
if (
|
||||
prop == "Radius1" or prop == "Radius2" or prop == "Distance" or prop == "Segments"
|
||||
): # if one of these is changed
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp): #main part of script
|
||||
steps=fp.Segments #get value from property
|
||||
dang=math.radians(360/steps)
|
||||
r2=fp.Radius2
|
||||
r1=fp.Radius1
|
||||
def execute(self, fp): # main part of script
|
||||
steps = fp.Segments # get value from property
|
||||
dang = math.radians(360 / steps)
|
||||
r2 = fp.Radius2
|
||||
r1 = fp.Radius1
|
||||
f1 = r1 + r2
|
||||
f2 = f1 / r2
|
||||
d=fp.Distance
|
||||
ang=0
|
||||
z=0
|
||||
d = fp.Distance
|
||||
ang = 0
|
||||
z = 0
|
||||
|
||||
if r2 == 0:
|
||||
raise ValueError("Exterior radius must not be zero")
|
||||
|
||||
for i in range(steps):
|
||||
if i==0:
|
||||
x1=f1*math.cos(ang)-d*math.cos(f2*ang) #coords for line startpoint
|
||||
y1=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
ang=dang
|
||||
x2=f1*math.cos(ang)-d*math.cos(f2*ang) #coords for line endpoint
|
||||
y2=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
seg=Part.makeLine((x1,y1,z),(x2,y2,z))
|
||||
wire=Part.Wire([seg])
|
||||
x1=x2
|
||||
y1=y2
|
||||
if i == 0:
|
||||
x1 = f1 * math.cos(ang) - d * math.cos(f2 * ang) # coords for line startpoint
|
||||
y1 = f1 * math.sin(ang) - d * math.sin(f2 * ang)
|
||||
ang = dang
|
||||
x2 = f1 * math.cos(ang) - d * math.cos(f2 * ang) # coords for line endpoint
|
||||
y2 = f1 * math.sin(ang) - d * math.sin(f2 * ang)
|
||||
seg = Part.makeLine((x1, y1, z), (x2, y2, z))
|
||||
wire = Part.Wire([seg])
|
||||
x1 = x2
|
||||
y1 = y2
|
||||
else:
|
||||
x2=f1*math.cos(ang)-d*math.cos(f2*ang)
|
||||
y2=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
seg=Part.makeLine((x1,y1,z),(x2,y2,z))
|
||||
wire=Part.Wire([wire,seg])
|
||||
x1=x2
|
||||
y1=y2
|
||||
ang=ang+dang #increment angle
|
||||
fp.Shape = wire #result shape
|
||||
x2 = f1 * math.cos(ang) - d * math.cos(f2 * ang)
|
||||
y2 = f1 * math.sin(ang) - d * math.sin(f2 * ang)
|
||||
seg = Part.makeLine((x1, y1, z), (x2, y2, z))
|
||||
wire = Part.Wire([wire, seg])
|
||||
x1 = x2
|
||||
y1 = y2
|
||||
ang = ang + dang # increment angle
|
||||
fp.Shape = wire # result shape
|
||||
|
||||
|
||||
def makeEpitrochoid():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
epitrochoid=doc.addObject("Part::FeaturePython","Epitrochoid") #add object to document
|
||||
epitrochoid = doc.addObject("Part::FeaturePython", "Epitrochoid") # add object to document
|
||||
epitrochoid.Label = "Epitrochoid"
|
||||
Epitrochoid(epitrochoid)
|
||||
epitrochoid.ViewObject.Proxy=0
|
||||
epitrochoid.ViewObject.Proxy = 0
|
||||
doc.recompute()
|
||||
|
||||
if __name__ == "__main__": #feature will be generated after macro execution
|
||||
|
||||
if __name__ == "__main__": # feature will be generated after macro execution
|
||||
makeEpitrochoid()
|
||||
|
||||
@@ -10,6 +10,7 @@ __author__ = "Werner Mayer <wmayer[at]users.sourceforge.net>"
|
||||
|
||||
import math
|
||||
|
||||
|
||||
# 3d vector class
|
||||
class Vector:
|
||||
def __init__(self, x, y, z):
|
||||
@@ -18,25 +19,26 @@ class Vector:
|
||||
self.z = z
|
||||
|
||||
def add(self, vec):
|
||||
return Vector(self.x+vec.x, self.y+vec.y, self.z+vec.z)
|
||||
return Vector(self.x + vec.x, self.y + vec.y, self.z + vec.z)
|
||||
|
||||
def sub(self, vec):
|
||||
return Vector(self.x-vec.x, self.y-vec.y, self.z-vec.z)
|
||||
return Vector(self.x - vec.x, self.y - vec.y, self.z - vec.z)
|
||||
|
||||
def dot(self, vec):
|
||||
return self.x*vec.x+self.y*vec.y+self.z*vec.z
|
||||
return self.x * vec.x + self.y * vec.y + self.z * vec.z
|
||||
|
||||
def mult(self, s):
|
||||
return Vector(self.x*s, self.y*s, self.z*s)
|
||||
return Vector(self.x * s, self.y * s, self.z * s)
|
||||
|
||||
def cross(self,vec):
|
||||
def cross(self, vec):
|
||||
return Vector(
|
||||
self.y * vec.z - self.z * vec.y,
|
||||
self.z * vec.x - self.x * vec.z,
|
||||
self.x * vec.y - self.y * vec.x)
|
||||
self.x * vec.y - self.y * vec.x,
|
||||
)
|
||||
|
||||
def length(self):
|
||||
return math.sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
|
||||
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
|
||||
|
||||
def norm(self):
|
||||
l = self.length()
|
||||
@@ -67,7 +69,7 @@ def sgn(val):
|
||||
# ccw ... counter-clockwise means which part of the arc is given. ccw must be either True or False
|
||||
|
||||
|
||||
def makeFilletArc(M1,P,Q,N,r2,ccw):
|
||||
def makeFilletArc(M1, P, Q, N, r2, ccw):
|
||||
u = Q.sub(P)
|
||||
v = P.sub(M1)
|
||||
if ccw:
|
||||
@@ -83,14 +85,14 @@ def makeFilletArc(M1,P,Q,N,r2,ccw):
|
||||
# distinguish between internal and external fillets
|
||||
r2 *= sgn(uv)
|
||||
|
||||
cc = 2.0 * r2 * (b.dot(v)-r1)
|
||||
cc = 2.0 * r2 * (b.dot(v) - r1)
|
||||
dd = uv * uv - uu * cc
|
||||
if dd < 0:
|
||||
raise RuntimeError("Unable to calculate intersection points")
|
||||
t1 = (-uv + math.sqrt(dd)) / uu
|
||||
t2 = (-uv - math.sqrt(dd)) / uu
|
||||
|
||||
if (abs(t1) < abs(t2)):
|
||||
if abs(t1) < abs(t2):
|
||||
t = t1
|
||||
else:
|
||||
t = t2
|
||||
@@ -100,13 +102,12 @@ def makeFilletArc(M1,P,Q,N,r2,ccw):
|
||||
ut = u.mult(t)
|
||||
print(ut)
|
||||
M2 = P.add(ut).add(br2)
|
||||
S1 = M1.mult(r2/(r1+r2)).add(M2.mult(r1/(r1+r2)))
|
||||
S1 = M1.mult(r2 / (r1 + r2)).add(M2.mult(r1 / (r1 + r2)))
|
||||
S2 = M2.sub(br2)
|
||||
|
||||
return (S1, S2, M2)
|
||||
|
||||
|
||||
|
||||
def test():
|
||||
from FreeCAD import Base
|
||||
import Part
|
||||
@@ -126,6 +127,13 @@ def test():
|
||||
Part.show(Part.makeLine(P3, Q))
|
||||
Part.show(arc.toShape())
|
||||
|
||||
(S1, S2, M2) = makeArc(Vector(C.x,C.y,C.z), Vector(P3.x,P3.y,P3.z), Vector(Q.x, Q.y, Q.z), Vector(axis.x, axis.y, axis.z), r2, ccw)
|
||||
(S1, S2, M2) = makeArc(
|
||||
Vector(C.x, C.y, C.z),
|
||||
Vector(P3.x, P3.y, P3.z),
|
||||
Vector(Q.x, Q.y, Q.z),
|
||||
Vector(axis.x, axis.y, axis.z),
|
||||
r2,
|
||||
ccw,
|
||||
)
|
||||
circle = Part.Circle(Base.Vector(M2.x, M2.y, M2.z), Base.Vector(0, 0, 1), math.fabs(r2))
|
||||
Part.show(circle.toShape())
|
||||
|
||||
@@ -36,36 +36,36 @@ def compute():
|
||||
N = int(l1.text())
|
||||
p = float(l2.text())
|
||||
alfa = int(l3.text())
|
||||
y = float(l4.text()) # standard value y<1 for gear drives y>1 for Gear pumps
|
||||
m = p/math.pi # standard value 0.06, 0.12, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 60 (polish norm)
|
||||
c = float(l5.text())*m # standard value 0,1*m - 0,3*m
|
||||
j = float(l6.text())*m # standard value 0,015 - 0,04*m
|
||||
width = float(l7.text()) # gear width
|
||||
y = float(l4.text()) # standard value y<1 for gear drives y>1 for Gear pumps
|
||||
m = (
|
||||
p / math.pi
|
||||
) # standard value 0.06, 0.12, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 60 (polish norm)
|
||||
c = float(l5.text()) * m # standard value 0,1*m - 0,3*m
|
||||
j = float(l6.text()) * m # standard value 0,015 - 0,04*m
|
||||
width = float(l7.text()) # gear width
|
||||
except ValueError:
|
||||
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed.\n")
|
||||
|
||||
|
||||
# tooth height
|
||||
h = 2*y*m+c
|
||||
h = 2 * y * m + c
|
||||
|
||||
# pitch diameter
|
||||
d = N*m
|
||||
d = N * m
|
||||
|
||||
# root diameter
|
||||
df = d - 2*y*m - 2*c # df=d-2hf where and hf=y*m+c
|
||||
df = d - 2 * y * m - 2 * c # df=d-2hf where and hf=y*m+c
|
||||
|
||||
# addendum diameter
|
||||
da = d + 2*y*m # da=d+2ha where ha=y*m
|
||||
da = d + 2 * y * m # da=d+2ha where ha=y*m
|
||||
|
||||
# base diameter for involute
|
||||
db = d * math.cos(math.radians(alfa))
|
||||
|
||||
|
||||
#Base circle
|
||||
# Base circle
|
||||
baseCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "BaseCircle")
|
||||
Draft._Circle(baseCircle)
|
||||
Draft._ViewProviderDraft(baseCircle.ViewObject)
|
||||
baseCircle.Radius = db/2
|
||||
baseCircle.Radius = db / 2
|
||||
baseCircle.FirstAngle = 0.0
|
||||
baseCircle.LastAngle = 0.0
|
||||
|
||||
@@ -73,7 +73,7 @@ def compute():
|
||||
rootCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "RootCircle")
|
||||
Draft._Circle(rootCircle)
|
||||
Draft._ViewProviderDraft(rootCircle.ViewObject)
|
||||
rootCircle.Radius = df/2
|
||||
rootCircle.Radius = df / 2
|
||||
rootCircle.FirstAngle = 0.0
|
||||
rootCircle.LastAngle = 0.0
|
||||
|
||||
@@ -81,7 +81,7 @@ def compute():
|
||||
addendumCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "AddendumCircle")
|
||||
Draft._Circle(addendumCircle)
|
||||
Draft._ViewProviderDraft(addendumCircle.ViewObject)
|
||||
addendumCircle.Radius = da/2
|
||||
addendumCircle.Radius = da / 2
|
||||
addendumCircle.FirstAngle = 0.0
|
||||
addendumCircle.LastAngle = 0.0
|
||||
|
||||
@@ -89,105 +89,122 @@ def compute():
|
||||
pitchCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "PitchCircle")
|
||||
Draft._Circle(pitchCircle)
|
||||
Draft._ViewProviderDraft(pitchCircle.ViewObject)
|
||||
pitchCircle.Radius = d/2
|
||||
pitchCircle.Radius = d / 2
|
||||
pitchCircle.FirstAngle = 0.0
|
||||
pitchCircle.LastAngle = 0.0
|
||||
|
||||
#************ Calculating right sides of teeth
|
||||
# ************ Calculating right sides of teeth
|
||||
# Involute of base circle
|
||||
involute = []
|
||||
involutee = []
|
||||
involutesav = []
|
||||
|
||||
for t in range(0, 60, 1):
|
||||
x = db/2*(math.cos(math.radians(t))+math.radians(t)*math.sin(math.radians(t)))
|
||||
y = db/2*(math.sin(math.radians(t))-math.radians(t)*math.cos(math.radians(t)))
|
||||
x = db / 2 * (math.cos(math.radians(t)) + math.radians(t) * math.sin(math.radians(t)))
|
||||
y = db / 2 * (math.sin(math.radians(t)) - math.radians(t) * math.cos(math.radians(t)))
|
||||
involute.append(Part.Vertex(x, y, 0).Point)
|
||||
|
||||
#************ Drawing right sides of teeth
|
||||
# ************ Drawing right sides of teeth
|
||||
involutesav.extend(involute)
|
||||
involutee.extend(involute)
|
||||
|
||||
for angle in range(1, N+1, 1):
|
||||
for angle in range(1, N + 1, 1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature", "InvoluteL" + str(angle))
|
||||
involutee.insert(0, (0, 0, 0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape=involuteshape
|
||||
involuteobj.Shape = involuteshape
|
||||
involutee = []
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
pointt = Part.Vertex(
|
||||
point.x * math.cos(math.radians(angle * 360 / N))
|
||||
- point.y * math.sin(math.radians(angle * 360 / N)),
|
||||
point.x * math.sin(math.radians(angle * 360 / N))
|
||||
+ point.y * math.cos(math.radians(angle * 360 / N)),
|
||||
0,
|
||||
).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutesav)
|
||||
involutee = []
|
||||
|
||||
#************ Calculating difference between tooth spacing on BaseCircle and PitchCircle
|
||||
# ************ Calculating difference between tooth spacing on BaseCircle and PitchCircle
|
||||
|
||||
pc = App.ActiveDocument.getObject("PitchCircle")
|
||||
inv = App.ActiveDocument.getObject("InvoluteL1")
|
||||
cut = inv.Shape.cut(pc.Shape)
|
||||
# FreeCAD.ActiveDocument.addObject("Part::Feature","CutInv").Shape=cut
|
||||
# FreeCAD.ActiveDocument.addObject("Part::Feature","CutInv").Shape=cut
|
||||
invPoint = cut.Vertexes[0].Point
|
||||
|
||||
diff = invPoint.y*2 # instead of making axial symmetry and calculating point distance.
|
||||
anglediff = 2*math.asin(diff/d)
|
||||
diff = invPoint.y * 2 # instead of making axial symmetry and calculating point distance.
|
||||
anglediff = 2 * math.asin(diff / d)
|
||||
|
||||
#************ Calculating left sides of teeth
|
||||
# ************ Calculating left sides of teeth
|
||||
|
||||
#************ Inversing Involute
|
||||
# ************ Inversing Involute
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x, point.y*-1, 0).Point
|
||||
pointt = Part.Vertex(point.x, point.y * -1, 0).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutee)
|
||||
involutee = []
|
||||
|
||||
#Normal tooth size calculated as: 0,5* p - j j = m * 0,1 below are calculations
|
||||
# 0,5* p - m * 0,1
|
||||
# 0,5* p - p /pi * 0,1
|
||||
# 0,5*360/N - ((360/N)/pi)* 0,1
|
||||
# 0,5*360/N - (360/N)*((1/pi)*0,1) j = (p/pi)*0,1
|
||||
# 0,5*360/N - (360/N)*((p/pi)*0,1)/p
|
||||
# 0,5*360/N - (360/N)*( j )/p
|
||||
# Normal tooth size calculated as: 0,5* p - j j = m * 0,1 below are calculations
|
||||
# 0,5* p - m * 0,1
|
||||
# 0,5* p - p /pi * 0,1
|
||||
# 0,5*360/N - ((360/N)/pi)* 0,1
|
||||
# 0,5*360/N - (360/N)*((1/pi)*0,1) j = (p/pi)*0,1
|
||||
# 0,5*360/N - (360/N)*((p/pi)*0,1)/p
|
||||
# 0,5*360/N - (360/N)*( j )/p
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff) - point.y*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff),point.x*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff) + point.y*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff),0).Point
|
||||
pointt = Part.Vertex(
|
||||
point.x * math.cos(math.radians(180 / N - (360 / N) * (j / p)) + anglediff)
|
||||
- point.y * math.sin(math.radians(180 / N - (360 / N) * (j / p)) + anglediff),
|
||||
point.x * math.sin(math.radians(180 / N - (360 / N) * (j / p)) + anglediff)
|
||||
+ point.y * math.cos(math.radians(180 / N - (360 / N) * (j / p)) + anglediff),
|
||||
0,
|
||||
).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutee)
|
||||
involutesav = []
|
||||
involutesav.extend(involute)
|
||||
|
||||
#************ Drawing left sides of teeth
|
||||
for angle in range(1, N+1, 1):
|
||||
# ************ Drawing left sides of teeth
|
||||
for angle in range(1, N + 1, 1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature", "InvoluteR" + str(angle))
|
||||
involutee.insert(0, (0, 0, 0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape = involuteshape
|
||||
involutee = []
|
||||
for num in range(0,60,1):
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
pointt = Part.Vertex(
|
||||
point.x * math.cos(math.radians(angle * 360 / N))
|
||||
- point.y * math.sin(math.radians(angle * 360 / N)),
|
||||
point.x * math.sin(math.radians(angle * 360 / N))
|
||||
+ point.y * math.cos(math.radians(angle * 360 / N)),
|
||||
0,
|
||||
).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutesav)
|
||||
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
#************ Forming teeth
|
||||
# ************ Forming teeth
|
||||
|
||||
cutCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "CutCircle")
|
||||
Draft._Circle(cutCircle)
|
||||
Draft._ViewProviderDraft(cutCircle.ViewObject)
|
||||
cutCircle.Radius = da # da because must be bigger than addendumCircle and bigger than whole construction da is right for this but it not has to be.
|
||||
cutCircle.Radius = da # da because must be bigger than addendumCircle and bigger than whole construction da is right for this but it not has to be.
|
||||
cutCircle.FirstAngle = 0.0
|
||||
cutCircle.LastAngle = 0.0
|
||||
|
||||
|
||||
cutTool = cutCircle.Shape.cut(addendumCircle.Shape)
|
||||
# cutshape = Part.show(cutTool)
|
||||
|
||||
gearShape = rootCircle.Shape
|
||||
|
||||
for invNum in range(1, N+1, 1):
|
||||
for invNum in range(1, N + 1, 1):
|
||||
invL = App.ActiveDocument.getObject("InvoluteL" + str(invNum))
|
||||
invR = App.ActiveDocument.getObject("InvoluteR" + str(invNum))
|
||||
cutL = invL.Shape.cut(cutTool)
|
||||
@@ -200,11 +217,10 @@ def compute():
|
||||
toothWhole = toothWhole.fuse(faceEdge)
|
||||
toothWire = Part.Wire(toothWhole.Edges)
|
||||
toothShape = Part.Face(toothWire)
|
||||
# tooth = App.ActiveDocument.addObject("Part::Feature", "Tooth" +str(invNum))
|
||||
# tooth.Shape=toothShape
|
||||
# tooth = App.ActiveDocument.addObject("Part::Feature", "Tooth" +str(invNum))
|
||||
# tooth.Shape=toothShape
|
||||
gearShape = gearShape.fuse(toothShape)
|
||||
|
||||
|
||||
for o in App.ActiveDocument.Objects:
|
||||
if oldDocumentObjects.count(o) == 0:
|
||||
App.ActiveDocument.removeObject(o.Name)
|
||||
@@ -218,12 +234,13 @@ def compute():
|
||||
gear.Dir = (0, 0, width)
|
||||
App.ActiveDocument.recompute()
|
||||
|
||||
|
||||
if c1.isChecked():
|
||||
gearMesh = App.ActiveDocument.addObject("Mesh::Feature", "Gear3D-mesh")
|
||||
|
||||
faces = []
|
||||
triangles = gear.Shape.tessellate(1) # the number represents the precision of the tessellation)
|
||||
triangles = gear.Shape.tessellate(
|
||||
1
|
||||
) # the number represents the precision of the tessellation)
|
||||
for tri in triangles[1]:
|
||||
face = []
|
||||
for i in range(3):
|
||||
@@ -236,20 +253,20 @@ def compute():
|
||||
App.ActiveDocument.removeObject(gear.Name)
|
||||
App.ActiveDocument.removeObject(gearFlat.Name)
|
||||
|
||||
|
||||
App.ActiveDocument.recompute()
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
QtGui.QApplication.restoreOverrideCursor()
|
||||
|
||||
|
||||
hide()
|
||||
|
||||
|
||||
def hide():
|
||||
dialog.hide()
|
||||
|
||||
|
||||
dialog = QtGui.QDialog()
|
||||
dialog.resize(200,450)
|
||||
dialog.resize(200, 450)
|
||||
dialog.setWindowTitle("Gear")
|
||||
la = QtGui.QVBoxLayout(dialog)
|
||||
t1 = QtGui.QLabel("Number of teeth (N)")
|
||||
@@ -296,7 +313,7 @@ la.addWidget(e1)
|
||||
|
||||
okbox = QtGui.QDialogButtonBox(dialog)
|
||||
okbox.setOrientation(QtCore.Qt.Horizontal)
|
||||
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
|
||||
la.addWidget(okbox)
|
||||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
|
||||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
|
||||
|
||||
@@ -10,12 +10,19 @@ __author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
class Parallelepiped:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Length, Edges, Radius, Height '''
|
||||
obj.addProperty("App::PropertyVector","A","Parallelepiped","Vector", locked=True).A=Base.Vector(1,0,0)
|
||||
obj.addProperty("App::PropertyVector","B","Parallelepiped","Vector", locked=True).B=Base.Vector(0,1,0)
|
||||
obj.addProperty("App::PropertyVector","C","Parallelepiped","Vector", locked=True).C=Base.Vector(0,0,1)
|
||||
"""Add the properties: Length, Edges, Radius, Height"""
|
||||
obj.addProperty("App::PropertyVector", "A", "Parallelepiped", "Vector", locked=True).A = (
|
||||
Base.Vector(1, 0, 0)
|
||||
)
|
||||
obj.addProperty("App::PropertyVector", "B", "Parallelepiped", "Vector", locked=True).B = (
|
||||
Base.Vector(0, 1, 0)
|
||||
)
|
||||
obj.addProperty("App::PropertyVector", "C", "Parallelepiped", "Vector", locked=True).C = (
|
||||
Base.Vector(0, 0, 1)
|
||||
)
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
@@ -27,24 +34,31 @@ class Parallelepiped:
|
||||
b = fp.B
|
||||
c = fp.C
|
||||
|
||||
m=Base.Matrix()
|
||||
m.A11=a.x
|
||||
m.A12=a.y
|
||||
m.A13=a.z
|
||||
m.A21=b.x
|
||||
m.A22=b.y
|
||||
m.A23=b.z
|
||||
m.A31=c.x
|
||||
m.A32=c.y
|
||||
m.A33=c.z
|
||||
box = Part.makeBox(1,1,1)
|
||||
m = Base.Matrix()
|
||||
m.A11 = a.x
|
||||
m.A12 = a.y
|
||||
m.A13 = a.z
|
||||
m.A21 = b.x
|
||||
m.A22 = b.y
|
||||
m.A23 = b.z
|
||||
m.A31 = c.x
|
||||
m.A32 = c.y
|
||||
m.A33 = c.z
|
||||
box = Part.makeBox(1, 1, 1)
|
||||
fp.Shape = box.transformGeometry(m)
|
||||
|
||||
|
||||
class BoxCylinder:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("App::PropertyFloat","Length","BoxCylinder","Length", locked=True).Length=10.0
|
||||
obj.addProperty("App::PropertyFloat","Width","BoxCylinder","Width", locked=True).Width=10.0
|
||||
obj.addProperty("App::PropertyLink","Source","BoxCylinder","Source", locked=True).Source=None
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat", "Length", "BoxCylinder", "Length", locked=True
|
||||
).Length = 10.0
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat", "Width", "BoxCylinder", "Width", locked=True
|
||||
).Width = 10.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLink", "Source", "BoxCylinder", "Source", locked=True
|
||||
).Source = None
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
@@ -52,36 +66,37 @@ class BoxCylinder:
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
FreeCAD.Console.PrintMessage(str(fp.Source)+"\n")
|
||||
FreeCAD.Console.PrintMessage(str(fp.Source) + "\n")
|
||||
if fp.Source is None:
|
||||
return
|
||||
r = fp.Source.Radius
|
||||
l = fp.Length
|
||||
w = fp.Width
|
||||
h = 2*r+10
|
||||
fp.Shape = Part.makeBox(l,w,h)
|
||||
h = 2 * r + 10
|
||||
fp.Shape = Part.makeBox(l, w, h)
|
||||
|
||||
|
||||
def makeParallelepiped():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
obj=doc.addObject("Part::FeaturePython","Parallelepiped")
|
||||
obj = doc.addObject("Part::FeaturePython", "Parallelepiped")
|
||||
obj.Label = "Parallelepiped"
|
||||
Parallelepiped(obj)
|
||||
obj.ViewObject.Proxy=0
|
||||
obj.ViewObject.Proxy = 0
|
||||
|
||||
|
||||
def makeBoxCylinder():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
cyl=doc.addObject("Part::Cylinder","Cylinder")
|
||||
cyl.Radius=16.0
|
||||
cyl.Height=800.0
|
||||
obj=doc.addObject("Part::FeaturePython","Box")
|
||||
cyl = doc.addObject("Part::Cylinder", "Cylinder")
|
||||
cyl.Radius = 16.0
|
||||
cyl.Height = 800.0
|
||||
obj = doc.addObject("Part::FeaturePython", "Box")
|
||||
BoxCylinder(obj)
|
||||
obj.Source=cyl
|
||||
obj.Length=800.0
|
||||
obj.Width=600.0
|
||||
obj.ViewObject.Proxy=0
|
||||
obj.Source = cyl
|
||||
obj.Length = 800.0
|
||||
obj.Width = 600.0
|
||||
obj.ViewObject.Proxy = 0
|
||||
doc.recompute()
|
||||
|
||||
@@ -10,6 +10,7 @@ import FreeCAD, FreeCADGui, Part, math
|
||||
from PySide import QtGui
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
def makeCopy(shape, radius, angle):
|
||||
mat = Base.Matrix()
|
||||
mat.rotateZ(math.radians(angle))
|
||||
@@ -25,14 +26,16 @@ def makeCopy(shape, radius, angle):
|
||||
|
||||
class RadialCopy:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("App::PropertyLength","Radius","","Radius", locked=True).Radius=10.0
|
||||
obj.addProperty("App::PropertyLength","Angle" ,"","Angle", locked=True).Angle=20.0
|
||||
obj.addProperty("App::PropertyLink","Source" ,"","Source shape", locked=True).Source=None
|
||||
obj.addProperty("App::PropertyLength", "Radius", "", "Radius", locked=True).Radius = 10.0
|
||||
obj.addProperty("App::PropertyLength", "Angle", "", "Angle", locked=True).Angle = 20.0
|
||||
obj.addProperty("App::PropertyLink", "Source", "", "Source shape", locked=True).Source = (
|
||||
None
|
||||
)
|
||||
obj.Proxy = self
|
||||
|
||||
# def onChanged(self, fp, prop):
|
||||
# if prop == "Angle" or prop == "Radius":
|
||||
# self.execute(fp)
|
||||
# def onChanged(self, fp, prop):
|
||||
# if prop == "Angle" or prop == "Radius":
|
||||
# self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
shape = fp.Source.Shape
|
||||
@@ -40,6 +43,7 @@ class RadialCopy:
|
||||
angle = fp.Angle
|
||||
fp.Shape = makeCopy(shape, radius, angle)
|
||||
|
||||
|
||||
def makeRadialCopy():
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
try:
|
||||
@@ -47,13 +51,12 @@ def makeRadialCopy():
|
||||
shape = sel.Shape
|
||||
name = sel.Label
|
||||
except (IndexError, AttributeError):
|
||||
QtGui.QMessageBox.critical(None,"Wrong selection","Please select a shape object")
|
||||
#raise Exception("Nothing selected")
|
||||
QtGui.QMessageBox.critical(None, "Wrong selection", "Please select a shape object")
|
||||
# raise Exception("Nothing selected")
|
||||
else:
|
||||
doc = sel.Document
|
||||
rc = doc.addObject("Part::FeaturePython","RadialCopy")
|
||||
rc.Label = name+"(Radial Copy)"
|
||||
rc = doc.addObject("Part::FeaturePython", "RadialCopy")
|
||||
rc.Label = name + "(Radial Copy)"
|
||||
RadialCopy(rc)
|
||||
rc.Source = sel
|
||||
rc.ViewObject.Proxy=0
|
||||
|
||||
rc.ViewObject.Proxy = 0
|
||||
|
||||
@@ -1,51 +1,61 @@
|
||||
#! python
|
||||
# (c) 2011 Adrian Przekwas LGPL
|
||||
|
||||
from __future__ import division # allows floating point division from integers
|
||||
from __future__ import division # allows floating point division from integers
|
||||
import FreeCAD, Part
|
||||
from FreeCAD import Base
|
||||
|
||||
|
||||
class MySpring:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Pitch, Diameter, Height, BarDiameter '''
|
||||
obj.addProperty("App::PropertyLength", "Pitch", "MySpring", "Pitch of the helix", locked=True).Pitch = 5.0
|
||||
obj.addProperty("App::PropertyLength", "Diameter", "MySpring", "Diameter of the helix", locked=True).Diameter = 6.0
|
||||
obj.addProperty("App::PropertyLength", "Height", "MySpring", "Height of the helix", locked=True).Height = 30.0
|
||||
obj.addProperty("App::PropertyLength", "BarDiameter", "MySpring", "Diameter of the bar", locked=True).BarDiameter = 3.0
|
||||
obj.Proxy = self
|
||||
def __init__(self, obj):
|
||||
"""Add the properties: Pitch, Diameter, Height, BarDiameter"""
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Pitch", "MySpring", "Pitch of the helix", locked=True
|
||||
).Pitch = 5.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Diameter", "MySpring", "Diameter of the helix", locked=True
|
||||
).Diameter = 6.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "Height", "MySpring", "Height of the helix", locked=True
|
||||
).Height = 30.0
|
||||
obj.addProperty(
|
||||
"App::PropertyLength", "BarDiameter", "MySpring", "Diameter of the bar", locked=True
|
||||
).BarDiameter = 3.0
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarDiameter":
|
||||
self.execute(fp)
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarDiameter":
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
pitch = fp.Pitch
|
||||
radius = fp.Diameter / 2
|
||||
height = fp.Height
|
||||
barradius = fp.BarDiameter / 2
|
||||
myhelix = Part.makeHelix(pitch, height, radius)
|
||||
g = myhelix.Edges[0].Curve
|
||||
c = Part.Circle()
|
||||
c.Center = g.value(0) # start point of the helix
|
||||
c.Axis = (0, 1, 0)
|
||||
c.Radius = barradius
|
||||
p = c.toShape()
|
||||
section = Part.Wire([p])
|
||||
makeSolid = True
|
||||
isFrenet = True
|
||||
myspring = Part.Wire(myhelix).makePipeShell([section], makeSolid, isFrenet)
|
||||
fp.Shape = myspring
|
||||
|
||||
def execute(self, fp):
|
||||
pitch = fp.Pitch
|
||||
radius = fp.Diameter/2
|
||||
height = fp.Height
|
||||
barradius = fp.BarDiameter/2
|
||||
myhelix = Part.makeHelix(pitch, height, radius)
|
||||
g = myhelix.Edges[0].Curve
|
||||
c = Part.Circle()
|
||||
c.Center = g.value(0) # start point of the helix
|
||||
c.Axis = (0, 1, 0)
|
||||
c.Radius = barradius
|
||||
p = c.toShape()
|
||||
section = Part.Wire([p])
|
||||
makeSolid = True
|
||||
isFrenet = True
|
||||
myspring = Part.Wire(myhelix).makePipeShell([section], makeSolid, isFrenet)
|
||||
fp.Shape = myspring
|
||||
|
||||
def makeMySpring():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
spring = doc.addObject("Part::FeaturePython", "My_Spring")
|
||||
spring.Label = "My Spring"
|
||||
MySpring(spring)
|
||||
spring.ViewObject.Proxy = 0
|
||||
doc.recompute()
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
spring = doc.addObject("Part::FeaturePython", "My_Spring")
|
||||
spring.Label = "My Spring"
|
||||
MySpring(spring)
|
||||
spring.ViewObject.Proxy = 0
|
||||
doc.recompute()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
makeMySpring()
|
||||
makeMySpring()
|
||||
|
||||
Reference in New Issue
Block a user