Need a macro to change a single character in a token name
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Need a macro to change a single character in a token name
I know the BoT has a macro that can fix bad alphanumeric characters in token names, but I have 3000 tokens that have a ; in the token name and the BoT is not currently configured to find and replace that particular character. I have asked Wolph42 for a possible feature to make that fix.
I don't know when/if Wolph42 will be able to provide that feature and I was hoping to fix my token names today since I don't have much spare time lately to fiddle with my MT stuff.
I'm hoping someone could provide me with a simple macro that will change any token names using a ; into a _ for any tokens I have selected on my token layer map. It would actually need to also remove the space after the ; but not any other spaces in the name. For example, "Human; Guy 1" to "Human_Guy 1".
I don't know when/if Wolph42 will be able to provide that feature and I was hoping to fix my token names today since I don't have much spare time lately to fiddle with my MT stuff.
I'm hoping someone could provide me with a simple macro that will change any token names using a ; into a _ for any tokens I have selected on my token layer map. It would actually need to also remove the space after the ; but not any other spaces in the name. For example, "Human; Guy 1" to "Human_Guy 1".
Re: Need a macro to change a single character in a token nam
Do you want to replace only selected tokens are all tokens on token layer?
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Need a macro to change a single character in a token nam
I suppose all tokens on the token layer would be better in case I missed some.aliasmask wrote:Do you want to replace only selected tokens are all tokens on token layer?
Re: Need a macro to change a single character in a token nam
Code: Select all
[H: allTokens = getTokens("json",json.set("{}","layer","TOKEN"))]
[H: numTokens = json.length(allTokens)]
[H: tokenSetSize = 1000]
[H: tokenSets = ceiling(numTokens / tokenSetSize)]
[H: counter = 0]
[H, c(tokenSets), code: {
[H: startSet = roll.count * tokenSetSize]
[H: theseTokens = json.get(allTokens,startSet,min(startSet+tokenSetSize,numTokens)-1)]
[H, foreach(id,theseTokens), code: {
[H: switchToken(id)]
[H, if(indexOf(token.name,";")+1): token.name = replace(token.name,"; *","_"); counter = counter + 1]
}]
}]
[H: counter = numTokens - counter]
[R: strformat("There were %{counter} tokens updated out of %{numTokens}.")]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Need a macro to change a single character in a token nam
As usual, not as fast as AM. But a response time of 6 hours (after getting the request at 3am in the morning aint bad...Oryan77 wrote:I don't know when/if Wolph42 will be able to provide that feature
I've just provided the new feature. And no its not so simple, there are many many factors to be taken into account.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: Need a macro to change a single character in a token nam
Yes, very fast response Wolph42. Sorry, I know you are on the other side of the world from me, so I usually assume you won't be able to work on anything until I'm sound asleep.
BTW aliasmask, I tried your code but get this message:
BTW aliasmask, I tried your code but get this message:
Code: Select all
Invalid end index "0" for array (size of 299) in function "json.end".
Re: Need a macro to change a single character in a token nam
I have to put a -1 with the json get because I want to get array places of 0 to 999 (or size of array), but I used the higher value of 1000 just like the way you get a substring. Code above updated.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Need a macro to change a single character in a token nam
There is a function avaliable to change the loop limit!
And IRC, the loop limit had changed:
Just created the wiki pages. Note that the limit is now (=1.4.0.2) 10,000
http://lmwcs.com/rptools/wiki/Category: ... ion_limits
And IRC, the loop limit had changed:
Just created the wiki pages. Note that the limit is now (=1.4.0.2) 10,000
http://lmwcs.com/rptools/wiki/Category: ... ion_limits
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: Need a macro to change a single character in a token nam
so with the loop limit out of the way you get:
Code: Select all
[H: allTokens = getTokens("json",json.set("{}","layer","TOKEN"))]
<!-- OR !! if you only want selected use this line-->
[H: allTokens = getSelected("json")]
[H, foreach(id,allTokens), code: {
[switchToken(id)]
[if(indexOf(token.name,";")+1): token.name = replace(token.name,"; *","_")]
}]
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: Need a macro to change a single character in a token nam
Thanks. This worked perfectly and all of my tokens appear to have working names now.