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

[Help] Is it possible to create a page with the API?

1485246279

Edited 1485246358
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I'm trying to make a new page with a script. But I'm running into errors. Can we make new pages with the API? My problem is this line:  var newPageObj = createObj("page", { name: newPageName }); // **** Is creating pages even possible? Here's the whole thing. "use strict"; var makePage = function(newPageName) {     log("Entering makePage with " + newPageName);     // find pages named newPageName. If exist, abort         var currentPages = findObjs({                                       _type: "page",         name: newPageName     });     log(JSON.stringify(currentPages));          if ( Boolean(currentPages) === false || currentPages.length == 0 ) { // safe to make a new page         var newPageObj = createObj("page", { name: newPageName }); // **** Is creating pages even possible? // == "ERROR: Tried to create an invalid object type. See the API Documentation for valid types."         log("newPage: " + JSON.stringify(newPageObj));     } else {         log("Page already exists: " + newPageName);     }          log("Leaving makePage. Returning " + JSON.stringify(newPageObj) );     return newPageObj; } var handleInput = function(msg) {     if (msg.type == "api" && msg.content.indexOf("!newPage") !== -1 ) {         var argsFromUser = msg.content.split(/ +/);         makePage( argsFromUser[1] );         log("Making a page: " + argsFromUser[1]);     }     } on('chat:message', handleInput );
1485247185

Edited 1485247535
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Nevermind. Found the answer: No Note: currently you can create 'graphic', 'text', 'path', 'character', 'ability', 'attribute', 'handout', 'rollabletable', 'tableitem', and 'macro' objects. That's going to put a damper on my next project.
1485265087
The Aaron
Pro
API Scripter
Yeah, that is a bummer.  Maybe that's something that could be added.   Would also like to be able to create decks and cards. One thing you CAN do is have your script get ready to do the work (say, queue the page id or path id you want to copy from) and  watch for on('add:page',...), then turn the new page into the page you would have created. Here's a snippet I wrote a while back that watches for on('add:page',...) and then copies the settings in a page named MASTER to the new page: on('ready',function(){     var masterPage = findObjs({type: 'page', name: 'MASTER'})[0];     if(masterPage) {         on('add:page',function(p){             log('got create page');             p.set({         showgrid: masterPage.get('showgrid'),     showdarkness: masterPage.get('showdarkness'),     showlighting: masterPage.get('showlighting'),     lightupdatedrop: masterPage.get('lightupdatedrop'),     lightenforcelos: masterPage.get('lightenforcelos'),     lightrestrictmove: masterPage.get('lightrestrictmove'),     lightglobalillum: masterPage.get('lightglobalillum'),     width: masterPage.get('width'),     height: masterPage.get('height'),     snapping_increment: masterPage.get('snapping_increment'),     grid_opacity: masterPage.get('grid_opacity'),     fog_opacity: masterPage.get('fog_opacity'),     background_color: masterPage.get('background_color'),     gridcolor: masterPage.get('gridcolor'),     grid_type: masterPage.get('grid_type'),     scale_number: masterPage.get('scale_number'),     scale_units: masterPage.get('scale_units'),     gridlabels: masterPage.get('gridlabels'),     diagonaltype: masterPage.get('diagonaltype')             });         });     } else {         sendChat('MasterPage','/w gm No page named MASTER found.');     } });
1485269830
Ada L.
Marketplace Creator
Sheet Author
API Scripter
plexsoup said: Nevermind. Found the answer: No Note: currently you can create 'graphic', 'text', 'path', 'character', 'ability', 'attribute', 'handout', 'rollabletable', 'tableitem', and 'macro' objects. That's going to put a damper on my next project. Ah, cool! Isometric map generator! :D
1485275485
plexsoup
Marketplace Creator
Sheet Author
API Scripter
The Aaron said: One thing you CAN do is have your script get ready to do the work (say, queue the page id or path id you want to copy from) and  watch for on('add:page',...), then turn the new page into the page you would have created. That's a good idea. i kinda love the idea of hijacking every new page and populating it with a random dungeon they didn't ask for. Reminds me of good 'ol "Keep on the Borderlands" and the Caves of Chaos.
1485275620
The Aaron
Pro
API Scripter
HAHAHAHAHA! Now Plexsoup, with power comes responsibility...
1485276928
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Alternatively, you could create a macro button that transforms all map layer paths on the current page into isometric space.  With Path Math and Matrix Math, you can transform all the points of your path by creating a PathMath Path object from your path, then apply a transformation to it consisting of rotating it PI/4 radians and scaling it by the vector [1, 0.5, 0], then convert the PathMath Path object back into a Roll20 path. Creating the walls in your isometric map would be an extra post-processing step.
1485277338
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Thanks. I'll definitely want to use path math to raycast out those vertical walls. I might also want to implement a convex hull algorithm to do some dyson cross-hatches on the top-down version.
1485278131
Ada L.
Marketplace Creator
Sheet Author
API Scripter
I don't think I've heard the term "Dyson cross-hatches" before.
1485278545
The Aaron
Pro
API Scripter
Dyson cross-hatches: &nbsp;<a href="https://rpgcharacters.wordpress.com/2011/09/03/dungeon-doodles-a-crosshatching-tutorial/" rel="nofollow">https://rpgcharacters.wordpress.com/2011/09/03/dungeon-doodles-a-crosshatching-tutorial/</a>
1485279855
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Ah, ok.. I've seen those used before in D&D Adventurers League modules.&nbsp;
1485282362
The Aaron
Pro
API Scripter
It might be far easier and way more performant to: Set the background to a color, like white Only draw filled paths for your halls Tile a seamless transparent cross-hatch texture at the deepest level Calculate smooth paths for all your "empty" areas and draw them above the texture filled and stroked with the background color.
1485287539
plexsoup
Marketplace Creator
Sheet Author
API Scripter
That makes sense Aaron. No need for me to calculate inside and outside if I can just drop a texture behind.
1485290008
The Aaron
Pro
API Scripter
Right, and no need to populate the table with 10,000 short lines. =D