0

Is there a way to bulk search/replace a text string inserted by a plugin (for game development), within an object, across all objects, across all collections?

Example: Collection 1 ( .. 2, 3, 4... have about 20 of them)

  • Object 1
  • Object 2
  • Object 3 etc... 100's of them

Each object might have >= 0 of any combination of strings inserted like...

  • /foo/Hoo/Fix/This/Part/123
  • /foo/Hoo/Fix/This/Part/4
  • /foo/Hoo/Fix/This/Part/abc

(I do not have a list of all the possible strings)

Now I'd like to bulk edit all objects within all Collections by searching-case-matching for

  • /Fix/This/Part/

to be replaced with

  • /Fixed/

so the final outcome for all these string in all objects in all collections are changed to:

  • /foo/Hoo/Fixed/123
  • /foo/Hoo/Fixed/4
  • /foo/Hoo/Fixed/abc

Hoping there is a clever way to do this instead of me having to open each object and fix each of these strings one at a time ... and that's very risky too!

Thanks for the help!!

Blunder
  • 13,925
  • 4
  • 13
  • 36
Mark777
  • 115
  • 1
  • 9
  • 1
    Have you tried the Batch Rename (Ctrl+F2) operation? – Blunder Sep 08 '22 at 18:51
  • Looked at it, thank you , but this does not work for my need... I don't need to change the name of the objects (or other blender data types) but rather search and replace a string of data contained within each object. As mentioned: Each obj has string/s attached to it using a (gaming) plugin. I need to go deeper 1 level into each objects data. – Mark777 Sep 08 '22 at 22:39
  • Ok, I see. So where do you find this "data contained within each object" in Blender? Is it a custom property? If so, you will most likely need a script to change it for so many objects. – Blunder Sep 09 '22 at 00:12
  • "Is it a custom property?" -- I think the answer is yes. It comes from a plugin I installed for the game dev. The plug then becomes another option in the Properties window (Once installed it is added to the existing options like the existing transform, Collections, relations etc options) So when I then open the "GameDev" Option in the properties window, it then has a place for me to enter these strings -- which are unique to the game being developed. Thats what I need to search and replace. So If I need to write a script, what language must it be written in?? – Mark777 Sep 09 '22 at 02:50
  • Blender allows you to store Custom Properties almost everywhere. For example, you can add them to the scene, world, collections, objects, meshes, materials, etc. You can view them at the bottom of the Properties editor in the Custom Properties section. It is the last section at the bottom. If you see them there, you can change them easily with a Python script. Check out the Scripting workspace. E.g. enter C.active_object['my_custom_prop'] in the console (left side) & you will see the value of my_custom_prop – Blunder Sep 09 '22 at 07:54
  • Oh this is what I feared -- sounds like script writing is the answer -- of which Python I know nothing about. I had to learn 2 scripting languages to build my project, now another??!! dang. Is there a sample python find/replace script you know of that I can reuse please? – Mark777 Sep 09 '22 at 19:31
  • Oh this is what I feared -- sounds like script writing is the answer -- of which Python I know nothing about. I had to learn 2 scripting languages to build my project, now another??!! dang.

    Is there a sample python find/replace script you know of that I can reuse please? -- there are a number I found that read and replace things in text files, but this is not a test file issue. Specific to find/replace things in the properties window, do you know of a sample script anywhere that finds and replaces text in that are contained in the properties window (in a specific plugin) please?

    – Mark777 Sep 09 '22 at 19:45
  • Can you show an example or provide a test file? Here is an example how to loop over all selected objects. Then use the property name as an index (or better the .get() method to check if the property exists (see my previous comment above). If the value is not 'None' you can change it. Here is an example of the replace method https://www.w3schools.com/python/ref_string_replace.asp. Python also supports regex for more sophisticated find & replace operations. – Blunder Sep 10 '22 at 20:36
  • Thanks, looked over the links. Since my S&R is exactly the same for all places entered in all obj in all collections using the plugin named (for this example) "TheNameOfMyPlugin", could it be as simple as: import bpy context = bpy.TheNameOfMyPlugin txt.replace("/findThis/", "/ReplaceItWithThis/")

    Will that find/replace ALL instances of findThis? -- which is essentially the need. findThis is very unique to the whole project. Also, will this work in 1 collection only, or across all Collections of objects? I'll test this, but good to know if on right/wrong track?

    – Mark777 Sep 12 '22 at 17:47
  • Tried
     `import bpy.NameOf-Plugin
     context = DatarefPath
     for o in context.DatarefPath
     txt.replace("/foo/", "/Hex1234/")
    ` (Sorry none of the preformatting seems to be working) -- Errors follow in 2 parts -- too long to be put into one comment.. but its all the same error in the Script test window
    – Mark777 Sep 12 '22 at 18:56
  • Error
    `
     import bpy.NameOf-Plugin
     File "", line 1
     import bpy.NameOf-Plugin
     ^`
    – Mark777 Sep 12 '22 at 18:56
  • `SyntaxError: invalid syntax
     context = DatarefPath
    Traceback (most recent call last):
     File "", line 1, in 
    NameError: name 'DatarefPath' is not defined

     for o in context.DatarefPath
     File "", line 1
    for o in context.DatarefPath
     
    ^
    SyntaxError: invalid syntax
    `
    – Mark777 Sep 12 '22 at 18:57

0 Answers0