4 Replies Latest reply on May 19, 2015 10:51 AM by Bruce Perry

    What is the actual note position?

    Bruce Perry

      I have the following code below to delete some notes in a title block; then enter them in the way I like.

      The problem is that the note parameters or x, and y are not the same as the cursor location.


      Why are the two of these different?


      Or how should I be selecting the notes?


      Names doesn't seem to be the right path templates could change and therefore names would be



      Also this doesn't work correctly unless I zoom to the title block; if I'm zoomed to max it tries to pick

      other items, so I've added a zoom to keep it the same.


      For now this stuff works for me; but I just wanted to know why it was not working the way it was suppose

      to and what I wasn't doing right?


      'boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 0.7584, 0.035, 0, False, 0, Nothing, 0)


      'Below is the note location by way of actual note parameters?

      'boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 1.5917335, 0.1003577, 0, True, 0, Nothing, 0)

      'boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 1.5927487, 0.0870927, 0, True, 0, Nothing, 0)

      'boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 1.4875112, 0.0738931, 0, True, 0, Nothing, 0)

      'boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 1.5510261, 0.0363082, 0, True, 0, Nothing, 0)


      'Note deletion does not work correctly unless you are zoomed into that location?

      'The location is by way of the cursor coordiants at the bottom of the screen?

      Part.ViewZoomTo2 0.507227071708, 0.1274311707953, 0, 0.8862202398957, -0.002615504563233, 0

          'Title Line 1 'DetailItem79

      boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 0.7953007, 0.0471673, 0, True, 0, Nothing, 0)

          'Title Line 2 'DetailItem80

      boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 0.7953007, 0.0404415, 0, True, 0, Nothing, 0)

          'FIRST MADE FOR 'DetailItem81

      boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 0.7469443, 0.0354551, 0, True, 0, Nothing, 0)

          'Title Line 2 'DetailItem80

      boolStatus = Part.Extension.SelectByID2(Note, "NOTE", 0.7779063, 0.0166691, 0, True, 0, Nothing, 0)



      Part.ClearSelection2 True

        • Re: What is the actual note position?
          Simon Turner

          If you know the name of the note, use IView.GetFIrstNote and then INote.GetNext to loop through all the notes in the view.

          Then use GetAnnotation followed by Select3

          • Re: What is the actual note position?
            Keith Rice

            If you're trying to replace note text then you shouldn't delete the notes at all, you should get the pointer to the note and then INote::SetText to change the text. If you need to relocate the note, you can do this using IAnnotation::SetPosition. You can get the IAnnotation pointer for the note just INote::GetAnnotation.


            To find the notes initially, you can use the approach Simon provided or use IView::GetNotes, though the latter requires an understanding of how sheets can count as views so Simon's might be better if you're a beginner. As you traverse each note, test its text using INote::GetText until you've found the right note.


            IAnnotation::SetPosition treates the upper left corner of the note as the origin, by the way. You can position it according to a different corner or even the center by using INote::GetExtent and then doing some math.


            If you actually need to delete notes, then you should still traverse notes until you find notes with certain text (use INote::GetText) and then use IAnnotation::SelectX to select the note and IModelDoc2::EditDelete to delete it. This traversal has two benefits:


            1. It allows you to bypass the difficulties involved with IModelDocExtension::SelectByID2, which I don't personally recommend using for any item that isn't named or doesn't reside in the feature tree.

            2. It makes the macro more flexible, since the macro is no longer assuming a particular note location, which could possibly change from drawing to drawing.



            SolidWorks API Tutorials

              • Re: What is the actual note position?
                Bruce Perry

                I wanted to delete the actual note and add in other notes without getting into detail, what i'm doing is sound rather than just change the note. And I get that using the notes unique name would be the best way to tag it. What I don't understand is why there was three or four positions for the location of the note and I'm not talking about xyz. Cursor position was one, parameters was another, and when I zoomed in and out there were others? If I was to use selection what's the fixed point that always works?


                Thanks for the reply and when I go back into the code to modify it I will certainly come back to this for further review in making in better.

              • Re: What is the actual note position?
                Bruce Perry

                If anybody is interested I found a short piece of code to get the name of a note after you have selected it. Was there another way of getting the name I didn't see it anywhere. It's actual purpose was to change the name, but I only wanted to know what the name was? Select the note run the code and you get the name in a debug window or you can change it to a message box.


                Option Explicit

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swDrawing As SldWorks.DrawingDoc

                Dim swSelMgr As SldWorks.SelectionMgr

                Dim swNote As SldWorks.Note

                Dim swAnn As SldWorks.Annotation


                Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swSelMgr = swModel.SelectionManager

                Set swNote = swSelMgr.GetSelectedObject6(1, 0)

                Set swAnn = swNote.GetAnnotation

                Debug.Print swAnn.GetName


                ' New name must be unique

                'swAnn.SetName "@MYADDIN-ANN1"

                'MsgBox swAnn.GetName


                End Sub