AnsweredAssumed Answered

Macro - Locating Circular Pattern Instances

Question asked by Dave Paul on Jul 17, 2017
Latest reply on Jul 20, 2017 by Dave Paul

I'm not good at transforms - and I'm making an assumption using the "Get Transform for Each Circular Pattern Instance" example.

With that example code I want to expand on it and locate all the instances in the circular pattern.  Here is what I have so far.

It is inserting the right number of points (to represent the location of the holes), but the location is not correct.  Thank you for your help.

 

  Dim swCirPatternData As SldWorks.CircularPatternFeatureData
  Dim swMathTransform As SldWorks.MathTransform
  
  Set swApp = Application.SldWorks
  Set swModel = swApp.ActiveDoc
  Set swSelMgr = swModel.SelectionManager
  
  boolstatus = swModel.Extension.SelectByID2("CirPattern1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)
  Set swFeat = swSelMgr.GetSelectedObject5(1)
  
  Set swCirPatternData = swFeat.GetDefinition
  
  ' Get the transform for each instance
  ' in the circular-pattern feature
  Dim NbrInstances As Long
  NbrInstances = swCirPatternData.TotalInstances
  swModel.Insert3DSketch2 False
  For i = 0 To (NbrInstances - 1)
    Debug.Print "  Processing instance... " & (i + 1)
    Set swMathTransform = swCirPatternData.GetTransform(i)
    Debug.Print "Pattern Instances: (" & -1# * swMathTransform.ArrayData(0) * 1000# & ", " _
      & -1# * swMathTransform.ArrayData(1) * 1000# & ", " _
      & -1# * swMathTransform.ArrayData(2) * 1000# & ") mm"
    swModel.SetAddToDB True
    Set swIntSkPt = swModel.CreatePoint2(swMathTransform.ArrayData(0), swMathTransform.ArrayData(1), swMathTransform.ArrayData(2))
    swModel.SetAddToDB False
  Next
  swModel.Insert3DSketch2 True

Outcomes