2 Replies Latest reply on Dec 17, 2014 2:51 AM by Huang Huan

    why doesn't my API program modify the sketch-driven pattern?

    Huang Huan

      Hello, everyone. I wrote an Excel Macro to change the reference sketch used in sketch-driven pattern from one skech to another. But my program does not modify the feature. Does anybody know why? Thank you.

       

      I have attached the solidworks document and the Excel macro.  The content of the Excel macro is as follows:

       

       

      Option Explicit

       

      Public Function update_model()

       

          Application.DisplayAlerts = False
         

          ' connect to solidworks. Solidworks part is already open.
          Dim swApp As SldWorks.SldWorks
          Set swApp = CreateObject("SldWorks.Application")
          swApp.Visible = True
          Dim swPart As SldWorks.PartDoc
          Set swPart = swApp.ActiveDoc
         
          ' modify sketch-driven pattern
          swPart.ClearSelection2 True
          Dim boolstatus As Boolean
          boolstatus = swPart.Extension.SelectByID2("new_sketch", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
          Dim swSelMgr As SldWorks.SelectionMgr
          Set swSelMgr = swPart.SelectionManager
          Dim swFeature As SldWorks.Feature
          Set swFeature = swSelMgr.GetSelectedObject6(1, -1)
          Dim swSketch As SldWorks.Sketch
          Set swSketch = swFeature.GetSpecificFeature2
          swPart.ClearSelection2 True
          boolstatus = swPart.Extension.SelectByID2("Sketch-Pattern", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
          Set swSelMgr = swPart.SelectionManager
          Set swFeature = swSelMgr.GetSelectedObject6(1, -1)
          Dim swSketchPatt As SldWorks.SketchPatternFeatureData
          Set swSketchPatt = swFeature.GetDefinition
          swSketchPatt.Sketch = swSketch
          boolstatus = swFeature.ModifyDefinition(swSketchPatt, swPart, Nothing)                  ' strange, it seems that this sentence is not effective.
         
         
          Set swApp = Nothing
        
         
      End Function