Edit a Note on a Solidworks Basemap with a Macro

Hello, I would like to modify an already existing note in the basemap in order to change the font size

I tried the automatic macro recording but it doesn't work. I can only get the macro to work if I edit the background plan manually and launch it.

So how do you program the macro so that it goes to work directly on the basemap?

Hello

You only need to edit your basemap file (.slddrt) once and then reload it in each MEP.

See this example that does what you want: http://help.solidworks.com/2017/english/api/sldworksapi/modify_and_reload_sheet_format_template_example_vb.htm

3 Likes

To edit the basemap you have to use the EditTemplate method cf this example link http://help.solidworks.com/2016/english/api/sldworksapi/Place_Note_Behind_Drawing_Sheet_Example_VB.htm

1 Like

I had the same thing to do.

For a change of cartridge following an update of the ems basemaps.

 

I did as @Remrem says, I overwrote the old background plan with the new one and then each time I opened it, click on reload or with a macro as I did.

So for the macro, I didn't rack my brains:

-Macro recording starts

-right click on "sheet 1" click on reload then press OK

- Stop recording the macro and create an icon to launch it quickly.


fdp.jpg

Hello if it helps, below is a snippet of code that allows you to reload a basemap regardless of the initial format of the plan (limited to A4, A3, A2, A1). Only one click to be made once associated with a button.

Option Explicit
Public Enum swDocumentTypes_e
    swDocNONE = 0       ' Used to be TYPE_NONE

    swDocPART = 1       ' Used to be TYPE_PART

    swDocASSEMBLY = 2   ' Used to be TYPE_ASSEMBLY

    swDocDRAWING = 3    ' Used to be TYPE_DRAWING
End Enum

Dim swSheet         As SldWorks.Sheet
Dim swApp           As Object
Dim swModel         As SldWorks.ModelDoc2
Dim swDraw          As SldWorks.DrawingDoc
Dim swModelDocExt   As ModelDocExtension
Dim sTemplate       As String
Dim stemplatepath   As String
Dim Count           As Integer
Dim vSheetNameArr   As Variant
Dim vSheetName      As Variant
Dim vSheetProps     As Variant
Dim bRet            As Boolean


'Constantes
Const cDirTemplate = "..." 'Mettre le chemin d'accès aux fonds de plans sous ce format: C:\xxx\xxx\
Const cTemplateA4 = "A4.slddrt" 'A renommer si vos templates s'appelent autrement
Const cTemplateA3 = "A3.slddrt"
Const cTemplateA2 = "A2.slddrt"
Const cTemplateA1 = "A1.slddrt"


Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
    MsgBox ("Pas de document ouvert")
    Else
        If swModel.GetType <> 3 Then
            MsgBox ("Il ne s'agît pas d'une mise en plan")
        Else
        Set swDraw = swModel
                Set swModelDocExt = swModel.Extension
        vSheetNameArr = swDraw.GetSheetNames
                For Each vSheetName In vSheetNameArr
                        bRet = swDraw.ActivateSheet(vSheetName): Debug.Assert bRet
                        Set swSheet = swDraw.GetCurrentSheet
                        vSheetProps = swSheet.GetProperties
                        If vSheetProps(0) = "7" Then 'A4
                            stemplatepath = cDirTemplate & cTemplateA3
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "8" Then 'A3
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA3
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False) 'A2
                        ElseIf vSheetProps(0) = "9" Then
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA2
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "10" Then 'A1
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA1
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
            ElseIf vSheetProps(0) <> "7" Then 'Pour les formats un peu exotiques non gérés
                            If vSheetProps(0) <> "8" Then
                            If vSheetProps(0) <> "9" Then
                            If vSheetProps(0) <> "10" Then
                                MsgBox "Le fond de plan ne correspond à aucune trame connue" & vbCrLf & "Aucun changement appliqué"
                                Exit Sub
                            End If: End If: End If
                        End If
                    Next
    End If
End If
swModel.Save2 (True) 'Sauvegarde des changements
End Sub

 

1 Like

Cyril.f

for your macro, what does it do for the following questions, when you recharge an FDP:

"Rename existing blocks yes / no?"

"Attention of values in backgrounds of forced / modified plans?"

 

Hello

It does nothing but reload a basemap (by changing the format because simply reloading with the same slddrt filename does not work). If there are blocks in the basemap added later, they are deleted (you have to add more processing but not necessarily easy to write since it depends on the parameters of each one).

If there are forced things, you have to get the values back to reapply them.

So in conclusion, this bit of macro is simplistic and is only suitable for classic things (all fields mapped with a SW property and no specificity added in the background). I have a much more complex code but this one is specific to the needs of my company and I can't share it simply (very few comments and difficult to understand without knowledge of the SW API and vba).

I admit that my answer is next to the request and more in response to Bart who, I find, has a lot of custom buttons to do the same action.

So, to scan the notes of the basemap it's more this piece of code:

    Set swView = swDraw.GetFirstView 'Fond de plan
    Set swNote = swView.GetFirstNote
    swModel.ClearSelection2 (True)
    Do While Not swNote Is Nothing
        If swNote.GetName = "..." Then 'Trouver le nom de l'objet si tout le temps le même sinon utiliser swNote.GetText et jouer avec le contenu puis appliquer une mise en forme        
         End If
        Set swNote = swNote.GetNext
    Loop

 

1 Like

Hello

The following snippet of code changes the height of the text by multiplying it by 5 of all notes with text equal to TextNote. It's CSharp language, I'll let you translate it and adapt it to your needs.

SldWorks swApp;
DrawingDoc swDraw;
long j;
long count;
SolidWorks.Interop.sldworks.View swView;

swDraw = (DrawingDoc)swApp.ActiveDoc;

swView = (SolidWorks.Interop.sldworks.View)swDraw.GetFirstView();

while ((swView != null))
{
    count = swView.GetNoteCount();
    if (count > 0)
    {
        Object[] Notes = (Object[])swView.GetNotes();
        for (j = 0; j <= Notes.GetUpperBound(0); j++)
        {
            Note swNote;
            swNote = (Note)Notes[j];

            if (swNote.GetText() == "NoteText")
            {
                swNote.SetHeight(swNote.GetHeight() * 5);
            }
        }
    }
    swView = (SolidWorks.Interop.sldworks.View)swView.GetNextView();
}

swDraw.ForceRebuild();

Kind regards

Sometimes, it's easier to record your macro yourself rather than going through coding ;) =)

1 Like

☺ Bart I pretty much agree with you but it all depends on the size of the project that needs to be done, the above snippet of code is only a tiny part of a program that allowed me to take 48000 plans and now it's better to code a little.

Kind regards

1 Like

Oh, of course it all depends on the project to be dealt with.

 

Is the task recurrent or not?

I use it when I update my cartridges (logo modification etc...)

When I take an old shot with the old cartridge, I just have to click on the icon to bring everything up to date =)

 

Otherwise, MycadTools doesn't own this kind of thing?

Cyril.f , when you put (by changing format because the simple reload by the same slddrt filename doesn't work), you can try to reload the format by putting the same line twice because indeed in one go it doesn't work, here is what I had to do on my equivalent program (but in c#):

We reload the format (in 2 steps otherwise it doesn't work)
bool boolstatus = false;
boolstatus = swDraw. SetupSheet5(sheetName, (int)PaperSize, (int)TemplateIn, Scale1, Scale2, true, file2, width, top, "Default", true);
boolstatus = swDraw. SetupSheet5(sheetName, (int)PaperSize, (int)TemplateIn, Scale1, Scale2, true, file1, width, top, "Default", true);

Kind regards

2 Likes

Hello

First of all, thank you for all your answers which helped me a lot because I'm not very good at VBA programming^^'

This macro is intended to work on a batch of 700 shots currently but I would like it to be reusable in the future.

 I looked with Mycadtool/Integration which should manage the launch of my macros but I can't find any action related to the software that allows me to change the font size.

Currently, I can program loops that count the number of sheets and then the number of views. However, when I try to repeat the operation for the notes, it doesn't work.

 


capture.jpg

It seems that you need to call getnotescount before

http://help.solidworks.com/2016/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.ISketchBlockDefinition~GetNoteCount.html

 

EDIT see also http://help.solidworks.com/2016/english/api/sldworksapi/get_views_and_notes_example_vb.htm

Hello

If multiple sheets then you need 1 loop on the sheets which includes 1 loop on the views which includes 1 loop on the notes which includes changing the pitch of the note text. See the attached file to see what it looks like in C# for example.           

Kind regards


exemple_modif_ht_texte_note.txt
1 Like

However I don't really understand the difference in vba of annotation and note

Does annotation correspond to the programming of the tab?

because I feel like I have to say that I'm going to look for an annotation and then a note :/

 

Good evening

A Note is a subtype of Annotation, see http://help.solidworks.com/2013/English/api/sldworksapi/Get_Annotation_Object_Example_VB.htm for test macro.

Kind regards

For i = 0 TB UBound(vSheets)                                                'loop sheet
        vViews = vSheets(i)
       
        For j = 1 TB UBound(vViews)                                             'loop view
        Set swView = vViews(j)


        vNote = swView.GetNotes
        vAnnotation = swView.GetAnnotations
           
                For k = 0 TB UBound(vNote)                                      'loop on the notes
                Set swNote = vNote(k)


                Next
               
                For c = 0 TB UBound(vAnnotation)
                Set swAnnotation = vAnnotation(c)
               
                Next