4 Replies Latest reply on Jan 24, 2018 4:22 PM by Matt Mitchell

    3D Sketch Macro not evaluating z coordinates

    Matt Mitchell

      In SW 2017 3D sketch example: http://help.solidworks.com/2017/english/api/sldworksapi/create_3d_sketch_plane_example_vb.htm does not evaluate z coordinates.  i.e. all created center lines are on 0z even if value is modified.

        • Re: 3D Sketch Macro not evaluating z coordinates
          Ivana Kolin

          Sub main()

              Set swApp = Application.SldWorks

              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchSnapsHVLines, False

              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchSnapsHVPoints, False

           

           

          ' rest of the macro

           

           

              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchSnapsHVLines, True

              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchSnapsHVPoints, True

          End Sub

            • Re: 3D Sketch Macro not evaluating z coordinates
              Matt Mitchell

              It changed nothing about the results.

               

              Matt

                • Re: 3D Sketch Macro not evaluating z coordinates
                  Ivana Kolin
                  Option Explicit
                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ModelDoc2
                  Dim swModelDocExt As SldWorks.ModelDocExtension
                  Dim swSketchManager As SldWorks.SketchManager
                  Dim swSketchSegment As SldWorks.SketchSegment
                  Dim swSketch As SldWorks.Sketch
                  Dim status As Boolean
                  Sub main()
                      Dim DefaultAssTemplate As String
                      Set swApp = Application.SldWorks
                      DefaultAssTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateAssembly)
                  
                  
                      Set swModel = swApp.NewDocument(DefaultAssTemplate, 0, 0, 0)
                       
                      Set swSketchManager = swModel.SketchManager
                      swSketchManager.Insert3DSketch True
                      Set swSketchSegment = swSketchManager.CreateCenterLine(-0.082642, 0.005659, 0#, -0.049926, 0.045073, 0#)
                      Set swSketch = swSketchManager.ActiveSketch
                      status = swSketch.SetWorkingPlaneOrientation(0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0)
                      Set swSketchSegment = swSketchManager.CreateLine(-0.049926, 0.045073, 0#, -0.049926, -0.022634, -0.065874)
                      swSketchSegment.ConstructionGeometry = True
                      Set swSketch = swSketchManager.ActiveSketch
                      status = swSketch.SetWorkingPlaneOrientation(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0)
                      swModel.ClearSelection2 True
                      swSketchManager.InsertSketch True
                      'Insert 2D sketch of a circle
                      swModel.ActivateSelectedFeature
                      swModel.ClearSelection2 True
                      swSketchManager.InsertSketch True
                      Set swModelDocExt = swModel.Extension
                      status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
                      swModel.ClearSelection2 True
                      Set swSketchSegment = swSketchManager.CreateCircle(-0.056401, 0.005985, 0#, -0.054697, -0.005141, 0#)
                      swModel.ClearSelection2 True
                      swSketchManager.InsertSketch True
                      swModel.ClearSelection2 True
                      'Insert a 3D sketch plane
                      swSketchManager.Insert3DSketch True
                      status = swModelDocExt.SelectByID2("Line1@3DSketch1", "EXTSKETCHSEGMENT", -5.65609614209999E-02, 3.70796232466087E-02, 0, True, 0, Nothing, 0)
                      status = swModelDocExt.SelectByID2("Point2@Sketch1", "EXTSKETCHPOINT", -5.64010297276809E-02, 5.98490302365917E-03, 0, True, 0, Nothing, 0)
                      status = swSketchManager.CreateSketchPlane(9, 9, 0)
                      status = swModelDocExt.SelectByID2("Plane1", "SKETCHSURFACES", 0, 0, 0, False, 0, Nothing, 0)
                      swModel.ActivateSelectedFeature
                      swModel.ClearSelection2 True
                      swSketchManager.InsertSketch True
                      swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchInference, True
                  End Sub