Batch "find/replace by" text in a plan folder

Hello everyone,

I have a folder with a lot of drawings and I would like to change part of a text (like M6x30 to M6x30 - 8.8) in notes.

I wanted to know if like in Word you can do a "find/replace by" on a drawing folder?

Macro, Mycadtool, ...

(I did a search on the forum but without success)

Thanks in advance

Hello

I don't know of any existing tools to do this but it is surely possible via a program that should automatically from a list of plans:

- Open the SLDDRW plan.

- Analyze all the notes in this plan.

- Modify the grade if = xxxxxxx.

- Save this plan.

- Move on to the next plan.

-etc...

Attached is a small example of a program, to be launched after starting SW and loading an SLDDRW plan. This program allows you to search for all the notes and all the dimensions present on a plane (not all tolerances though).

Kind regards


test-search.zip
2 Likes

Thank you d.roger!

I looked at your executable.

It works well for listing everything.

Two remarks:

  • Too bad we can't scroll some info was inaccessible at the bottom of the result window
  • We can't select the text

But especially for my application I would have to open all the plans (200) one by one. You might as well do it by hand with SW / tools / Search/modify.

I would have liked something more automatic, but I don't think it exists.

I'll have to get into VB.

Have a nice day

The macro recorder gives this

Dim swApp As Object

Dim Part As Object
Dim longstatus As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
'--------------------Find and Replace Annotations--------------------
Set swUtil = swApp.GetAddInObject("Utilities.UtilitiesApp")
Set swUtilFindReplaceAnnotations = swUtil.FindReplaceAnnotations
longstatus = swUtilFindReplaceAnnotations.InitPMPage()
'--------------------Block Recording--------------------
#If 0 Then
#End If
'--------------------UnBlock Recording------------------
swUtilFindReplaceAnnotations.FindText = "M6x30"
swUtilFindReplaceAnnotations.ReplaceText = "M6x30 - 8.8"
swUtilFindReplaceAnnotations.options = gtFraMatchCase Or gtFraWholeWord Or gtFraIncludeHiddenAnnotation
swUtilFindReplaceAnnotations.AnnotationFilter = gtFraAllTypes
Part.ClearSelection2 True
longstatus = swUtilFindReplaceAnnotations.ReplaceAll()
'--------------------Block Recording--------------------
#If 0 Then
#End If
'--------------------UnBlock Recording------------------
longstatus = swUtilFindReplaceAnnotations.Close()
End Sub

to see to put it in a program that loops on all the planes of a folder on the other hand I am bothered by the dialog box that appears at the end of the macro :/

1 Like

Hello

This program is just an example to search for the notes and dimensions of a shot, you have to automate the opening and closing of SLDDRWs, modify notes or dimensions automatically, trace the result in a log file, etc ....

Your need requires a bit of programming knowledge (vba, vb.net or C#) but is doable. To process 200 plans, this will represent a processing time of about 20 to 30 minutes in the end, but before that, it takes about 2 hours to write the program.

Kind regards

Here is already a function (in C#) to list all the notes of a clip and replace the value "M6x30" with "M6x30 - 8.8":

private void ListeAnnotations()
{

            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];
                        string valueNote = swNote. GetText();
                        string newValueNote = valueNote;
                        if (valueNote.Contains(M6x30))
                        {
                            newValueNote = newValueNote. Replace(M6x30, M6x30 - 8.8);
                            swNote. SetText(newValueNote);
                        }
                    }
                }
                swView = (SolidWorks.Interop.sldworks.View)swView. GetNextView();
            }

}

Kind regards

1 Like

Thank you for your feedback, and your involvement!

I'll look according to my meagre programming skills and my availability.

I'm more familiar with VB because I've done a lot of macro for Excel, for C++ I saw it at school in the 2000s, so I'm not up to date at all but it offers other possibilities.

I will be inspired by your code to make a choice.

Have a good weekend

Hello

Here is a program version that allows you to:

- Loading a CSV file containing the list of files to be analyzed, please note that this list must be formatted like the file liste.csv attached with the program.

- Open each file in Solidworks.

- Analyze all notes in each 2D file loaded.

- Replace the "Text to be modified" with the "New note text"

- Save the modified plan.

It is best to test on a small amount of 2D file copy to get started.

At the end of the processing, a résultat.csv file will be created in the executable folder indicating whether the files have been processed or misplaced.

As indicated when launching the program, it is imperative to make a backup of all the files to be processed before processing.

I don't like to create a backup function of SolidWorks files for other people because as an external person I feel that I don't have to intervene on them in modification mode but for the operation of this program I was a bit obliged to do so, so please work on copies of the files and not on the originals.

Kind regards


modif-notes.zip
1 Like

Thank you d.roger,

Unfortunately the restrictions of my organization no longer allow me to use executables (the first one passed but not the second)

So I'm going to go for VBA SW + task planner.

Hats off to the work! I'm sure it would have met 100% of my need

Have a nice day!

Otherwise there is the integration tool in mycadtools that you can install and launch on a folder, just modify the attached rule.

And for that, no programming skills are necessary.

Just change the condition here I put for all the outline type documents.

Then to change the operation here to replace the text of a note with another note. Note searched in attached rule M6x30 alt text M6x30 -8.8

And choice of leaves I chose all the leaves.

You can adapt it very simply and then apply this rule to a whole file, to a whole assembly or other according to your needs.

 


modification_de_note.mcact
1 Like