AnsweredAssumed Answered

Adjusting sheet format with a macro

Question asked by John Boire on Nov 9, 2017
Latest reply on Nov 10, 2017 by John Boire

So here is my issue, I have a macro set up to go through sheets in a drawing and add document numbers to the sheets. (I want to make it difficult to do manually but easy to do when setting up a drawing the first time)


However when I try to edit the note I run into an issue,
I select the note as follows:

ret = swDwg.SelectByID("DetailItem1020@Sheet Format" & i + 1, "NOTE", 0.209024, 0.198179, 0)
Which works if the sheets are sequential and haven't been rearranged


However if this makes the document numbers follow the order in which the sheets were added to the drawing. So if I rearrange the sheets  from 1,2,3,4 to 1,3,4,2
The document numbers  would also get re-ordered


I tried putting a loop before the main loop that renames the note

For i = 0 To (SheetNum + (SheetNum / 2))


    If i <= SheetNum - 1 Then

        swDwg.ActivateSheet (SheetName(i))

        ret = swDwg.SelectByID("DetailItem1020@Sheet Format" & i + 1, "NOTE", 0.209024, 0.198179, 0)

            If ret = True Then

                Set selObj = selMgr.GetSelectedObject2(1)

                ret = selObj.SetName("DOC#")

            End If

    End If


Next i


This sets the document name to DOC# , but when I run a loop later to check if there is something called DOC# and to select it, it doesn't work.


For i = 0 To (SheetNum - 1)


               boolstatus = swModel.Extension.SelectByID2(SheetName(i), "SHEET", 0.2, 0.05, 0, False, 0, Nothing, 0)

                swDwg.ActivateSheet (SheetName(i))


                ret = swDwg.SelectByID("DOC#", "NOTE", 0, 0, 0)

                Debug.Print (ret)

                    'Check to make sure that an object was selected

                If ret = True Then

                'Gets the text note, which should be SldWorks.Note object

                    Set selObj = selMgr.GetSelectedObject2(1)

                'Call the SldWorks.Note.SetText method to change the text

                    ret = selObj.SetText("<FONT size=11PTS>" & PS(i))

                    swModel.ClearSelection2 True


               (A bunch of code that adds another 2 Notes)


I can't figure out why this doesn't work. Is there something I am missing?

I checked it and the reason is that it still needs the format part
So new question, is there any way to renumber the format?