9 Replies Latest reply on Jan 22, 2015 7:06 PM by Yong Ning

    Insert Hole Table

    Yateen Shembade

      I am trying to create a Macro to insert a HoleTable in a drawing view.

      Can any one tell me if there is a way to insert a hole table by just selecting a vertex in the view.

      Api will select all the faces i that view and insert a hole table using selected vertes and faces.

       

       

      Set swView = swSelMgr.GetSelectedObjectsDrawingView2(1, -1)

      Set swHoleTable = swView.InsertHoleTable2(False, 0.011, 0.545, swBOMConfigurationAnchor_TopLeft, "A", "C:\Program Files\SolidWorks 2012\SolidWorks\lang\english\standard hole table--letters.sldholtbt")

        • Re: Insert Hole Table
          Artem Taturevych

          Yes, use the View::GetVisibleEntities method. Refer the following example in API Help Documentation that will help you:

           

          Get All Edges in Visible Component in Drawing View (VBA)

          Get Visible Components and Entities in Drawing View (VBA)

           

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: Insert Hole Table
              Yateen Shembade

              Artem

               

              Thank you for your reply. However I wasn't able to get holetable through that method.

              I am not sure what I am doing wrong.

              Presently, I am selecting a point in a view and running my macro.

              It puts the origin at that point, but does not select any face in that view.

              I am not very sure what I am doing wrong.

              This is my code:

               

              Sub main()

              Set swApp = Application.SldWorks

              Set swDrawModel = swApp.ActiveDoc

              Set swModelDocExt = swDrawModel.Extension

              Set swSelMgr = swDrawModel.SelectionManager

              Set swView = swDrawModel.GetFirstView

              Set swView = swView.GetNextView

              Set swView = swSelMgr.GetSelectedObject5(1)

              Set swHoleTable = swView.InsertHoleTable2(False, 0.011, 0.545, swBOMConfigurationAnchor_TopLeft, "A", "C:\Program Files\SolidWorks 2012\SolidWorks (2)\lang\english\standard hole table--letters.sldholtbt")

                • Re: Insert Hole Table
                  Artem Taturevych

                  Please find the attached sample. It will create a hole table for the all faces within view of preselected vertex. The vertex will used as origin.

                  ______________________

                  Regards,

                  Artem Taturevych

                  Application Engineer at Intercad

                  http://intercad.com.au/

                  Tel: +61 2 9454 4444

                    • Re: Insert Hole Table
                      Yateen Shembade

                      I am using this macro for a while now.

                      Recently I realized, this macro is selecting counter bore hole as an another surface.

                      I am seeing two callouts for the same counter bore hole.

                        • Re: Insert Hole Table
                          Artem Taturevych

                          Can you post the sample picture and file? I'm not sure what do you mean.

                           

                          ______________________

                          Regards,

                          Artem Taturevych

                          Application Engineer at Intercad

                          http://intercad.com.au/

                          Tel: +61 2 9454 4444

                          • Re: Insert Hole Table
                            Keith Rice

                            Yateen,

                             

                            The reason you are getting two callouts for a counterbore hole is that a counterbore creates a new face in the part that is picked up by IView::GetVisibleEntities. Since Artem's macro is creating a hole tag for hole wizard holes associated with EVERY face, the counterbore hole is tagged twice---once for the "main" face and once for the face created by the counterbore.

                             

                            So what you can do is add, within the second For-Next loop, a conditional statement testing whether that face belongs to a hole wizard feature.  Here is a version of the macro similar to what Artem provided that includes that conditional. Please change the BOM template path to the appropriate path on your computer:

                             

                            ========

                             

                            Const BOM_TEMPLATE_PATH = "C:\Program Files\SolidWorks 2012\SolidWorks\lang\english\standard hole table--letters.sldholtbt"

                            Dim swApp As SldWorks.SldWorks

                            Dim swModel As SldWorks.ModelDoc2

                            Dim swSelMgr As SldWorks.SelectionMgr

                            Dim swVertex As SldWorks.Vertex

                            Dim swEnt As SldWorks.Entity

                            Dim swFace As SldWorks.Face2

                            Dim swView As SldWorks.View

                            Dim swFeat As SldWorks.Feature

                            Dim swHoleTable As SldWorks.HoleTableAnnotation

                            Dim swHoleTableFeat As SldWorks.HoleTable

                            Dim swSelData As SldWorks.SelectData

                            Dim vVisibleComps As Variant

                            Dim vFaces As Variant

                            Dim i As Integer

                            Dim j As Integer

                             

                            Sub main()

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                                Set swSelMgr = swModel.SelectionManager

                                Set swSelData = swSelMgr.CreateSelectData

                             

                                Set swView = swSelMgr.GetSelectedObjectsDrawingView2(1, -1)

                                Set swVertex = swSelMgr.GetSelectedObject6(2, -1)

                                Set swEnt = swVertex

                             

                                vVisibleComps = swView.GetVisibleComponents

                                swSelData.Mark = 1

                                swEnt.Select4 False, swSelData

                             

                                For i = 0 To UBound(vVisibleComps)

                                    vFaces = swView.GetVisibleEntities(vVisibleComps(i), swViewEntityType_Face)

                                    For j = 0 To UBound(vFaces)

                                        'Determine if the face was created by the hole wizard; if it is then ignore it, otherwise mark it

                                        Set swFace = vFaces(j)

                                        Set swFeat = swFace.GetFeature

                                        If swFeat.GetTypeName2 <> "HoleWzd" Then

                                            Set swEnt = vFaces(j)

                                            swSelData.Mark = 2

                                            swEnt.Select4 True, swSelData

                                        End If

                                    Next

                                Next

                             

                                swView.InsertHoleTable2 False, 0, 0, swBOMConfigurationAnchor_BottomLeft, "A", BOM_TEMPLATE_PATH

                            End Sub

                             

                            ========

                             

                            By the way, I also noticed that if you leave the last argument of IView::InsertHoleTable2 empty (a zero-length string), then the first hole tag is "1" and not "A1". This is corrected, I found, by actually specifying the hole table template path.

                             

                            Hope that helps.

                             

                            Keith

                            Video Tutorials for the SolidWorks API

                              • Re: Insert Hole Table
                                Yong Ning

                                Why don't insert Hole Table?

                                 

                                '--------------------------------------

                                '

                                ' Preconditions:

                                '         (1) Drawing is open.

                                '         (2) A view in the open drawing is selected.

                                '

                                ' Postconditions: A hole table is inserted in the drawing at the point where the

                                '         view was selected.

                                '

                                '--------------------------------------

                                Option Explicit

                                Public Enum swBOMConfigurationAnchorType_e

                                    swBOMConfigurationAnchor_TopLeft = 1

                                    swBOMConfigurationAnchor_TopRight = 2

                                    swBOMConfigurationAnchor_BottomLeft = 3

                                    swBOMConfigurationAnchor_BottomRight = 4

                                End Enum

                                Sub main()

                                    Dim swApp                   As SldWorks.SldWorks

                                    Dim swModel                 As SldWorks.ModelDoc2

                                    Dim swSelMgr                As SldWorks.SelectionMgr

                                    Dim swView                  As SldWorks.View

                                    Dim swHoleTable             As SldWorks.HoleTableAnnotation

                                    Dim swTable                 As SldWorks.TableAnnotation

                                    Dim swAnn                   As SldWorks.Annotation

                                    Dim vPickPt                 As Variant

                                    Dim nNumCol                 As Long

                                    Dim nNumRow                 As Long

                                    Dim sRowStr                 As String

                                    Dim i                       As Long

                                    Dim j                       As Long

                                    Dim bRet                    As Boolean

                                 

                                    Set swApp = Application.SldWorks

                                    Set swModel = swApp.ActiveDoc

                                    Set swSelMgr = swModel.SelectionManager

                                    Set swView = swSelMgr.GetSelectedObject5(1)

                                 

                                    vPickPt = swSelMgr.GetSelectionPoint(1)

                                    Stop

                                      

                                    ' View::InsertHoleTable

                                    '   datum     --> 1

                                    '   X axis    --> 4

                                    '   Y axis    --> 8

                                    '   hole      --> 2

                                    '"C:\Program Files\SolidWorks\lang\chinese-simplified\hole table--tags combined--numbers.sldholtbt"

                                    'View.InsertHoleTable 0, 0.150505, 0.114403, 1, "C:\Program Files\SolidWorks\lang\chinese-simplified\hole table--tags combined--numbers.sldholtbt"

                                 

                                 

                                    'Set swHoleTable = swView.InsertHoleTable( _

                                                        False, _

                                                        vPickPt(0), vPickPt(1), _

                                                        swBOMConfigurationAnchor_TopLeft, _

                                                        ""): Debug.Assert Not swHoleTable Is Nothing

                                    Set swHoleTable = swView.InsertHoleTable(0, 0.15, 0.1, 1, "C:\Program Files\SolidWorks\lang\chinese-simplified\hole table--tags combined--numbers.sldholtbt")

                                    Set swTable = swHoleTable

                                    Set swAnn = swTable.GetAnnotation

                                 

                                    nNumCol = swTable.ColumnCount

                                    nNumRow = swTable.RowCount

                                 

                                    ' List table contents

                                    For i = 0 To nNumRow - 1

                                        sRowStr = ""

                                        For j = 0 To nNumCol - 1

                                            sRowStr = sRowStr & swTable.Text(i, j) & ","

                                        Next j

                                        Debug.Print Left(sRowStr, Len(sRowStr) - 1)

                                    Next i

                                End Sub

                                '--------------------------------------