2 Replies Latest reply on Jan 28, 2015 6:44 PM by Yong Ning

    InsertCenterMark2→double Center Mark?

    Yong Ning

      Follow code run result is double center mark.

       

      0.jpg

      4

       

       

       

      Sub main()

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swSelMgr As SldWorks.SelectionMgr

      Dim swComp As SldWorks.Component2

      Dim swView As SldWorks.View

      Dim vComps As Variant

      Dim vEdges As Variant

       

          Set swApp = Application.SldWorks

          swApp.SetUserPreferenceToggle swUseEnglishLanguage, True

          'Stop

          Set swModel = swApp.ActiveDoc

          Set swSelMgr = swModel.SelectionManager

          Set swView = swSelMgr.GetSelectedObjectsDrawingView2(1, -1)

          swModel.ClearSelection2 True

          vComps = swView.GetVisibleComponents

          Dim i As Integer

          If False = IsEmpty(vComps) Then

              For i = 0 To UBound(vComps)

                  vEdges = swView.GetVisibleEntities(vComps(i), swViewEntityType_Edge)

                  If False = IsEmpty(vEdges) Then

                      Dim swSelData As SldWorks.SelectData

                      Dim j As Integer

                      Set swSelData = swSelMgr.CreateSelectData

                      swSelData.View = swView

                      For j = 0 To UBound(vEdges)

                          Dim swEnt As SldWorks.Entity

                          Dim swEdge As SldWorks.Edge

                          Dim swCurve As SldWorks.Curve

                          Set swEdge = vEdges(j)

                          Set swCurve = swEdge.GetCurve

                          If swCurve.IsCircle Then

                              Dim isClosed As Boolean

                              swCurve.GetEndParams 0, 0, isClosed, False

                              If isClosed Then

                                  Set swEnt = swEdge

                                  swEnt.Select4 True, swSelData

                              End If

                          End If

                      Next

                  End If

              Next

          End If

          ''

          Dim SwDraw As DrawingDoc, SwCenMark As CenterMark

             Set SwDraw = swModel

             Set CenterMark = SwDraw.InsertCenterMark2(swCenterMark_CircularGroup, True)

             'Stop

      End Sub

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

       

      run code result error ,is double center mark   see arrow

       

      2.jpg

       

       

       

       

      Hope run result see follow picture → single center mark.

       

       

       

       

      1.jpg

        • Re: InsertCenterMark2→double Center Mark?
          Raghvendra Bhargava

          HI Yong,

          Try this out..

           

          Dim swApp As SldWorks.SldWorks

          Dim Part As SldWorks.ModelDoc2

          Dim Draw As SldWorks.DrawingDoc

          Dim swActiveView As SldWorks.View

          Dim boolstatus As Boolean

          Option Explicit

           

           

          Sub main()

           

              Set swApp = Application.SldWorks

              Set Part = swApp.ActiveDoc

              Set Draw = Part

             

           

           

              Draw.ActivateSheet ("Sheet1")

             

              boolstatus = Draw.ActivateView("Drawing View10")

              Set swActiveView = Draw.ActiveDrawingView

              boolstatus = swActiveView.AutoInsertCenterMarks(1, _

                                                             2, _

                                                             False, _

                                                             False, _

                                                             True, _

                                                             0.0025, _

                                                             False, _

                                                             False, _

                                                             0)

             

           

           

          End Sub

           

          Please let me know if you have any doubt...

            • Re: InsertCenterMark2→double Center Mark?
              Yong Ning

              Thank your tips

               

              2012 SolidWorks API Help - Automatically Insert Center Marks Example (VBA)

              http://help.solidworks.com/2012/english/api/sldworksapi/auto_insert_center_marks_example_vb.htm

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

              2012 SolidWorks API Help - AutoInsertCenterMarks Method (IView)

              http://help.solidworks.com/2012/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.iview~autoinsertcentermarks.html

               

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

              change code is

              Function SelectEdge(SwModel As ModelDoc2, SwView As View, Xx, Yy, Ss, ii)

                   

                 Dim Pp(1)     

                    'Ss = SwView.Position     

                    Pp(0) = Ss(0) + Xx * SwView.ScaleDecimal / 1000

                    Pp(1) = Ss(1) + Yy * SwView.ScaleDecimal / 1000

                    ''

                    With SwModel.Extension

                       .SelectByID2 "", "EDGE", Pp(0), Pp(1), 0, True, ii, Nothing, 0

                    End With

              End Function

               

              Private Sub ll1()

                 Dim Pi, RadiusAngle, nn, Alfa

                    Pi = Atn(1) * 4

                    nn = 12

                    Alfa = 360 / nn

                    RadiusAngle = Alfa * Pi / 180

                    Debug.Print Round(RadiusAngle, 5)        

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwModel = SwApp.ActiveDoc

                    SwModel.ClearSelection2 True

                 Dim SwSelMgr As SelectionMgr

                    Set SwSelMgr = SwModel.SelectionManager

                 Dim SwDraw As DrawingDoc, SwView As View

                    Set SwDraw = SwModel

                 Dim SwFeat As Feature, Ss, Xx, Yy, Rr

                    Rr = 130 - 5     

                    Set SwFeat = SwDraw.FeatureByName("Drawing View10")

                    SwFeat.Select True

                    Set SwView = SwFeat.GetSpecificFeature2

                    Ss = SwView.Position

                    For ii = 0 To 12 - 1

                       Xx = Rr * Cos(ii * RadiusAngle)

                       Yy = Rr * Sin(ii * RadiusAngle)

                       SelectEdge SwModel, SwView, Xx, Yy, Ss, ii

                       'Stop

                    Next ii      ''

                    SelectEdge SwModel, SwView, 150, 0, Ss, ii

                  Dim SwCenMark As CenterMark

                     Set SwDraw = SwModel

                     Set CenterMark = SwDraw.InsertCenterMark2(swCenterMark_CircularGroup, True)

                    'Stop

              End Sub