AnsweredAssumed Answered

How do I add a counter / repeat / while loop to repeat one step (add multiple lines to a table)??

Question asked by Patrick Malone on Nov 12, 2015
Latest reply on Nov 18, 2015 by Patrick Malone

This is another users code for adding a line to a table (BOM)

(Will have to look for the actual post to credit properly..)

 

At the bottom of the code is this line:

 

ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

 

I have simply copied the line the number of lines I want to add to my table.

Works just fine for my purposes!!

In desiring to learn more I was thinking that I would like to get the routine to ask me

how many lines I'd like to add to my table then have it repeat the above line (that one step) that many times...

 

I assume its a counter or a while loop.

This code works.

 

Hoping someone will have some mercy on me..

 

= = =

 

Option Explicit

Option Compare Text

 

Dim swApp As SldWorks.SldWorks

Dim Part As ModelDoc2

 

Sub main()

 

    Dim myTable As TableAnnotation

 

    Dim selMgr As SelectionMgr

 

    Dim i1 As Long

    Dim i2 As Long

    Dim i3 As Long

    Dim i4 As Long

    Dim ret As Boolean

 

    Set swApp = Application.SldWorks

 

    Set Part = swApp.ActiveDoc

 

    If Part Is Nothing Then Exit Sub

 

    If Part.GetType <> 3 Then Exit Sub

 

    Set selMgr = Part.SelectionManager

 

    If selMgr.GetSelectedObjectCount2(-1) <> 1 Then Exit Sub

 

    If selMgr.GetSelectedObjectType3(1, -1) <> swSelANNOTATIONTABLES Then Exit Sub

 

    Set myTable = selMgr.GetSelectedObject6(1, -1)

 

    myTable.GetCellRange i1, i2, i3, i4

 

 

'Copy following line for the Number of lines you want to add - 5 entries = 5 new lines to the table

' ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

 

     ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

    ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

    ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

    ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

    ret = myTable.InsertRow(swTableItemInsertPosition_Before, i1)

 

End Sub

 

 

 

Thanks in advance!

Outcomes