6 Replies Latest reply on Dec 17, 2014 4:35 AM by Yong Ning

    How to set CenterPoint of Sketch Arc

    Yong Ning

      How to set Point of Sketch Arc.jpg

      can get centerPoint → cArr = .GetCenterPoint

       

      But don't set CenterPoint.

       

      Help me.  picture x,y

        x → -103.389 change 22.5

         y →  103.317 change 22.5

      Thank you very much

       

       

      ******************************************

      Private Sub ll()

        Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

           Set SwApp = Application.SldWorks

           Set SwModel = SwApp.ActiveDoc

        Dim SwFeat As Feature, SwSketch As Sketch

           Set SwFeat = SwModel.FeatureByName("hSketch")

           Set SwSketch = SwFeat.GetSpecificFeature2

           Debug.Print SwFeat.Name

        Dim SwSeg As SketchSegment, SegArr, ii

           SegArr = SwSketch.GetSketchSegments

        Dim SwArc As SketchArc, cArr

           For ii = 0 To UBound(SegArr)

              Set SwSeg = SegArr(ii)

              Select Case SwSeg.GetType

                 Case 1

                    Set SwArc = SwSeg

                      With SwArc

                         cArr = .GetCenterPoint

                         cArr(0) = 45 / 2 / 1000

                         cArr(1) = cArr(0)

                         cArr(2) = 0

                         Stop

                         Debug.Print .GetRadius

                         .GetCenterPoint = cArr

                         cArr = .GetCenterPoint2

                         Stop

                      End With

              End Select

           Next ii

         

       

      End Sub

        • Re: How to set CenterPoint of Sketch Arc
          Daniel Andersson

          I would approach it by using dimensions (parameters).

           

          The you could use the IModelDoc2::SetParamValue method.

          http://help.solidworks.com/2014/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2~SetParamValue.html

           

          Or use the IDimension::SetSystemValue

           

          http://help.solidworks.com/2014/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IDimension~SetSystemValue3.html

           

          Both methods would require that you add dimensions in the sketch to the center of the arc.

          • Re: How to set CenterPoint of Sketch Arc
            Amirtharaj Vk

            Hi Yong:

             

            I slightly modified your code. Following code will resolve your problem.

            '---------------------

            Private Sub ll()

              Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                 Set SwApp = Application.SldWorks

                 Set SwModel = SwApp.ActiveDoc

              Dim SwFeat As Feature, SwSketch As Sketch

                 Set SwFeat = SwModel.FeatureByName("hSketch")

                 Set SwSketch = SwFeat.GetSpecificFeature2

                 Debug.Print SwFeat.Name

              Dim SwSeg As SketchSegment, SegArr, ii

                 SegArr = SwSketch.GetSketchSegments

              Dim SwArc As SketchArc, cArr

            Dim sktpt As SketchPoint

              Dim bool As Boolean

                 For ii = 0 To UBound(SegArr)

                    Set SwSeg = SegArr(ii)

                    Select Case SwSeg.GetType

                       Case 1

                          Set SwArc = SwSeg

                            With SwArc

                               'cArr = .GetCenterPoint

                               Set sktpt = .GetCenterPoint2

                               cArr(0) = 45 / 2 / 1000

                               cArr(1) = cArr(0)

                               cArr(2) = 0

                               Stop

                               Debug.Print .GetRadius

                               bool = sktpt.SetCoords(cArr(0), cArr(1), cArr(2))

                               Stop

                            End With

                    End Select

                 Next ii

               

             

            End Sub

            '---------------------

             

            Regards

            V K Amirtharaj

            EGS Computers India Pvt Ltd

            Dassault System SolidWorks Reseller

            Chennai | Tamilnadu | India

            http://www.egsindia.com/solidworks.html

            http://www.egs.co.in

            2 people found this helpful
              • Re: How to set CenterPoint of Sketch Arc
                Yong Ning

                thank you  reply

                Sorry , Mr Amirtharaj Vk, your code , not resolve my problem. see picture

                 

                0.jpg

                 

                My code See attach file.

                  • Re: How to set CenterPoint of Sketch Arc
                    Daniel Andersson

                    Are you  sure that the constraints in the sketch allows the position you want to set?

                    • Re: How to set CenterPoint of Sketch Arc
                      Daniel Andersson

                      You where missing IModelDoc2::EditSketch and ISketchManager::InsertSketch2

                      Sorry for rearranging you code a bit... just had to in order to get a better view of it.

                      Private Sub ll()

                      Dim SwApp As SldWorks.SldWorks
                      Dim SwModel As ModelDoc2
                      Dim swSketchMgr As SldWorks.SketchManager

                      Dim SwFeat As Feature
                      Dim SwSketch As Sketch

                      Dim cArr(2) As Double

                       

                      Set SwApp = Application.SldWorks
                      Set SwModel = SwApp.ActiveDoc
                      Set swSketchMgr = SwModel.SketchManager

                      Set SwFeat = SwModel.FeatureByName("hSketch")
                      Set SwSketch = SwFeat.GetSpecificFeature2

                       

                      SwFeat.Select2 True, 0
                      SwModel.EditSketch

                       

                      Debug.Print SwFeat.Name

                       

                      Dim SwSeg As SketchSegment, SegArr, ii

                       

                      SegArr = SwSketch.GetSketchSegments

                       

                      Dim SwArc As SketchArc
                      Dim sktpt As SketchPoint
                      Dim bool As Boolean

                       

                      For ii = 0 To UBound(SegArr)

                          Set SwSeg = SegArr(ii)

                          Select Case SwSeg.GetType
                             Case 1
                                Set SwArc = SwSeg
                                  With SwArc
                                     Set sktpt = .GetCenterPoint2
                                     cArr(0) = 45 / 2 / 1000
                                     cArr(1) = cArr(0)
                                     cArr(2) = 0
                                     Debug.Print .GetRadius
                                     bool = sktpt.SetCoords(cArr(0), cArr(1), cArr(2))
                                  End With
                          End Select

                         swSketchMgr.InsertSketch True
                      Next ii
                      End Sub

                      You should anyway consider that the sketch is not fully constrained which is recommended. You could add a fix constrain or add dimensions in order to have the sketch fully constrained.

                      1 person found this helpful