Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Synchronizing (Placed) Tokens with Updated Ones

Hi all,  I was wondering if there's a script or macro that anybody has written that allows me to synch already placed tokens with new ones I've updated? I've already set the new tokens the default ones but having to go through the maps one by one seems like a nightmare of task right now. Any help appreciated! 
1611497202
The Aaron
Roll20 Production Team
API Scripter
If they represent a given character, you can change all of them by supplying a character id to the --ids argument of TokenMod: !token-mod --set (bunch of stuff) --ids @{selected|character_id} That will update all tokens for that character at once. 
1611508651

Edited 1611519970
The Aaron
Roll20 Production Team
API Scripter
Try this out. !sync-token Script: on('ready',()=>{ const syncProps=[ // graphic stuff 'isdrawing', 'flipv', 'fliph', 'tint_color', 'imgsrc', // Bars 'bar1_value', 'bar1_max', 'bar1_link', 'bar2_value', 'bar2_max', 'bar2_link', 'bar3_value', 'bar3_max', 'bar3_link', // auras 'aura1_radius', 'aura1_color', 'aura1_square', 'aura2_radius', 'aura2_color', 'aura2_square', // Permissions 'showplayers_name', 'playersedit_name', 'showplayers_bar1', 'showplayers_bar2', 'showplayers_bar3', 'playersedit_bar1', 'playersedit_bar2', 'playersedit_bar3', 'showplayers_aura1', 'showplayers_aura2', 'playersedit_aura1', 'playersedit_aura2', // Legacy Dynamic Lighting 'light_radius', 'light_dimradius', 'light_otherplayers', 'light_hassight', 'light_angle', 'light_losangle', // Updated Dynamic Lighting 'has_bright_light_vision', 'emits_bright_light', 'bright_light_distance', 'has_directional_bright_light', 'directional_bright_light_total', 'directional_bright_light_center', 'emits_low_light', 'low_light_distance', 'has_directional_low_light', 'directional_low_light_total', 'directional_low_light_center', 'has_limit_field_of_vision', 'limit_field_of_vision_center', 'limit_field_of_vision_total', 'has_night_vision', 'night_vision_tint', 'night_vision_distance', 'has_limit_field_of_night_vision', 'limit_field_of_night_vision_center', 'limit_field_of_night_vision_total' ]; const getCleanImgsrc = (imgsrc) => { let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; const simpleObj = (o) => JSON.parse(JSON.stringify(o)); const parseErrs = (err) => (err.length ? `<div><b>Errors:</b><ul>${err.map(e=>`<li>${e}</li>`).join('')}</ul></div>`: ''); const syncSiblings = (t) => { let c = getObj('character',t.get('represents')); let tokens = findObjs({ type: 'graphic', represents: c.id }).filter(o=>t.id !== o.id); let count = tokens.length; let s = (1 === count) ? '' : 's'; let src = simpleObj(t); let props = syncProps.reduce((m,p)=>({...m,[p]:src[p]}),{}); let err = []; if(props.hasOwnProperty('imgsrc')) { props.imgsrc=getCleanImgsrc(props.imgsrc); if(undefined === getCleanImgsrc(props['imgsrc'])){ delete props.imgsrc; err.push('Could not sync <code>imgsrc</code> from Marketplace.'); } } tokens.forEach(t=>t.set(props)); return `<div><code>${c.get('name')}</code>: ${count} token${s} synchronized.${parseErrs(err)}</div>`; }; on('chat:message',msg=>{ if('api'===msg.type && /^!sync-token(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let msgs = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .filter(g=>g.get('represents').length>0) .map(syncSiblings); sendChat('',`/w "${who}" ${msgs.join('')}`); } }); });
Hi Aaron,  I appreciate the quick feedback! I tried out the Sync-Token script and while I do get confirmation that things were synchronized, there doesn't appear to be any change in the artwork even after a refresh. I checked the API Output console and I did notice I got the error below after running !sync-token "ERROR: Please use the 'thumb' size for imgsrc properties." I'll give the TokenMod script a go and update you!  Thanks again!
1611519992
The Aaron
Roll20 Production Team
API Scripter
Ah, fixed that thumb issue in the above posted script.
Worked beautifully! Thank you so much!
1611524676
The Aaron
Roll20 Production Team
API Scripter
Sweet! =D