目录
1、手动建模
2、python自动建模
1、手动建模
第一步:草图1,在上视基准面画一个圆心在原点,直径50mm的圆;
第二步:草图2,在上视基准面画两条构造线,一条经过原点方向竖直,另一条同样经过原点,与前者夹角30°,然后画一个直径2.5mm的圆,将其圆心约束在第二条构造线上
第三步:扫描,轮廓为草图2,路径为草图1,扭转50圈,得到圆形弹簧。
2、python自动建模
import win32com.client as win32
import pythoncom
swApp = win32.Dispatch('sldworks.application')
swApp.Visible = True
Nothing = win32.VARIANT(pythoncom.VT_DISPATCH, None)
Part = swApp.NewDocument(r"C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\gb_part.prtdot", 0, 0, 0)
swPart = Part
Part.SketchManager.InsertSketch(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0.188860841006942, 0.100112928494525, 4.97830164353559E-02, False, 0, Nothing, 0)
Part.ClearSelection2(True)
skSegment = Part.SketchManager.CreateCircle(0, 0, 0, 0.078729, -0.00057, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 7.79681291362058E-02, 0.011, -2.0918278548738E-03, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(0.100788069371193, 0, -1.16001362861183E-02)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D1@草图1")
myDimension.SystemValue = 0.05
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2(True)
skSegment = Part.SketchManager.CreateCenterLine(0, 0, 0, 0, -0.029287, 0)
Part.ClearSelection2(True)
skSegment = Part.SketchManager.CreateCenterLine(0, 0, 0, 0.018237, -0.0282, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 1.59420289855072E-02, 3.49300410547659E-03, 2.56642512077295E-02, False, 0, Nothing, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", -1.20772946859915E-04, 3.49300410547656E-03, 2.02294685990338E-02, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 8.93719806763284E-03, 3.49300410547651E-03, 1.40700483091787E-02, True, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(7.85024154589371E-03, 0, 1.74516908212561E-02)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D1@草图2")
myDimension.SystemValue = 0.5235987755983
Part.ClearSelection2(True)
skSegment = Part.SketchManager.CreateCircle(0.036473, -0.014191, 0, 0.041787, -0.017572, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 0.042512077294686, 3.49300410547652E-03, 1.52777777777778E-02, False, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(4.64975845410628E-02, 0, 1.46739130434783E-02)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D2@草图2")
myDimension.SystemValue = 0.0025
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Point6", "SKETCHPOINT", 3.64734299516908E-02, -1.41908212560387E-02, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 1.41304347826087E-02, 3.49300410547659E-03, 2.46980676328502E-02, True, 0, Nothing, 0)
Part.SketchAddConstraints("sgCOINCIDENT")
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 1.22288134053267E-04, -8.40790429292215E-03, 5.00000000000925E-05, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point6", "SKETCHPOINT", 2.97336674744748E-03, 5.15002227611493E-03, 0, True, 0, Nothing, 0)
myDisplayDim = Part.AddDimension2(2.89576459055716E-02, 1.72382894854328E-02, 0)
Part.ClearSelection2(True)
myDimension = Part.Parameter("D3@草图2")
myDimension.SystemValue = 0.035/2
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 1.84217624883487E-02, -3.11551958984316E-02, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", -2.06551763495207E-02, -1.40841645109038E-02, 0, True, 0, Nothing, 0)
Part.ClearSelection2(True)
boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 1.84217624883487E-02, -3.11551958984316E-02, 0, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", -2.06551763495207E-02, -1.40841645109038E-02, 0, True, 4, Nothing, 0)
myFeature = Part.FeatureManager.InsertProtrusionSwept4(False, False, 8, False, False, 0, 0, False, 0, 0, 0, 0, True, True, True, 314.15926535898, True, False, 0.01, False)
Part.ClearSelection2(True)
Part.ShowNamedView2("*上下二等角轴测", 8)
Part.SelectionManager.EnableContourSelection = False
Part.ViewZoomtofit2()