目录
1、参数
2、手动建模
2.1方程式驱动曲线画渐开线
2.2画基圆、齿根圆、分度圆和齿顶圆
2.3画单个齿廓
2.4以齿厚拉伸基圆草图
2.5以齿厚拉伸单齿廓草图
2.6阵列齿数个单齿
3、python自动化建模
4、总结
1、参数
模数 "m" = 2
齿数"z"= 50
压力角 "a"= 20
分度圆直径 "d"= "m" * "z"
齿顶圆直径 "da"= ( "z" + 2 ) * "m"
齿根圆直径 "df"= ( "z" - 2.5 ) * "m"
基圆直径 "db"= "m" * "z" * cos ( "a" )
基圆半径 "rb"= "db" / 2
分度圆齿厚 "s"= pi * "m" / 2
齿厚 "B"= 0.3 * "d"
齿根圆角 "r"= 0.38 * "m"
2、手动建模
2.1方程式驱动曲线画渐开线
在上视基准面构建草图1,画渐开线齿廓
xt="rb"*cos(t)+"rb"*t*sin(t)
yt="rb"*sin(t)-"rb"*t*cos(t)
t1=0
t2=pi/4
2.2画基圆、齿根圆、分度圆和齿顶圆
在上视基准面构建草图2,以构造线画基圆、齿根圆、分度圆和齿顶圆
2.3画单个齿廓
在上视基准面构建草图3,对草图1的渐开线转换实体引用,对草图2基圆、齿根圆、分度圆和齿顶圆转换实体引用,画出齿宽中心构造线进行约束,然后裁剪掉齿顶圆外的部分渐开线,再对齿根圆与渐开线作圆角,最后以齿宽中心构造线为对称轴对称另一侧并画出齿底圆部分。
2.4以齿厚拉伸基圆草图
在上视基准面构建草图4,以齿根圆尺寸画圆,约束后退出草图,以齿厚为尺寸拉伸凸台
2.5以齿厚拉伸单齿廓草图
选择草图3,以齿厚为尺寸拉伸凸台
2.6阵列齿数个单齿
3、python自动化建模
#导入win32com.client库,并将其简写为win32以方便后续使用
import win32com.client as win32
import pythoncom
import numpy as np
m=2/1000
z=50
a=20*np.pi/180
d=m*z
da= (z + 2)* m
df= (z - 2.5 ) * m
db= m*z* np.cos(a)
rb= db / 2
s= np.pi * m / 2
B= 0.3 * d
r= 0.38 * m
#使用Dispatch函数创建一个SolidWorks应用程序的实例。这里,"sldworks.application"是SolidWorks应用程序的COM对象标识符
swApp = win32.Dispatch("sldworks.application")
#使得SolidWorks应用程序可见。
swApp.Visible=True
Nothing = win32.VARIANT(pythoncom.VT_DISPATCH, None)
swSheetWidth = 0
swSheetHeight = 0
Part = swApp.NewDocument(r"C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\gb_part.prtdot", 0, swSheetWidth, swSheetHeight)
#sketch1 spline
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
equationDriveCurve = Part.SketchManager.CreateEquationSpline2(f"{1000*rb}*cos(t)+{1000*rb}*t*sin(t)", f"{1000*rb}*sin(t)-{1000*rb}*t*cos(t)", "", "0", "pi/4", False, 0, 0, 0, True, True)
Part.SketchManager.InsertSketch(True)
#sketch2 4circle
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
skSegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, 10*db)
skSegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, 10*df)
skSegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, 10*d)
skSegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, 10*da)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", -4.17913430963818E-02, 4.06570904526804E-03, 0, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(-0.129688100551224, 0, 4.06570904526804E-03)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc2", "SKETCHSEGMENT", -7.00577012206262E-02, 5.61455058632253E-03, 0, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(-0.145176515961769, 0, 5.2273402010589E-03)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc3", "SKETCHSEGMENT", -8.74821685574891E-02, 4.84012981579529E-03, 0, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(-0.160664931372314, 0, 9.09944405369512E-03)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc4", "SKETCHSEGMENT", -0.108778739746988, 1.35523634842269E-03, 0, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(-0.183123133717604, 0, 2.12965711894994E-03)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D1@草图2")
myDimension.SystemValue = db
myDimension = Part.Parameter("D3@草图2")
myDimension.SystemValue = df
myDimension = Part.Parameter("D2@草图2")
myDimension.SystemValue = d
myDimension = Part.Parameter("D4@草图2")
myDimension.SystemValue = da
Part.SketchManager.InsertSketch(True)
#sketch3
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Spline2@草图1", "EXTSKETCHSEGMENT", 5.68109938451896E-02, 4.85306098373878E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
Part.ClearSelection2(True)
skSegment = Part.SketchManager.CreateCenterLine(0, 0, 0, 0.076976, 0.012754, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc2@草图2", "EXTSKETCHSEGMENT", 4.98812101498907E-02, -3.44454263762836E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc2", "SKETCHSEGMENT", 4.96566221826677E-02, 0, 5.84977550063237E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Point9", "SKETCHPOINT", 4.93275253639167E-02, 8.17283558333082E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point10", "SKETCHPOINT", 4.99944465783859E-02, 7.45192136917484E-04, 0, True, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(7.32063894288394E-02, 0, -2.05367474294104E-03)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D1@草图3")
myDimension.SystemValue = s/2
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc1@草图2", "EXTSKETCHSEGMENT", 4.69732428651685E-02, -1.05103745408897E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc4", "SKETCHSEGMENT", 4.69719073506605E-02, 0, -1.09337721747326E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Spline2", "SKETCHSEGMENT", 4.79822046708633E-02, 3.17508241647045E-03, -6.01947737600295E-05, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Arc4", "SKETCHSEGMENT", 4.68002780288081E-02, 3.17508241647046E-03, 8.7549715120034E-04, True, 0, Nothing, 0)
skSegment = Part.SketchManager.CreateFillet(r, 1)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc4@草图2", "EXTSKETCHSEGMENT", 5.19985313273173E-02, -3.90819398187038E-04, 0, False, 0, Nothing, 0)
boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc7", "SKETCHSEGMENT", 5.19429524769286E-02, 0, 2.43509506581086E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Spline2", "SKETCHSEGMENT", 5.65326491634615E-02, 0, -4.6272000856053E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Spline2", "SKETCHSEGMENT", 5.27616245715102E-02, 0, -2.05666338249153E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 5.57072998941891E-02, 0.011, -2.62243109097623E-03, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point22", "SKETCHPOINT", 5.19442248953657E-02, 2.40779982965117E-03, 0, True, 0, Nothing, 0)
Part.SketchAddConstraints("sgFIXED")
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc5", "SKETCHSEGMENT", 4.70597163100455E-02, 0.011, 3.38711166624456E-04, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Spline2", "SKETCHSEGMENT", 4.86320042344352E-02, 0.011, -3.16408801871271E-04, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Arc7", "SKETCHSEGMENT", 5.20648328693528E-02, 0.011, -1.83628712878136E-03, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 4.81079082596386E-02, 0.011, -2.25556390861863E-03, True, 0, Nothing, 0)
Part.SketchMirror()
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc4", "SKETCHSEGMENT", 4.66277826249411E-02, 0, -5.7797440583439E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc4", "SKETCHSEGMENT", 4.68500779201268E-02, 0.011, -3.43477985191093E-03, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 4.87106186306547E-02, 0.011, -2.30797350609828E-03, True, 0, Nothing, 0)
Part.SketchMirror()
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc2", "SKETCHSEGMENT", 4.99783574598799E-02, 0, -1.47098117339316E-03, False, 2, Nothing, 0)
boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)
Part.SketchManager.InsertSketch(True)
#sketch4
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc1@草图2", "EXTSKETCHSEGMENT", 4.69092540638955E-02, -2.66685360845074E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
boolstatus = Part.Extension.SelectByID2("草图4", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0,B, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("草图3", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, B, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("凸台-拉伸2", "BODYFEATURE", 0, 0, 0, False, 4, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 1.00069959505049E-02, 2.39622182303378E-02, 4.59065963226521E-02, True, 1, Nothing, 0)
myFeature = Part.FeatureManager.FeatureCircularPattern4(z, 6.2831853071796, False, "NULL", False, True, False)
Part.ClearSelection2(True)
Part.ShowNamedView2("*上下二等角轴测", 8)
Part.ViewZoomtofit2()
4、总结
自动化建模只需要两个参数,即模数m和齿数z,但是更改这两个参数后无法成功,原因是有些API受到尺寸的影响而失效,需要解决这个问题才能实现任意更改参数。