1 Reply Latest reply on Jun 3, 2015 3:52 PM by Keith Rice

    Traverse Faces in a Circular Pattern

    Dave Paul

      I would like to add an axis to all the holes in a circular pattern.  I have just about everything except for access to the individual faces of the features in the pattern.  Here is the code that I have so far.  I'm just stubbing up.

       

      Dim swApp As SldWorks.SldWorks
      Dim swCirPat As SldWorks.CircularPatternFeatureData
      Dim swModelDoc As SldWorks.ModelDoc2
      Dim swPartDoc As SldWorks.PartDoc
      Dim swFeat As SldWorks.Feature
      Dim bolStatus As Boolean
      Dim swInstance As Variant
      Dim intCount As Integer
      Dim intCountPatFace As Integer
      
      Sub main()
          Set swApp = Application.SldWorks
          Set swModelDoc = swApp.ActiveDoc
          Set swPartDoc = swModelDoc
          Set swFeat = swPartDoc.FeatureByName("CirPattern6")
          Set swCirPat = swFeat.GetDefinition
          bolStatus = swCirPat.AccessSelections(swModelDoc, Nothing)
          intCount = swCirPat.TotalInstances
         
          For i = 0 To (intCount - 1)
            Debug.Print "  Processing instance... " & (i + 1)
            bolStatus = swModel.Extension.SelectByID2("", "FACE", -0.282507498267705, 0.138969899029291, 4.17544183963798E-02, False, 0, Nothing, 0)
            bolStatus = swModel.InsertAxis2(True)
          Next
         
          swCirPat.ReleaseSelectionAccess
      End Sub
      

       

      Thank you - Dave

        • Re: Traverse Faces in a Circular Pattern
          Keith Rice

          Hi Dave,

           

          This is an interesting idea for a macro. First, I wouldn't recommend trying to modify the feature tree while a feature's selections are accessed, since the model is in a roll back state. Second, IModelDocExtension::SelectByID2 shouldn't be used to select faces, and I wouldn't recommend using to ever select anything that doesn't have a name (such as faces, edges, vertices, etc).

           

          The easiest way to tackle this would probably be to simply get the faces owned by the circular pattern feature, that way you can avoid accessing the feature data. This won't let you get the pattern seed faces, however, so you would need to select that feature as well. This macro will do that:

           

          Sub main()
              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swSelMgr As SldWorks.SelectionMgr
              Dim swFeat As SldWorks.Feature
              Dim swFace As SldWorks.Face2
              Dim swSurf As SldWorks.Surface
              Dim swEnt As SldWorks.Entity
              Dim vFaces As Variant
              Dim colSelFeats As New Collection
              Dim i As Integer, j As Integer
              
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSelMgr = swModel.SelectionManager
              
              For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
                  If TypeOf swSelMgr.GetSelectedObject6(i, -1) Is Feature Then
                      colSelFeats.Add swSelMgr.GetSelectedObject6(i, -1)
                  End If
              Next i
              
              swModel.ClearSelection2 True
              
              For i = 1 To colSelFeats.Count
                  Set swFeat = colSelFeats.Item(i)
                  vFaces = swFeat.GetFaces
                  If IsEmpty(vFaces) = False Then
                      For j = 0 To UBound(vFaces)
                          Set swFace = vFaces(j)
                          Set swSurf = swFace.GetSurface
                          If swSurf.IsCylinder Then
                              Set swEnt = vFaces(j)
                              swEnt.Select False
                              swModel.InsertAxis2 True
                          End If
                      Next j
                  End If
              Next i
              
          End Sub
          

           

          Keith

          SolidWorks API Training & Services