Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi All,
I'm quite new to customisation using web.link. I have a customisation that is very close to doing what I need, except that I cannot work out how to trigger a certain option. I have already worked out, from the documentation that the pfcModel.ExportIntf3D() instruction will use the default export profile for the export settings, which is OK. I can control this easily with our setup. However, when exporting manually there is the option "Customize Export", a check box in the "Save a Copy" dialogue box. If I use this, I can export my assembly with the origin point set to a coordinate system of my choosing. How can I either invoke this dialogue or set the origin of the export to an existing named coordinate system (e.g. "export_csys") in the assembly? Is this possible?
Solved! Go to Solution.
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
Have you tried a Mapkey with Variables in your code to initiate?
Dave
Thanks for this, I did think of using a mapkey for the whole lot, but it's a bit too involved for that. My requirement is to output all of the components (there are a variable number of them) as individual STEP, IGES, Parasolid and STL files, but with the origin for the parts all set at the point of the selected coordiante system. The idea is that you should be able to reassemble the parts by just placing them all at the origin.
I've got what I need working, with the sole exception of being able to choose an arbitrary coordinate system (or even a hard coded named system) for the origin of the output.
My code automatically names the files, which I can't see how I could do with a mapkey?
@Chris_Johnson wrote:
Thanks for this, I did think of using a mapkey for the whole lot, but it's a bit too involved for that. My requirement is to output all of the components (there are a variable number of them) as individual STEP, IGES, Parasolid and STL files, but with the origin for the parts all set at the point of the selected coordiante system. The idea is that you should be able to reassemble the parts by just placing them all at the origin.
I've got what I need working, with the sole exception of being able to choose an arbitrary coordinate system (or even a hard coded named system) for the origin of the output.
My code automatically names the files, which I can't see how I could do with a mapkey?
Hi,
I think you can create&load&play mapkey from your application. I am not sure if WEB.Link enables it. Other APIs are able to launch mapkey.
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
Thanks for this, Dave. I did some work down this path and got it mostly working, but I could never quite make it as slick as I wanted. There was quite a lot of work for the end users to do afterwards (creating folder structures, zipping the results, etc.) as well, which was more a limitation of the process running in a web browser (no direct access to the file system).
In the end, I used OTK Java Free (jlink) and got it all working very slickly with an extra button on the tools ribbon tab.
Chris