AnsweredAssumed Answered

Little help with HoleWizard API

Question asked by Mário Neto on Apr 4, 2018
Latest reply on May 15, 2018 by Mário Neto

Hello!

 

I'm trying to write a macro that makes a guiding hole in every end/start point of the bend lines in a sheet metal component. But i'm stuck with this code and can't make it.

 

   

Public Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swPartDoc As SldWorks.ModelDoc2

    Dim swFeature As SldWorks.Feature

    Dim swSubFeature As SldWorks.Feature

 

 

    Dim vSkSegArr As Variant

    Dim vSkSeg As Variant

    Dim swSkSeg  As SldWorks.SketchSegment

    Dim swSkLine As SldWorks.SketchLine

 

 

    Set swApp = Application.SldWorks

    Set swPartDoc = swApp.ActiveDoc

    

    Set swFeature = swPartDoc.FirstFeature

      

    While Not swFeature Is Nothing

           

        Select Case swFeature.GetTypeName2

            Case "FlatPattern"

                Set swSubFeature = swFeature.GetFirstSubFeature

                  

                While Not swSubFeature Is Nothing

                    If swSubFeature.Name Like "*Curva-Linhas*" Then

                        Dim swSketch As Sketch

                        Set swSketch = swSubFeature.GetSpecificFeature2

                        vSkSegArr = swSketch.GetSketchSegments

                        For Each vSkSeg In vSkSegArr

                            Set swSkSeg = vSkSeg

                            Select Case swSkSeg.GetType

                                Case swSketchLINE

                                    Set swSkLine = swSkSeg

                                    ProcessSketchLine swApp, swPartDoc, swSketch, swSkLine

                            End Select

                        Next vSkSeg

                    End If

                    Set swSubFeature = swSubFeature.GetNextSubFeature

                Wend

        End Select

        Set swFeature = swFeature.GetNextFeature()

    Wend

 

 

End Sub

 

 

Private Sub ProcessSketchLine(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swSketch As SldWorks.Sketch, swSkLine As SldWorks.SketchLine)

    Dim swStartPt As SldWorks.SketchPoint

    Dim swEndPt As SldWorks.SketchPoint

    Dim swStartModPt As SldWorks.MathPoint

    Dim swEndModPt As SldWorks.MathPoint

    Dim swFeatMgr               As SldWorks.FeatureManager

    Dim swFeat                  As SldWorks.Feature

    Dim swWizHole               As SldWorks.WizardHoleFeatureData2

   

         Set swFeatMgr = swModel.FeatureManager

      

 

    Set swStartPt = swSkLine.GetStartPoint2

    Set swEndPt = swSkLine.GetEndPoint2

   

Set swFeat = swFeatMgr.HoleWizard(swWzdHole, _

                    swStandardAnsiMetric, _

                    swStandardAnsiMetricSocketHeadCapScrew, _

                    "M2.0", _

                    swEndCondThroughAll, _

                    2, _

                    2, _

                    swStartPt, _

                    swEndPt, False, False, False, False, False, False, False, False, False, False)

End Sub

Outcomes