Open adamdiestelkamp opened 7 years ago
Yep, find and replace in symbol overrides would be a huge win!
Do you have any advice to do this? I try to find some documentation about text in symbols overrides to do it !
Please share your knowledge about this feature. I am ready to Fork.
I'd love this feature as well.
@thierryc The best discussion I've seen about accessing and changing text within symbols is on the Sketch Developers discussion board.
How to get and set overrides ? Do you know any plugins working with symbols and overrides?
@thierryc I'm not aware of any plugins that work with symbols and overrides. :(
I'm not very familiar with javascript, but in that same discussion a user shared this code. It might help with working with overrides.
// HACKY
function nsArrayToArray(nsArray) {
var result = [];
for(var i = 0; i < nsArray.count(); i++) {
result[i] = nsArray.objectAtIndex(i);
}
return result;
}
function fieldsForInstance(symbolInstance) {
var master = symbolInstance.symbolMaster();
return nsArrayToArray(master.children());
}
function setSymbolOverride(instance, fieldName, value) {
log('updating override ' + fieldName +' with: ' + value);
var existingOverrides = instance.overrides() || NSDictionary.dictionary();
var values = NSMutableDictionary.dictionary();
if (existingOverrides.objectForKey(0)){
var existingValues = existingOverrides.objectForKey(0);
values = NSMutableDictionary.dictionaryWithDictionary(existingValues)
}
var field = fieldsForInstance(instance).find(function(f){ return f.name() == fieldName; });
values.setObject_forKey(value, field.objectID());
var overrideValuesWrapper = NSMutableDictionary.dictionary();
overrideValuesWrapper.setObject_forKey(values, 0);
instance.applyOverrides_allSymbols(overrideValuesWrapper, false);
}
var instance = context.selection[0];
setSymbolOverride(instance, 'title', 'New Title set by plugin')
If it doesn't, take a look at the entire discussion thread.
http://sketchplugins.com/d/154-applyoverrides-allsymbols-depreciated-in-43/20
@thierryc I'm still trying to figure out how to write plugins. If you have any problems, I'd recommend asking questions on the Sketch Plugins discussion board. There's lots of friendly and helpful developers on there.
Thank You Sean. Let me figure out.
I also start a discussion "Set and get Symbol Overrides" in sketchplugins.com. http://sketchplugins.com/d/224-set-and-get-symbol-overrides
I push a pull request https://github.com/mscodemonkey/Sketch-Find-And-Replace/pull/28
Try it; https://github.com/anotherplanet-io/Sketch-Find-And-Replace
@thierryc Wow! That was quick. Great job!
I tested a simple document and it worked great, but had problems on a more complicated document.
I've added a bug report on your pull request. https://github.com/mscodemonkey/Sketch-Find-And-Replace/pull/28
Thank you ! I Try to fix it today.
I fix it ! @seandellis Do you confirm ? Please try it !
Hurray! This is fantastic!
That fixed it. Thanks so much @thierryc !
Done!
has this made it into the master?
sorry for the question. it does work. I had regexp support selected and a string with parentheses :P
Do you have an example of your 2 strings ?
This is a great plugin, would love to see it expanded to be able to include the text in symbol overrides also.