Global style and template change in patcher text editor

Bill Kleinsasser's icon

I am using Max8 with pre-existing (mostly Max 6) patches. Working to get an interface look that works well for me, without having to open all of my existing patches and subpatches to set the style and default templates one by one, I am using a text editor find/replace function to insert specific style and template definitions into existing older Max patches as text. I open the patch and save it in Max8, then I can successfully search and replace the style definitions in the text editor but when I open the patch the named style for the patch or subpatch is shown as "... (missing)" even though I am certain that the style exists in the styles folder in my User/.../Documents directory. If I then manually select the style in the patch from the library, it works fine. Any thoughts or better ideas for global style and template modifications in existing patches? Getting something to work would save countless hours of style updating. Thanks to all.

William Kleinsasser's icon

Also, is there a way to set "Show Grid" as the default in a style or template for all windows and subpatches of existing patches?

Bill Kleinsasser's icon

The answer to my second post is to open a Max8 patch in a text editor and "find /replace"

Find:
"gridonopen" : 1,
change all to:
"gridonopen" : 2,

I'm still hoping to get a fix for the "... (missing)" style problem from my first post above.

William Kleinsasser's icon

I'm also looking for a global approach to setting the JS Painter file for multiple objects in existing patches so that a border can be drawn around objects using the jsp.border.js script shared by SPA on Dec 17 2015 in the forums. Find/Replace in a text editor only seems to work if the object has already been given a JS Painter file definition in the inspector. I'm hoping that a more efficient solution can be found to save time updating many objects in existing patches and subpatches from previous versions.

Bill Kleinsasser's icon

I've been working on the problem of the "... (missing)" style issue described above. I've learned a bit more about the syntax of Max/MSP text code and I recognize now that each patch and subpatcher has a structure of code that includes the style declaration followed by lines of code defining each object then lines defining the connection wires then, at the end of the section, there are lines that define the styles called for at the top of the section.

Patcher header code ...

Declaration of the style name used in the block
Code defining each object
Code defining patch cables connecting the objects
*Code defining elements of the style names called for in the block

Declaration of the style name used in the block
Code defining each object
Code defining patch cables connecting the objects
*Code defining elements of the style names called for in the block

etc.

Here's an example of a block of section ending style definition code:

"name" : "WK classic",
                "default" :                 {
                    "patchlinecolor" : [ 0.345098, 0.345098, 0.345098, 1.0 ],
                    "bgfillcolor" :                     {
                        "type" : "color",
                        "color" : [ 0.9019607, 0.9019607, 0.9019607, 1.0 ],
                        "color1" : [ 0.996078, 0.984313, 0.984313, 1.0 ],
                        "color2" : [ 0.8, 0.8, 0.8, 1.0 ],
                        "angle" : 270.0,
                        "proportion" : 0.5,
                        "autogradient" : 0.0
                    }
,
                    "stripecolor" : [ 0.9019607, 0.9019607, 0.9019607, 1.0 ],
                    "accentcolor" : [ 0.9019607, 0.9019607, 0.9019607, 1.0 ],
                    "elementcolor" : [ 0.9019607, 0.9019607, 0.9019607, 1.0 ],
                    "bgcolor" : [ 0.9019607, 0.9019607, 0.9019607, 1.0 ],
                    "editing_bgcolor" : [ 0.879098, 0.948043, 0.899827, 1.0 ],
                    "locked_bgcolor" : [ 0.957613, 0.958892, 0.936557, 1.0 ],
                    "fontsize" : [ 9.0 ],
                    "color" : [ 0.0, 0.501960814, 1.0, 1.0 ],
                    "clearcolor" : [ 0.0, 0.0, 0.0, 0.0 ],
                    "selectioncolor" : [ 0.0, 0.501960814, 1.0, 1.0 ]
                }

So when I was finding and replacing just the style name at the top of the blocks, I had been missing the need to also insert the style defining block of code at the end of the patch or subpatch section. That's what the "... (missing)" error was referring to.

I'm working on a BBedit find/replace approach that can do this efficiently for many existing patches. It's pretty easy with single block patches by simply putting the defining code at the very end of the patch code text but if the patch has subpatches, then the end of each subpatch code section needs to be found and the style block and inserted or older unused style definitions deleted and replaced. I'll keep working on solutions in the hope that it might help others working to bring older patches into Max8 and look clean using the new "Light" color palette.

I'm woking with the BBedit tool, TextFactory, which can create a list of find/replace-all tasks and then run the script to change all of the iterations of all the tasks that need to be altered or inserted in the Max text code at once. This can also be run on multiple open files as a batch, which can make quick work of adding or altering JS Painter File definitions, bgcolor changes, style changes, etc. in the text code of patches.

Bill Kleinsasser's icon

One interesting thing I have noticed is in the Max inspector window, when you click on the pop-down menu to copy the floating point values of a color, the decimal precision is lower than what is actually in the text code for the patch for that object when you edit it in a text editor. This makes find/replace difficult. Any thoughts on that?

Timothy Place's icon

Hi Bill, I've logged this inspector precision problem in our internal issue tracker (ticket #12554). That's a definitely a bummer.

If you are using BBEdit then maybe there is a way to do something fancy for matching the values with a regular expression in your Find?

Bill Kleinsasser's icon

I have found a relatively easy way to change the style definitions for patches and subpatches in existing work when updating to Max 8. This approach solves the "... (missing)" problem of declaring the style but not having the style definition for each subpatch when editing in a text editor like BBedit. This procedure allows for quick modification of multiple max patches without the need to open each patch and suppatch and set the style manually, which can be very time consuming when updating a set of exitisting patches.

Below is the process I have learned. The process works for three levels deep of subpatches. That is, the style on the main patch level is changed when opening the old patch and saving it in Max 8, then this process below modifies the styles for two levels deep of subpatches from the main level. Presumably, the general approach can be extended to cover deeper levels of subpatches as needed by identifying the exact code to search for and replacing it with the style code. If anyone knows of a more efficient approach than this, I'd be eager to hear about it.

The first step is to open and save the pre-existing patch in Max8. This inserts the codes in the text that will be used below.

(The remaining steps involve using a text editor to find/replace code as as shown below. This inserts style definition lines in many places in the text code related to the subpatches in the code blocks.)

Open the patch file in a text editor.

Using Find/Replace All, set the search for:

]
                    }
,
                    "patching_rect" :

Set Replace All for the following (or any style name and definitions that are desired for subpatches)

],
        "styles" : [             {
                "name" : "WK classic",
                "textbutton" :                 {
                    "selectioncolor" : [ 0.070588235294118, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "color" : [ 0.16078431372549, 0.16078431372549, 0.16078431372549, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "default" :                 {
                    "selectioncolor" : [ 0.070588235294118, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "color" : [ 0.47843137254902, 0.486274509803922, 0.498039215686275, 1.0 ],
                    "patchlinecolor" : [ 0.407843137254902, 0.407843137254902, 0.407843137254902, 1.0 ],
                    "bgfillcolor" :                     {
                        "type" : "color",
                        "color1" : [ 0.917647058823529, 0.917647058823529, 0.92156862745098, 1.0 ],
                        "color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                        "color" : [ 0.847058823529412, 0.843137254901961, 0.843137254901961, 1.0 ],
                        "angle" : 270.0,
                        "proportion" : 0.39,
                        "autogradient" : 0.0
                    }
,
                    "lightcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ],
                    "elementcolor" : [ 0.901960784313726, 0.894117647058824, 0.894117647058824, 1.0 ],
                    "editing_bgcolor" : [ 0.870588235294118, 0.941176470588235, 0.890196078431372, 1.0 ],
                    "locked_bgcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ],
                    "clearcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 0.0 ]
                }
,
                "gswitch2" :                 {
                    "color" : [ 0.105882352941176, 0.105882352941176, 0.105882352941176, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "filtergraph~" :                 {
                    "color" : [ 0.231372549019608, 0.235294117647059, 0.231372549019608, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "nslider" :                 {
                    "color" : [ 0.0, 0.0, 0.0, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "gain~" :                 {
                    "color" : [ 0.47843137254902, 0.486274509803922, 0.498039215686275, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "dial" :                 {
                    "color" : [ 0.086274509803922, 0.086274509803922, 0.090196078431373, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "gswitch" :                 {
                    "color" : [ 0.066666666666667, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "zplane~" :                 {
                    "color" : [ 0.411764705882353, 0.423529411764706, 0.407843137254902, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "slider" :                 {
                    "color" : [ 0.423529411764706, 0.419607843137255, 0.419607843137255, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "message" :                 {
                    "bgfillcolor" :                     {
                        "type" : "color",
                        "color1" : [ 0.917647058823529, 0.917647058823529, 0.92156862745098, 1.0 ],
                        "color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                        "color" : [ 0.847058823529412, 0.843137254901961, 0.843137254901961, 1.0 ],
                        "angle" : 270.0,
                        "proportion" : 0.39,
                        "autogradient" : 0.0
                    }

                }
,
                "kslider" :                 {
                    "lightcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ]
                }
,
                "nodes" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "number~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "playlist~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "multislider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "led" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "toggle" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "levelmeter~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "waveform~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "number" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "ezadc~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "itable" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "radiogroup" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "matrixctrl" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "jit.fpsgui" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "spectroscope~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "newobj" :                 {
                    "bgcolor" : [ 0.96078431372549, 0.952941176470588, 0.952941176470588, 1.0 ]
                }
,
                "pictslider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "textedit" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "function" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "rslider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "ezdac~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "playbar" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "button" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "incdec" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "scope~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "tab" :                 {
                    "clearcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "parentstyle" : "",
                "multi" : 0
            }
]

                    }
,
                    "patching_rect" :

The two steps above will redefine the style in the first level deep of subpatches. Proceed with the steps below to alter the next level deep of subpatch styles (there must be a better way to do these levels all at once but this brute force approach at least works.

Do a second Find/Replace All process searching for the following text:

]
                                    }
,
                                    "patching_rect" :

And Replace All with the following, which is the same block of text as used in the steps above:

],
        "styles" : [             {
                "name" : "WK classic",
                "textbutton" :                 {
                    "selectioncolor" : [ 0.070588235294118, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "color" : [ 0.16078431372549, 0.16078431372549, 0.16078431372549, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "default" :                 {
                    "selectioncolor" : [ 0.070588235294118, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "color" : [ 0.47843137254902, 0.486274509803922, 0.498039215686275, 1.0 ],
                    "patchlinecolor" : [ 0.407843137254902, 0.407843137254902, 0.407843137254902, 1.0 ],
                    "bgfillcolor" :                     {
                        "type" : "color",
                        "color1" : [ 0.917647058823529, 0.917647058823529, 0.92156862745098, 1.0 ],
                        "color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                        "color" : [ 0.847058823529412, 0.843137254901961, 0.843137254901961, 1.0 ],
                        "angle" : 270.0,
                        "proportion" : 0.39,
                        "autogradient" : 0.0
                    }
,
                    "lightcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ],
                    "elementcolor" : [ 0.901960784313726, 0.894117647058824, 0.894117647058824, 1.0 ],
                    "editing_bgcolor" : [ 0.870588235294118, 0.941176470588235, 0.890196078431372, 1.0 ],
                    "locked_bgcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ],
                    "clearcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 0.0 ]
                }
,
                "gswitch2" :                 {
                    "color" : [ 0.105882352941176, 0.105882352941176, 0.105882352941176, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "filtergraph~" :                 {
                    "color" : [ 0.231372549019608, 0.235294117647059, 0.231372549019608, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "nslider" :                 {
                    "color" : [ 0.0, 0.0, 0.0, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "gain~" :                 {
                    "color" : [ 0.47843137254902, 0.486274509803922, 0.498039215686275, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "dial" :                 {
                    "color" : [ 0.086274509803922, 0.086274509803922, 0.090196078431373, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "gswitch" :                 {
                    "color" : [ 0.066666666666667, 0.070588235294118, 0.070588235294118, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "zplane~" :                 {
                    "color" : [ 0.411764705882353, 0.423529411764706, 0.407843137254902, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "slider" :                 {
                    "color" : [ 0.423529411764706, 0.419607843137255, 0.419607843137255, 1.0 ],
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "message" :                 {
                    "bgfillcolor" :                     {
                        "type" : "color",
                        "color1" : [ 0.917647058823529, 0.917647058823529, 0.92156862745098, 1.0 ],
                        "color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                        "color" : [ 0.847058823529412, 0.843137254901961, 0.843137254901961, 1.0 ],
                        "angle" : 270.0,
                        "proportion" : 0.39,
                        "autogradient" : 0.0
                    }

                }
,
                "kslider" :                 {
                    "lightcolor" : [ 0.996078431372549, 0.996078431372549, 0.996078431372549, 1.0 ]
                }
,
                "nodes" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "number~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "playlist~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "multislider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "led" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "toggle" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "levelmeter~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "waveform~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "number" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "ezadc~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "itable" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "radiogroup" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "matrixctrl" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "jit.fpsgui" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "spectroscope~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "newobj" :                 {
                    "bgcolor" : [ 0.96078431372549, 0.952941176470588, 0.952941176470588, 1.0 ]
                }
,
                "pictslider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "textedit" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "function" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "rslider" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "ezdac~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "playbar" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "button" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "incdec" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "scope~" :                 {
                    "bgcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "tab" :                 {
                    "clearcolor" : [ 0.976470588235294, 0.972549019607843, 0.972549019607843, 1.0 ]
                }
,
                "parentstyle" : "",
                "multi" : 0
            }
]

                    }
,
                    "patching_rect" :

Save the text file from the text editor and open it in Max8.

The patch should now have the style definitions in place for the subpatches as well as the top level. The whole process takes less than a minute for each patch and if the steps are built into a BBedit "Text Factory" macro, it can apply these changes to all files that are currently open in BBedit allowing for large batch updates all at once.

As I said, there must be more sophisticated approaches based on a better understanding of the Max text code syntax so if anyone can offer advice, it's welcome!

Hans Tutschku's icon

Hi Bill,
I'm in the same situation, searching for a workflow. I will look into your Bbedit batch process. Or have yo come across a more efficient way in the past 2 years?
Thanks, Hans