2 Replies Latest reply on Dec 10, 2018 10:57 AM by Fifi Riri

    Solidworks macro

    changliang lv

      I want to build a knitted fabric coil model, has been completed and recorded macro, now running error, inserted in the reference level this sentence error, I hope there are good people can help me!

       

      Dim swApp As Object

      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long

      Sub main()

      Set swApp = _
      Application.SldWorks

      Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2016\templates\gb_part.prtdot", 0, 0, 0)
      swApp.ActivateDoc2 "零件2", False, longstatus
      Set Part = swApp.ActiveDoc
      Dim myModelView As Object
      Set myModelView = Part.ActiveView
      myModelView.FrameState = swWindowState_e.swWindowMaximized
      Part.SketchManager.Insert3DSketch True
      Dim equationDriveCurve As Object
      Set equationDriveCurve = Part.SketchManager.CreateEquationSpline2("0.075*cos(t)", "(0.568*t)/pi", "0.075*sin(t)", "pi/2", "pi", False, 0, 0, 0, True, True)
      Part.ClearSelection2 True
      Part.SketchManager.Insert3DSketch True
      Part.SetPickMode
      Part.ClearSelection2 True
      Part.SketchManager.Insert3DSketch True
      Set equationDriveCurve = Part.SketchManager.CreateEquationSpline2("0.279*cos(t)+0.204", "0.279*sin(t)*(sin(arctan(0.568/(pi*0.075))))+0.568", "-0.279*sin(t)*(cos(arctan(0.568/(pi*0.075))))", "0", "pi", False, 0, 0, 0, True, True)
      Part.ClearSelection2 True
      Part.SketchManager.Insert3DSketch True
      Part.SetPickMode
      Part.ClearSelection2 True
      Part.SetPickMode
      Part.SketchManager.Insert3DSketch True
      Set equationDriveCurve = Part.SketchManager.CreateEquationSpline2("0.075*cos(t)+0.408", "(-0.568*t)/pi+0.568", "0.075*sin(t)", "0", "pi/2", False, 0, 0, 0, True, True)
      Part.ClearSelection2 True
      Part.SketchManager.Insert3DSketch True
      Part.SetPickMode
      Part.ClearSelection2 True

       

      Set myModelView = Part.ActiveView
      myModelView.RotateAboutCenter -1.75835409715847E-02, 0.278404566360324
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Point3@3D草图1", "EXTSKETCHPOINT", 0, 0.000284, 0.000075, True, 1, Nothing, 0)
      Dim myRefPlane As Object
      Set myRefPlane = Part.FeatureManager.InsertRefPlane(1, 0, 4, 0, 0, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.ClearSelection2 True

       

      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Point4@3D草图3", "EXTSKETCHPOINT", 0.000408, 0.000284, 0.000075, True, 1, Nothing, 0)
      Set myRefPlane = Part.FeatureManager.InsertRefPlane(1, 0, 4, 0, 0, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.ClearSelection2 True

      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("Point3@3D草图2", "EXTSKETCHPOINT", 0.000483, 0.000568, 0, False, 0, Nothing, 0)
      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("Point3@3D草图2", "EXTSKETCHPOINT", 0.000483, 0.000568, 0, False, 0, Nothing, 0)

      Set myModelView = Part.ActiveView
      myModelView.RotateAboutCenter 3.51670819431694E-03, 0
      boolstatus = Part.Extension.SelectByID2("Point3@3D草图2", "EXTSKETCHPOINT", 0.000483, 0.000568, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Spline2@3D草图2", "EXTSKETCHSEGMENT", -0.000075, 5.67999999999812E-04, 0, True, 1, Nothing, 0)
      Set myRefPlane = Part.FeatureManager.InsertRefPlane(4, 0, 2, 0, 0, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("Point3@3D草图2", "EXTSKETCHPOINT", 0.000483, 0.000568, 0, False, 0, Nothing, 0)
      Part.ClearSelection2 True
      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("Point4@3D草图1", "EXTSKETCHPOINT", -0.000075, 0.000568, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Point4@3D草图1", "EXTSKETCHPOINT", -0.000075, 0.000568, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Spline2@3D草图2", "EXTSKETCHSEGMENT", -7.16596509139201E-05, 6.06598426956561E-04, -1.60115142473838E-05, True, 1, Nothing, 0)
      Set myRefPlane = Part.FeatureManager.InsertRefPlane(4, 0, 2, 0, 0, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("Point4@3D草图1", "EXTSKETCHPOINT", -0.000075, 0.000568, 0, False, 0, Nothing, 0)
      Part.ClearSelection2 True
      Part.SetPickMode
      Part.ClearSelection2 True
      Part.SetPickMode

       

      boolstatus = Part.Extension.SelectByID2("基准面1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.SketchManager.InsertSketch True
      Part.ClearSelection2 True
      Dim skSegment As Object
      Set skSegment = Part.SketchManager.CreateCircle(0#, -0.000075, 0#, -0.000014, -0.00004, 0#)
      Part.ClearSelection2 True
      Part.SketchManager.InsertSketch True
      boolstatus = Part.Extension.SelectByID2("基准面2", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.SketchManager.InsertSketch True
      Part.ClearSelection2 True
      Set skSegment = Part.SketchManager.CreateCircle(0.000408, -0.000075, 0#, 0.000385, -0.000024, 0#)
      Part.ClearSelection2 True
      Part.SketchManager.InsertSketch True
      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("基准面3", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.SketchManager.InsertSketch True
      Part.ClearSelection2 True
      Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, -0.000011, 0.000041, 0#)
      Part.ClearSelection2 True
      Part.SketchManager.InsertSketch True
      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("基准面4", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      Part.SketchManager.InsertSketch True
      Part.ClearSelection2 True
      Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, 0.000111, 0.000086, 0#)
      Part.ClearSelection2 True
      Part.SketchManager.InsertSketch True
      Part.SetPickMode
      Part.ClearSelection2 True
      Part.SetPickMode
      boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 4.49539623633657E-04, -2.116265544834E-05, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图3", "SKETCH", 3.9485529731395E-05, 5.53614752497721E-05, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图4", "SKETCH", -5.58949298854199E-05, 3.87266938054876E-05, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", 5.89374545037079E-05, -1.08917200011548E-04, 0, True, 0, Nothing, 0)
      Part.ClearSelection2 True
      Part.SetPickMode
      Part.SetPickMode
      boolstatus = Part.Extension.SelectByID2("3D草图3", "SKETCH", -1.59611142684112E-04, 2.92871397113331E-04, -1.35453718524438E-05, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("3D草图2", "SKETCH", -2.02055138477819E-04, 4.23367121605451E-04, -7.04345991953471E-05, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("3D草图1", "SKETCH", -2.07221920884152E-04, 4.23040896945763E-04, 2.89993898079128E-05, True, 0, Nothing, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("3D草图3", "SKETCH", -1.59611142684112E-04, 2.92871397113331E-04, -1.35453718524438E-05, False, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("3D草图2", "SKETCH", -2.02055138477819E-04, 4.23367121605451E-04, -7.04345991953471E-05, True, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("3D草图1", "SKETCH", -2.07221920884152E-04, 4.23040896945763E-04, 2.89993898079128E-05, True, 1, Nothing, 0)
      Part.InsertCompositeCurve
      Part.SetPickMode
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 4.27599400282332E-04, -9.88576569925024E-06, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图3", "SKETCH", 2.86420936435154E-05, 6.16735800137798E-05, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图4", "SKETCH", -6.24971132082434E-05, 2.67975902020314E-05, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", 5.30997369203589E-05, -1.17478440872855E-04, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("组合曲线1", "REFERENCECURVES", 0.100471591858707, 3.54815638325761E-02, 5.28296013234453E-03, True, 0, Nothing, 0)
      Part.ClearSelection2 True
      boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 4.27599400282332E-04, -9.88576569925024E-06, 0, False, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图3", "SKETCH", 2.86420936435154E-05, 6.16735800137798E-05, 0, True, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图4", "SKETCH", -6.24971132082434E-05, 2.67975902020314E-05, 0, True, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", 5.30997369203589E-05, -1.17478440872855E-04, 0, True, 1, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("组合曲线1", "REFERENCECURVES", 0.100471591858707, 3.54815638325761E-02, 5.28296013234453E-03, True, 4, Nothing, 0)
      Part.FeatureManager.InsertProtrusionBlend False, True, False, 1, 6, 6, 1, 1, True, True, False, 0, 0, 0, True, True, True
      Part.SetPickMode
      Part.ClearSelection2 True

       

      myModelView.TranslateBy 0, -5.52173913043478E-04
      Set myModelView = Part.ActiveView
      myModelView.TranslateBy 0, -5.52173913043478E-04
      End Sub