macroIO: batch import/export macros via copy & paste

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Batch Macro Import and Export via Copy&Paste

Post by CoveredInFish »

aliasmask wrote:this is all CoveredInFish's.
You did some amazing tweaks to this tool i didnt even considered. :)


Btw ... i stress tested the import by trying it on the movepad-lib:token (2650 lines of code) and it didnt went through importing. Following error msg came.
I didnt tested yet to pump up my stack size.
maptool wrote:java.lang.IndexOutOfBoundsException: Index: 526, Size: 526 error executing expression tLine = json.get(tLines,maxLines).

EDIT: okay - as i hoped - setting the stack size to 6 helped. It went through nicely (took its time though).

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

That's odd. I ran the same lib through, you know as a test and I didn't get any errors and I only use a stack of 2. A stack of 6 seems pretty high to me. I'm not too sure about java, but I recall someone posting that anything above 1.6g max mem is outside the range of java.

Doing string manipulation inside of a nested loop can really overload the stack, especially when you nest the function calls. I'll take a look at the code again and separate anything like that out in to separate statements.

Also, that error seems to be related to calling an index of an array that doesn't exist. I'll check my logic and make do a test with some various end of file conditions. It may be a problem with my whitespace filter.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

Okay, I fixed the logic with the maxLines error. If I had 501 lines, it would change the maxLines to 501 and then try to read line 501 to see if it was the beginning of a macro... but line 501 is really 502.. hence the error. I don't know why it didn't error sooner or changing the stack would help, oh well.

I also broke apart a pretty stack intensive statement

Code: Select all

 [H, if(isCommentLine): tLine = replace(tLine,encode("<!--") + ".*?" + encode("-->"),encode(strformat("[H: '%s']",tTemp)))]

<!-- Changed to -->

[H, if(isCommentLine), code: {
   [H: tRegEx = encode("<!--") + ".*?" + encode("-->")]
   [H: rText = encode(strformat("[H: '%s']",tTemp))]
   [H: tLine = replace(tLine,tRegEx,rText)]
};{}]
edit: Actually, I do know why I didn't see the error before. It only would happen if the code block being transferred was over 500 lines and was the last code block. So, 900 lines would be split in to potentially 500 and 400.. no problem, but 1020 could be 500 and 520 if line 500 was in the middle of the macro. That's when the error would occur. I'm thinking changing the stack had nothing to do with it. The number or lines must have been changed or functions repositioned to avoid the above outcome.

So, I guess here is version 1a which includes my moving of onCampaignLoad to top of output:
Attachments
MacroIO_v1.0a.rptok
(177.72 KiB) Downloaded 130 times
Last edited by aliasmask on Sat May 15, 2010 10:24 am, edited 1 time in total.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Batch Macro Import and Export via Copy&Paste

Post by Azhrei »

Not to be too picky or anything (although I am, I guess!) but HTML comments must have spaces next to the dashes. So "<!--" is not an HTML comment lead-in, but "<!-- " is (notice the trailing space). Ditto for "-->" and " -->" (notice the leading space).

Not a big deal I suppose, but your current code would treat "<!---->" as a comment and technically it isn't. ;)

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

That is pretty picky, hehe. I suppose a comment should have content. I guess I would be accounting for ill-formed comments then, like the one at w3schools in their definition and example of comments.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Batch Macro Import and Export via Copy&Paste

Post by Azhrei »

aliasmask wrote:That is pretty picky, hehe.
Yepper. But I can tell from the macros you've posted that you're the type who would appreciate doing it The Right Way. ;)

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

I'm tempted to make the change because you're right, but I do use <!-----------> as a visual spacer sometimes and the whole point of putting the comment in a hidden tag is because maptool doesn't hide comments or visual spacers. So, that's why during a function that sometimes has output and sometimes doesn't will just post a blank giving away gm activities. So, putting the text string in a hidden maptool tag will just leave the whitespace which is trimmed and doesn't produce output. Well, in most cases with the exception of using execLink where it always outputs at least a blank even with no output when using the "all" parameter and [if:] statements with no false branch specified.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

I found something that is potentially a problem. I had the habit of copying the props from another macro when making a new macro not thinking about the "index" prop. Oops. I was wondering why my macros were disappearing. This can also happen if you export from one lib to another lib where one index will overwrite the other. So, I here is my change to fix that:

Code: Select all

@@createOrEditMacro
@PROPS@ autoExecute=true ; color=default ; fontColor=black ; group= ; includeLabel=false ; sortBy=0 ; index=7 ; fontSize=1.00em ; minWidth= ; playerEditable=false ; maxWidth= ; tooltip= ; applyToSelected=false ; 
[h: id = json.get( macro.args, "id" )]
[h: label = json.get(macro.args, "label")]
[h: switchToken(id)]
[h, if(label != ""), code: {
   [h, if( hasMacro(label) ), code: {
      [h, foreach(index, getMacroIndexes(label)): removeMacro(index)]
   };{}]
   [H: macro.args = json.remove(macro.args,"index")]
   [h: createMacro(macro.args)]
};{}] 
Basically, I just delete the index so a new one is created.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

I made a slight update, which includes the fix above.
  • Fixed import/export spacing. All white space will eventually be 1 line with multiple import exports.
  • Forced line break between macros.
  • Fixed loss of macros when the props index was the wrong number.
  • Macro names with commas won't break exporter.
Check the version before you download.

edit: Odd, I just noticed the size difference in 1.3b63. Anyway, newer version is a couple of posts down. It's compatible with 63 and above.
MacroIO_v1.0b.rptok
1.3b63
(337.47 KiB) Downloaded 117 times
MacroIO_v1.0b.rptok
1.3b68
(170.47 KiB) Downloaded 124 times
Last edited by aliasmask on Sun Jun 13, 2010 1:38 am, edited 4 times in total.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Batch Macro Import and Export via Copy&Paste

Post by Full Bleed »

aliasmask wrote:I made a slight update, which includes the fix above.
Thanks for the update, but I'm getting a very strange error when I try to drag that rptok onto my map:
Spoiler
java.lang.InstantiationError: java.util.Map$Entry
at sun.reflect.GeneratedSerializationConstructorAccessor149.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:62)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:124)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:66)
at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:63)
at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:54)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:789)
at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:138)
at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:123)
at net.rptools.maptool.util.PersistenceUtil.loadToken(PersistenceUtil.java:400)
at net.rptools.maptool.client.ui.assetpanel.ImageFileImagePanelModel.getTransferable(ImageFileImagePanelModel.java:98)
at net.rptools.maptool.client.ui.assetpanel.AssetPanel$3.getTransferable(AssetPanel.java:261)
at net.rptools.lib.swing.ImagePanel.dragGestureRecognized(ImagePanel.java:395)
at java.awt.dnd.DragGestureRecognizer.fireDragGestureRecognized(Unknown Source)
at sun.awt.windows.WMouseDragGestureRecognizer.mouseDragged(Unknown Source)
at java.awt.AWTEventMulticaster.mouseDragged(Unknown Source)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:24)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I'm not doing anything different than I normally would and can deploy the 1.0a rptok just fine the same way.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

Full Bleed wrote:
aliasmask wrote:I made a slight update, which includes the fix above.
Thanks for the update, but I'm getting a very strange error when I try to drag that rptok onto my map:
Spoiler
java.lang.InstantiationError: java.util.Map$Entry
at sun.reflect.GeneratedSerializationConstructorAccessor149.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:62)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:124)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:66)
at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:63)
at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:54)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:789)
at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:138)
at net.rptools.lib.io.PackedFile.getContent(PackedFile.java:123)
at net.rptools.maptool.util.PersistenceUtil.loadToken(PersistenceUtil.java:400)
at net.rptools.maptool.client.ui.assetpanel.ImageFileImagePanelModel.getTransferable(ImageFileImagePanelModel.java:98)
at net.rptools.maptool.client.ui.assetpanel.AssetPanel$3.getTransferable(AssetPanel.java:261)
at net.rptools.lib.swing.ImagePanel.dragGestureRecognized(ImagePanel.java:395)
at java.awt.dnd.DragGestureRecognizer.fireDragGestureRecognized(Unknown Source)
at sun.awt.windows.WMouseDragGestureRecognizer.mouseDragged(Unknown Source)
at java.awt.AWTEventMulticaster.mouseDragged(Unknown Source)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:24)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I'm not doing anything different than I normally would and can deploy the 1.0a rptok just fine the same way.
That might be because I created it in 1.3b68... I'll export the macros and create it in 1.3b63 after dinner and see how it works for you.

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Batch Macro Import and Export via Copy&Paste

Post by Raoden »

Question: Why does the dumpMacros macro need to use manual string concatenation instead of Wiki: strformat()? I believe that it does, because I've been trying to re-write it using strformat in hopes of it going faster, but that throws errors. I just wondered if someone who knows more about encode/decode can explain why.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

Raoden wrote:Question: Why does the dumpMacros macro need to use manual string concatenation instead of Wiki: strformat()? I believe that it does, because I've been trying to re-write it using strformat in hopes of it going faster, but that throws errors. I just wondered if someone who knows more about encode/decode can explain why.
Apparently [if:] doesn't like Wiki: strformat(). I don't know if this is any faster, but it takes about 6-7 seconds to output 2500 lines.

Here is the updated version:
Attachments
MacroIO_v1.0c.rptok
(177.78 KiB) Downloaded 123 times

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: Batch Macro Import and Export via Copy&Paste

Post by Raoden »

Cool. Also, what's the value of inserting [h:] around comment lines?
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Batch Macro Import and Export via Copy&Paste

Post by aliasmask »

No output, ie blank lines when you don't want them.

Post Reply

Return to “Drop-In Macro Resources”