3 Replies Latest reply on Jun 25, 2014 7:07 AM by Ar K

    Create Plane

    Ar K

      Hi :-)

      I have a sketch with chain of segments (lines,arcs,splines,...)

      I want to create a normal Plane in end point of this sketch automaticly.

      Do you have an idea or answer for this ?

      Please help me :-)

        • Re: Create Plane
          Artem Taturevych

          Hi,

           

          Try this. Select the spline in the closed sketch before running the macro.

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swSelMgr As SldWorks.SelectionMgr

           

          Sub main()

           

              Set swApp = Application.SldWorks

           

              Set swModel = swApp.ActiveDoc

           

              Set swSelMgr = swModel.SelectionManager

           

              Dim swSkSpline As SldWorks.SketchSpline

           

              Set swSkSpline = swSelMgr.GetSelectedObject6(1, -1)

           

              Dim vPts As Variant

              vPts = swSkSpline.GetPoints2()

           

              Dim swStartPt As SldWorks.SketchPoint

              Dim swEndPt As SldWorks.SketchPoint

           

              Set swStartPt = vPts(0)

              Set swEndPt = vPts(UBound(vPts))

           

              CreatePlane swStartPt, swSkSpline

              CreatePlane swEndPt, swSkSpline

           

          End Sub

           

          Sub CreatePlane(skPoint As SldWorks.SketchPoint, skSeg As SldWorks.SketchSegment)

           

              swModel.ClearSelection2 True

           

              skPoint.Select4 True, Nothing

              swSelMgr.SetSelectedObjectMark 1, 0, swSelectionMarkAction_e.swSelectionMarkSet

           

              skSeg.Select4 True, Nothing

              swSelMgr.SetSelectedObjectMark 2, 1, swSelectionMarkAction_e.swSelectionMarkSet

           

              swModel.FeatureManager.InsertRefPlane _

                  swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Coincident, 0, _

                  swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Perpendicular, 0, _

                  0, 0

           

          End Sub

          ______________________________________________

          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

           

          IC3DSteel – New Steel Solution for SolidWorks

          LinkedIn - SolidWorks API Group

            • Re: Create Plane
              Ar K

              Thank you ,

              But attached pic was an example !!

              I just know , i have a sketch which has some segments

              I do not know end segment is line or arc or spline !!

              this sketch draw by user !!!

              now i want create a normal plane in end of path of sketch.

            • Re: Create Plane
              Ar K

              Option Explicit

               

              Sub main()

               

              Dim swApp As Object

              Dim swModel As ModelDoc2

              Dim swPart As PartDoc

              Dim swSelMgr As SelectionMgr

              Dim swFeat As Feature

              Dim swSketch As Sketch

              Dim vSkContours() As Object

              Dim skContour As SketchContour

              Dim vSkSegments() As Object

              Dim skSegment As SketchSegment

              Dim skSegType As Long

              Dim swEndPt As SketchPoint

              Dim swSkLine As SketchLine

              Dim swSkArc As SketchArc

              Dim swSkSpline As SketchSpline

              Dim i, j As Integer

               

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Set swPart = swModel

              Set swFeat = swPart.FeatureByName("Sketch1")

              Set swSketch = swFeat.GetSpecificFeature2()

              '             or

              'Set swSketch = swModel.GetActiveSketch2()

              'Set swFeature = swSketch

               

              If Not swSketch Is Nothing Then

                         vSkContours = swSketch.GetSketchContours()

               

                          For i = LBound(vSkContours) To UBound(vSkContours)

               

                              Set skContour = vSkContours(i)

               

                              If Not skContour Is Nothing Then

               

                                  vSkSegments = skContour.GetSketchSegments()

                                  j = UBound(vSkSegments)

                                  Set skSegment = vSkSegments(j)

               

                                  If Not skSegment Is Nothing Then

               

                                      skSegType = skSegment.GetType()

               

                                      Select Case skSegType

               

                                          Case swSketchSegments_e.swSketchLINE

                                             Set swSkLine = skSegment

                                             Set swEndPt = swSkLine.GetEndPoint2()

                                             Call CreatePlane(swModel, swSelMgr, swEndPt, skSegment)

               

                                          Case swSketchSegments_e.swSketchARC

                                              Set swSkArc = skSegment

                                              Set swEndPt = swSkArc.GetEndPoint2()

                                             Call CreatePlane(swModel, swSelMgr, swEndPt, skSegment)

               

                                          Case swSketchSegments_e.swSketchSPLINE

                                              Set swSkSpline = skSegment

                                              Dim vPts() As Object

                                              vPts = swSkSpline.GetPoints2()

                                              Set swEndPt = vPts(UBound(vPts))

                                             Call CreatePlane(swModel, swSelMgr, swEndPt, skSegment)

               

                                          Case Else

               

                                      End Select

               

                                  End If

               

                              End If

               

                          Next i

               

                      End If

               

              End Sub

               

              Sub CreatePlane( _

                                           swModel As ModelDoc2, swSelMgr As SelectionMgr, _

                                           skPoint As SketchPoint, skSeg As SketchSegment)

               

                  swModel.ClearSelection2 True

               

                  skPoint.Select4 True, Nothing

                  swSelMgr.SetSelectedObjectMark 1, 0, swSelectionMarkAction_e.swSelectionMarkSet

               

                  skSeg.Select4 True, Nothing

                  swSelMgr.SetSelectedObjectMark 2, 1, swSelectionMarkAction_e.swSelectionMarkSet

               

                  swModel.FeatureManager.InsertRefPlane _

                       swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Coincident, 0, _

                       swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Perpendicular, 0, 0, 0

               

              End Sub

               

               

               

              With Special Thanks to Artem Taturevych :-)