3 Replies Latest reply on Aug 29, 2016 8:57 AM by Amen Allah Jlili

    API - Chain pattern feature data

    Christopher Elyassi

      Hi all,


      I'm running SW Premium 2015 x64 SP 3.0 and I need a macro to modify the sketch used in a chain pattern.

      I'm not very experienced in writing macros for SolidWorks but I've managed to put this together by editing various forum posts.


      See code below (some irrelevant parts have been removed and I've censored the part/assembly names)

      When I try to run it I get the error "User-defined type not defined" at the line in bold below.

      After doing some digging it would seem that ChainPatternFeatureData is not available in SW 2015?

      Is there any way I can do this in SW 2015?






      Dim swApp As Object

      Dim Part As Object

      Dim boolstatus As Boolean


      Sub main()


      Set swApp = Application.SldWorks


      Set Part = swApp.ActiveDoc

      Dim myModelView As Object

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized


      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("XXXX@XXXX-1@XXXX/XXXX-1@XXXX", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)


      Dim swSelMgr As SldWorks.SelectionMgr

      Set swSelMgr = Part.SelectionManager


      Dim swFeature As SldWorks.Feature

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


      Dim swSketch As SldWorks.Sketch

      Set swSketch = swFeature.GetSpecificFeature2


      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("XXXX@XXXX", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

      Set swSelMgr = Part.SelectionManager

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

      Dim swChainPatt As SldWorks.ChainPatternFeatureData

      Set swChainPatt = swFeature.GetDefinition


      swChainPatt.AccessSelections Part, Nothing

      swChainPatt.Sketch = swSketch

      boolstatus = swFeature.ModifyDefinition(swChainPatt, Part, Nothing)


      End sub