macroIO: batch import/export macros via copy & paste
Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
macroIO: batch import/export macros via copy & paste
Hiho,
i developed some tool to get all my macro code from a token quickly in my nice editor, work there with all the fancy features and then put it back to maptool. And i didnt want to do it macro per macro.
This has been vastly improved by aliasmask. So you should use his latest version called RPEdit
So i created this libtoken. It has 2 macro that you should copy in your cmpgn/global macros. Then select the token with the macros you want to export. Fire the export macro and a frame opens with your code. Each macro is denoted as "@@macroname".
After editing you select the target token (you should delete the macro before this or they all will be doubled - i sense a new feature here already) and fire the import macro. Paste your code into the frame and say import.
Note that this is limited to 1000 lines of code (and thats why its not helping me in my intended project) due to the "Infinite Loop detection" of maptool.
Not tested to the limits yet so handle with care and backup copies!
Important: check out the thread for newer versions. Now (10-13-10) it is v1.2 by aliasmask.
i developed some tool to get all my macro code from a token quickly in my nice editor, work there with all the fancy features and then put it back to maptool. And i didnt want to do it macro per macro.
This has been vastly improved by aliasmask. So you should use his latest version called RPEdit
So i created this libtoken. It has 2 macro that you should copy in your cmpgn/global macros. Then select the token with the macros you want to export. Fire the export macro and a frame opens with your code. Each macro is denoted as "@@macroname".
After editing you select the target token (you should delete the macro before this or they all will be doubled - i sense a new feature here already) and fire the import macro. Paste your code into the frame and say import.
Note that this is limited to 1000 lines of code (and thats why its not helping me in my intended project) due to the "Infinite Loop detection" of maptool.
Not tested to the limits yet so handle with care and backup copies!
Important: check out the thread for newer versions. Now (10-13-10) it is v1.2 by aliasmask.
Last edited by CoveredInFish on Wed Nov 10, 2010 3:31 am, edited 15 times in total.
Re: Batch Macro Import and Export via Copy&Paste
Ping me with a PM when you think this is ready to be moved into the Drop-In Resources subforum.
It seems like an interesting idea for editing all of a token's macros at once. The same thing can't be done with XML because of the entity conversions (yuck).
It seems like an interesting idea for editing all of a token's macros at once. The same thing can't be done with XML because of the entity conversions (yuck).
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Batch Macro Import and Export via Copy&Paste
Update
- fixed the appearing whitespaces
- groups are now stored
- macros are now deleted before they are (newly) created.
There may be characters in group or macro names that break my code. || for example is my new limiter between macro name and macro group.
No other macro props are exported (which are needed? maybe i better add them all by adding a props line like @@@(strPropList of props) or something like that).
All macros named like a imported label will be deleted. If there are two macros named the same the first one will probably get deleted as well...
- fixed the appearing whitespaces
- groups are now stored
- macros are now deleted before they are (newly) created.
There may be characters in group or macro names that break my code. || for example is my new limiter between macro name and macro group.
No other macro props are exported (which are needed? maybe i better add them all by adding a props line like @@@(strPropList of props) or something like that).
All macros named like a imported label will be deleted. If there are two macros named the same the first one will probably get deleted as well...
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Batch Macro Import and Export via Copy&Paste
UPDATE
- There is now created a line containing all the exportable macro props (begins with @PROP@). So all possible macro props are imported as well. Groups, colours, etc are now preserved.
Done.
- There is now created a line containing all the exportable macro props (begins with @PROP@). So all possible macro props are imported as well. Groups, colours, etc are now preserved.
Done.
Re: Batch Macro Import and Export via Copy&Paste
This is a great tool. I used it in your movpad campaign so I can go over your code (since you have a bazillion macros) and use my editors keyword search feature.
I may have to do all my future projects using a single file method. I haven't played around with it too much, but if you don't define a prop it will just be defaulted, right? Or will something break in processor? The only props I typically change are color, fontColor, group, index, tooltip where I leave the rest at their defaults except playerEditable which for lib token should always default to false (but it is true by default). That is something I would change when importing. If playerEditable is not defined, then default to false.
It would be nice if when exporting, it would output by group, then index. I'll take a look at your code and see if I can make those changes.
I love this tool.
edit: I just realized something. index is the internal index for macro, so for the sorting, I would sort by group then by sortBy which should be defaulted to 0 if no value is given.
I may have to do all my future projects using a single file method. I haven't played around with it too much, but if you don't define a prop it will just be defaulted, right? Or will something break in processor? The only props I typically change are color, fontColor, group, index, tooltip where I leave the rest at their defaults except playerEditable which for lib token should always default to false (but it is true by default). That is something I would change when importing. If playerEditable is not defined, then default to false.
It would be nice if when exporting, it would output by group, then index. I'll take a look at your code and see if I can make those changes.
I love this tool.
edit: I just realized something. index is the internal index for macro, so for the sorting, I would sort by group then by sortBy which should be defaulted to 0 if no value is given.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Batch Macro Import and Export via Copy&Paste
Glad you like it.
Code is quite easy, should be possible to find out where to make those changes. If props arent defined my code will go with the createMacro-defaults. Easy to make own choices about that i think.
Code is quite easy, should be possible to find out where to make those changes. If props arent defined my code will go with the createMacro-defaults. Easy to make own choices about that i think.
Re: Batch Macro Import and Export via Copy&Paste
Okay, here's the code I came up with. It will sort the export by group, sortBy, color (button) and label (macro name).
I was thinking of adding some options like having it resort the macro index, force setPlayerEditable to false, have different sort options and have button color sortBy preference. That would set the sortBy so the button colors are grouped and in a specific order. For the index resort, the panel would have to be cleared to avoid duplicates and other errors.
I was thinking of adding some options like having it resort the macro index, force setPlayerEditable to false, have different sort options and have button color sortBy preference. That would set the sortBy so the button colors are grouped and in a specific order. For the index resort, the panel would have to be cleared to avoid duplicates and other errors.
Import Code
Code: Select all
@@dumpMacros
@PROPS@autoExecute=true ; color=default ; fontColor=black ; group= ; includeLabel=false ; sortBy= ; index=1 ; fontSize=1.00em ; minWidth= ; playerEditable=false ; maxWidth= ; tooltip= ; applyToSelected=false ;
[h: switchToken(macro.args)]
[h: allMacros = getMacroGroups()]
[H: groupList = json.sort(json.fromList(json.fields(allMacros)),"a")]
[h: output = ""]
[h: newLine = "%0A"]
<!-- Could put an input menu here for sort method, redo macro index, setPlayerEditable to false -->
[H, foreach(iGroup,groupList), code: {
[H, if(json.isEmpty(iGroup)): iGroup = " "]
[H: gMacros = json.get(allMacros,iGroup)]
[H: gMacros = json.sort(gMacros,"a","sortBy","color","label")]
[H, foreach(iMacro,gMacros), code: {
[h: indexes = json.get(iMacro,"index")]
[h: props = getMacroProps(indexes, "json")]
[h: macroheader = "@@"+ json.get(props, "label")]
[h: macroProps = "@PROPS@" + deleteStrProp(getMacroProps(indexes), "label")]
[h: output = output + macroheader+newLine]
[h: output = output + macroProps+newLine]
[h: output = output + encode(json.get(props, "command")) + newLine]
[h: output = output + newLine]
}]
}]
[R, macro("showInFrame@Lib:cifMacroIO"): output]
@@getMacroGroups
@PROPS@autoExecute=true ; color=default ; fontColor=black ; group= ; includeLabel=false ; sortBy= ; index=8 ; fontSize=1.00em ; minWidth= ; playerEditable=false ; maxWidth= ; tooltip= ; applyToSelected=false ;
[H, if(!json.isEmpty(macro.args)): tokenId = json.get(macro.args,0); tokenId = currentToken()]
[H: assert(tokenId != "","getMacroGroups(tokenId)",0)]
[H: switchToken(tokenId)]
[H: allMacros = getMacros()]
[H: mGroups = "{}"]
[H, foreach(tMacro,allMacros), code: {
[H: mIndex = listGet(getMacroIndexes(tMacro),0)]
[H: varsFromStrProp(getMacroProps(mIndex))]
[H, if(sortBy == ""): sortBy = 0]
[H, if(json.isEmpty(group)): group = " "]
[H: mGroupArray = json.get(mGroups,group)]
[H, if(json.isEmpty(mGroupArray)): mGroupArray = "[]"]
[H: mGroupObject = json.set("{}","sortBy",sortBy,"index",index,"color",color,"label",label)]
[H: mGroupArray = json.append(mGroupArray,mGroupObject)]
[H: mGroups = json.set(mGroups,group,mGroupArray)]
}]
[H: macro.return = mGroups]
@@onCampaignLoad
@PROPS@autoExecute=true ; color=red ; fontColor=white ; group= ; includeLabel=false ; sortBy= ; index=9 ; fontSize=0.95em ; minWidth= ; playerEditable=false ; maxWidth= ; tooltip= ; applyToSelected=false ;
[H: defineFunction("getMacroGroups","getMacroGroups@this",1)]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Batch Macro Import and Export via Copy&Paste
I just noticed one thing about export though. The # entities are converted to the html equivalent rather than remaining their literal value.
For example, export the lib:cifMacroIO and look at processImport. You'll see a line that says:
and it should say:
I'll experiment and see what I come up with to fix that.
edit: I think this fixes it:
For example, export the lib:cifMacroIO and look at processImport. You'll see a line that says:
Code: Select all
[h: line = replace(line, ";", ";")]
Code: Select all
[h: line = replace(line, ";", ";")]
edit: I think this fixes it:
Code: Select all
@@showInFrame
[h: content = decode(macro.args)]
[h: content = replace(content, "&", "&")]
[h: content = replace(content, "<", "<")]
[h: content = replace(content, ">", ">")]
[r, frame("Exporter"): {
<html><head><title>Exporter</title></head>
<body>
<pre>
[r: content]
</pre>
</body>
</html>
}]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Batch Macro Import and Export via Copy&Paste
Thx for the patches. I just realized how convenient it is with this tool to share updates via the forum
Re: Batch Macro Import and Export via Copy&Paste
The one thing that doesn't work is if you use ; in your code. I tried to work around it, but ended up with other problems. So, it's best not to use the import part if you use that in your code. That, or just know that it will be converted to ";" after the import. I think a work around could be "&#"+59. This is a result of using the encode/decode functions.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Batch Macro Import and Export via Copy&Paste
Okay, I made a few changes to the lib. This was good practice for me. I plan on making a text editor for my spell reference lib for editing spells. The things I changed are:
For Importing: I put the Submit Query at the top and cleared the text in the query box. I didn't like having to scroll down and high lighting the text to delete before I put my text in. I changed the output to show each macro name and number of lines imported. You can now import an unlimited size text file. It breaks the macros up in to 500+ lines before writing and then will call itself to finish the other macro writes.
For exporting: If a button doesn't have a sort order, colored buttons will be given one and sorted together. playerEditable property is set to false. Fixed the html entities on output.
The only bug that can't be worked around is using ; ";". You can't have this text in your macro because it will be changed, when the query is submitted, to a semi-colon. That's just the way it is. I couldn't find any other entities it effected, so I think we're mostly safe. Like I said, if you have to use that string, just use "&#"+59 in its place and the importer won't mess it up.
edit: I added comment hiding and only 1 line of whitespace on import.
For Importing: I put the Submit Query at the top and cleared the text in the query box. I didn't like having to scroll down and high lighting the text to delete before I put my text in. I changed the output to show each macro name and number of lines imported. You can now import an unlimited size text file. It breaks the macros up in to 500+ lines before writing and then will call itself to finish the other macro writes.
For exporting: If a button doesn't have a sort order, colored buttons will be given one and sorted together. playerEditable property is set to false. Fixed the html entities on output.
The only bug that can't be worked around is using ; ";". You can't have this text in your macro because it will be changed, when the query is submitted, to a semi-colon. That's just the way it is. I couldn't find any other entities it effected, so I think we're mostly safe. Like I said, if you have to use that string, just use "&#"+59 in its place and the importer won't mess it up.
edit: I added comment hiding and only 1 line of whitespace on import.
- Attachments
-
- macroio.rptok
- (176.49 KiB) Downloaded 186 times
Last edited by aliasmask on Wed May 12, 2010 8:44 am, edited 1 time in total.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: Batch Macro Import and Export via Copy&Paste
I have to say again, wow... this is a great idea. Doing code changes is much easier and quicker now. The real power is being able to create new macros on the fly, that and breaking up my code in to smaller logical chunks. It's also nice having all the code on the same page. Now I just jump around using bookmarks or keyword search. I'm going to update my editor to high light @@macroname so it pops on my screen.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Full Bleed
- Demigod
- Posts: 4736
- Joined: Sun Feb 25, 2007 11:53 am
- Location: FL
Re: Batch Macro Import and Export via Copy&Paste
Nice work, guys.
And you guys should combine your versions of this drop-in into one with a version number so that people can be sure to have the latest version.
You're using Notepad++, right? You should update your thread on the config files to better support this.aliasmask wrote:I'm going to update my editor to high light @@macroname so it pops on my screen.
And you guys should combine your versions of this drop-in into one with a version number so that people can be sure to have the latest version.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."
Re: Batch Macro Import and Export via Copy&Paste
Will do on the Notepad++.. i just changed it a couple of hours ago.. sheesh. I was going to add more data for the auto complete before I do and that won't be until, the very soonest, next week. Yeah, I'm working on releasing a version 1.0 once I get the initial features fleshed out.. I still have some more coding to do (next week too). I'm running a game this Sunday and right now, I'm devoting time for that.Full Bleed wrote:Nice work, guys.
You're using Notepad++, right? You should update your thread on the config files to better support this.aliasmask wrote:I'm going to update my editor to high light @@macroname so it pops on my screen.
And you guys should combine your versions of this drop-in into one with a version number so that people can be sure to have the latest version.
edit: Forgot what thread I was on. I was talking about making a version for something else. This is all CoveredInFish's. I did make another tweak to my version though. When exporting, I put onCampaignLoad macro at the very top.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools