Hi Andrea,
Sorry about the delay. I had a look at it last weekend but for some reason, the code I imagined would work simply did not.
But I think I found the culprit. Reading a brush name during an [IKeyPress,…] did not work for me. Adding a slight delay solved the problem.
So, the following code will flip the wrap mode according to the wrap mode of the currently selected brush. Any brushes that you hardcode will also need a variable to define which type of brush they are. The standard modelling, smoothing and masking brushes are supported but not the clip and selection brushes. I took those out as I tried to narrow down the problem, besides, they do not seem to be affected by the wrap mode setting.
You still cannot hold any modifier keys while pressing the plugin button or the plugin might fail. Not sure what to do about that as the previous modifier key detection solution does not seem to work anymore.
Edit: I just noticed copy / pasting the code does not preserve the indentation. So here is the file:
[IConfig, 4.5]
[ISubPalette, “Zplugin:Brush WrapMode”]
[VarSet, brushCount, 4]
// brushes() defines the pathname and brushType() defines what type of brush it is.
// 0: standard modeling brush.
// 1: smooth brush.
// 2: masking brush.
[VarDef, brushes(brushCount), “”] [VarDef, brushType(brushCount), 0]
[VarSet, brushes(0), “Brush:Clay”] [VarSet, brushType(0), 0]
[VarSet, brushes(1), “Brush:Standard”] [VarSet, brushType(1), 0]
[VarSet, brushes(2), “Brush:Smooth”] [VarSet, brushType(2), 1]
[VarSet, brushes(3), “Brush:MaskPen”] [VarSet, brushType(3), 2]
[IButton, “ZPlugin:Brush WrapMode:Flip WrapModes”, “Flip WrapModes.”,[IFreeze, // Stops interface updates while we switch brushes.
// Store the currently selected modeling brush.
[VarSet, currentBrush, [IGet, 30516]] // 30516 is the Brush slider.
// Determine the new WrapMode
[If, [IGet, “Brush:Curve:WrapMode”], // WrapMode is 1 or higher.
[VarSet, newWrapMode, 0]
,
[VarSet, newWrapMode, 1]
]
// Set the new WrapMode for the currently selected brush.
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
// Store the currently selected smooth brush.
[IKeyPress, SHIFT,
[Delay, 0.05] // Apparently needed to read the brushName.
[VarSet, brushName, [IGetTitle, 30516]]
[VarSet, smoothPath, [StrMerge, “Brush:”, brushName]]
// Remove the . and space from the path.
[VarSet, smoothPath, [StrExtract, smoothPath, 0, [StrLength, smoothPath] - 2]]
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
]
// Store the currenlty selected masking brush.
[IKeyPress, CTRL,
[Delay, 0.05] // Apparently needed to read the brushName.
[VarSet, brushName, [IGetTitle, 30516]]
[VarSet, maskPath, [StrMerge, “Brush:”, brushName]]
// Remove the . and space from the path.
[VarSet, maskPath, [StrExtract, maskPath, 0, [StrLength, maskPath] - 2]]
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
]
// Then set WrapMode for the hardcoded brushes.
[Loop, brushCount,
// Checks if the interface path name or UI ID exists.
[If, [IExists, brushes(index)],
[If, brushType(index) == 0,
[IPress, brushes(index)]
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
[LoopContinue] // No need to check for other brushType().
]
[If, brushType(index) == 1,
[IKeyPress, SHIFT,
[IPress, brushes(index)]
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
]
[LoopContinue] // No need to check for other brushType().
]
[If, brushType(index) == 2,
[IKeyPress, CTRL,
[IPress, brushes(index)]
[ISet, “Brush:Curve:WrapMode”, newWrapMode]
]
]
]
, index]
// Restore the previously selected smooth, mask and modeling brushes.
[IKeyPress, SHIFT,
[IPress, smoothPath]
]
[IKeyPress, CTRL,
[IPress, maskPath]
]
[ISet, 30516, currentBrush]
] // End of IFreeze
, /DISABLED ?/, /BUTTON WIDTH/, , /BUTTON ICON/, /BUTTON HEIGHT/]