From: stefano (LIGHTWAVE)
This is a quick utlity script
It uses object name as the 'calculator input'
Simply name objects as you would normally do,
then append the price at end after ">"
Example:
"YourObjectName>16.15"
anything after ">" is counted.
1 object selected = 16.15
10 objects selected = 161.15
8 objects selected:
Seems to work...ok..if any bugs or new requests or suggestions please provide feedback.
Other:
You can also set currency symbol in the code, or if currency copied to clipboard
or not. I prefer to choose "false" so: 129.90
you can change to "true" if you want to get $129.90.
code:
// ObjectCosts.js
// Calculates total cost from selected object names.
// Naming syntax: Material description >20.50
// Example: "Polycarb Clear 2mm >20.50"
(function(){
var currency = "$";
var copyCurrencySymbolToClipboard = false;
function formatClipboardAmount( amount, currencySymbol, includeCurrencySymbol )
{
if ( includeCurrencySymbol )
return currencySymbol + amount;
return amount;
}
var objs = moi.geometryDatabase.getSelectedObjects();
var total = 0;
var found = 0;
for ( var i = 0; i < objs.length; ++i )
{
var name = objs.item(i).name;
var m = name.match(/> *([0-9]+(?:\.[0-9]{1,2})?)$/);
if ( m )
{
total += parseFloat(m[1]);
found++;
}
}
var amount = total.toFixed(2);
var clipboardText = formatClipboardAmount(
amount,
currency,
copyCurrencySymbolToClipboard
);
moi.copyTextToClipboard( clipboardText );
moi.ui.alert(
"Found prices on " + found + " object(s)\n\n" +
"Total = " + currency + amount + "\n\n" +
"Copied to clipboard: " + clipboardText
);
})();
This script should go into usual place; moi app data commands folder and/or be assigned to a shortcut key
You can also use command line typing: "Objectcosts"
Resources:
Install scripts
Assign shortcut keys via options/shortcuts Attachments:
ObjectCosts.js
Image Attachments:
ObjectsCost.jpg
From: Frenchy Pilou (PILOU)
About € against $ i suppose just to edit the file or it's more complicated ?
From: stefano (LIGHTWAVE)
hi pilou, yes that should work, let me know if it does not work as intented
or you want any other tweaks.. cheers stefano
From: Larry Fahnoe (FAHNOE)
This is a clever idea Stefano, thanks for sharing!
I've also appreciated your CommandPalette, though have only been using v1.20 as it met my needs.
--Larry
From: stefano (LIGHTWAVE)
cheers for the feedback Larry,
i also like the one off scripts, the other one im using (a lot) is the curvelengths one i posted
few weeks or so ago (i think). i'll likely do a better modal window one soon...
re: command palette glad you getting some use out of it.
cheers stefano