This is a perfect example for using CREOSON. (Open Source Automation for Creo Parametric). So I am going to show you the code to do most of this using that. The example is in JavaScript - so you should be able to follow it. There is a JS Library in the latest distribution... and you can run the code from a browser or Node.js if you wanted to.
This is literally a modified version of the code that is in the CREOSON Playground (Web Page) .. so you can copy and paste this code in to the live editor in the CREOSON Playground and it should work with minimal modification for your use case.
// generic interface object used for STEP and IGES Exports.
let intObj = new creo.InterfaceObj();
function exportStep(itemName) {
intObj.type = 'STEP';
intObj.file = itemName;
return intObj.export_file();
}
function exportIges(itemName) {
intObj.type = 'IGES';
intObj.file = itemName;
return intObj.export_file();
}
function exportParasolid(itemName) {
let psldObj = new creo.InterfaceObj();
// EXAMPLE ONLY FOR MAPKEY
return;
let mapkeyText = '..bla bla bla..'
psldObj.script = mapkeyText;
return psldObj.mapkey()
.then(() => setTimeout(Promise.resolve(), 1000)); // delay 1 second
}
function exportStl(itemName) {
let stlObj = new creo.InterfaceObj();
// EXAMPLE ONLY FOR MAPKEY
return;
let mapkeyText = '..bla bla bla..'
stlObj.script = mapkeyText;
return stlObj.mapkey()
.then(() => setTimeout(Promise.resolve(), 1000)); // delay 1 second
}
function processItem(itemName) {
let fileObj = new creo.FileObj();
fileObj.display = true;
fileObj.activate = true;
fileObj.file = itemName;
return fileObj.open().then(() => {
return exportStep(itemName);
}).then(() => {
return exportIges(itemName);
}).then(() => {
return exportParasolid(itemName);
}).then(() => {
return exportStl(itemName);
});
}
function batchFiles () {
let creoObj = new creo.CreoObj();
let creosonUtilObj = new creo.CreosonUtils();
creoObj.filename = "*.prt"; // <<-- ENTER CREO FILE (*) and EXTENSION
creoObj.list_files()
.then(function (respObj) {
return creosonUtilObj.loopItems(respObj.filelist, processItem)
})
.then(function () {
alert("Finished Batching!");
})
.catch((err) => {
alert('ERROR: '+err);
});
}
// START THE BATCH PROCESS!
batchFiles();
The Mapkey portion of this is a bit tricker... mainly because of Creo and the type of exports you are wanting to do. -- BUT should be very possible.
THE TRICK - is to record a mapkey that starts from a known state and goes back to a known state. -- meaning record from before you want to start your export -- and end up back at where you started. Then save that to your config.pro. Find and retrieve that in a text editor - and remove all the extraneous info -- to get to the core Mapkey. NOTE: You have to be creative on the mapkey - especially when trying to select a CSYS for Parasolids Exports - Control-F and Control-A is your friend!
THEN it is just a matter of parameterizing that mapkey text in your script for the various things you want to do... e.g. file name to export as, CSYS to select, etc. A simple string substitution for text/variable - or alter the mapkey text into a variable inclusion as a string construction would be slick and easy.
OH - One problem with the Mapkey - you need a DELAY after execution so that you do not step on the next operation. Mapkeys run different than other functions - they do not return when finished...hence the need for a wait...
But I think with a bit of playing around -- you can get this to work very slick using CREOSON.
Hope that helps.
Dave