Hi @YannickB833 and @Jacob Bugge, this is a new topic for me so forgive me if I am going over old ground. I wrote a quick function getItemArea to attempt to do this.
I have tested on some basic cases (see attached sample file) but I am guessing by your post that it is more complicated than I can see. You can specify the units as 'mm', 'cm', 'inch' or 'pt' (default).
One complicated example I did find was that a compoundPath may be malformed quite easily: if you create a compoundPath out of grouped compoundPaths (for example if you outline text and then, without ungrouping, create compoundPath of it—as I did in the attached sample doc) then it will have zero pathItems. The script makes an attempt to fix this—but see caveats in script listing.
@YannickB833, please let me know how it works in your case, and post example .ai file that shows unexpected result.
- Mark

// make a selection first and run script
(function () {
// choose unit: pt, mm, cm, inch
const unit = 'mm';
if (
app.documents.length == 0
|| app.activeDocument.selection.length == 0
) {
alert('Please select a page item and try again.');
return;
}
var doc = app.activeDocument,
item = doc.selection[0],
itemArea = getItemArea(item, unit);
if (itemArea > 0)
alert('selected item area = ' + itemArea + '\u00A0sq.\u00A0' + unit + '.');
else
alert('Did not calculate area for this item.');
/**
* Returns area of a PathItem or CompoundPathItem.
* @author m1b
* @version 2022-08-02
* @discussion https://community.adobe.com/t5/illustrator-discussions/calcul-d-aires-complexe-dans-illustrator/m-p/13106830
* @param {PageItem} item - an Illustrator PathItem or CompoundPathItem.
* @param {String} unit - 'pt', 'mm', 'cm', 'inch'.
* @returns {Number} - the item area in square points.
*/
function getItemArea(item, unit) {
unit = {
mm: 2.834645,
cm: 28.34645,
inch: 72,
pt: 1
}[unit || 'pt'];
var itemArea = 0;
if (item == undefined)
return 0;
else if (item.hasOwnProperty('pathItems')) {
// compoundPathItem
if (item.pathItems.length == 0) {
// attempt to fix malformed compoundPathItem
// WARNING: this will alter the
// compoundPathItem by uncompounding,
// ungrouping and re-compounding it.
// It will lose some properties, eg. name
// and you should check that path winding
// is correct afterwards.
// store the selection
var selectedItems = [],
itemIsSelected = item.selected;
for (var i = 0; i < app.selection.length; i++)
if (app.selection[i] !== item)
selectedItems.push(app.selection[i]);
// work on a copy
var temp = item.duplicate();
app.selection = [temp];
// fix bad compoundPathItem
app.executeMenuCommand('noCompoundPath');
app.executeMenuCommand('ungroup');
app.executeMenuCommand('compoundPath');
// get fresh reference to item
// and remove the malformed item
for (var i = 1; i < item.layer.compoundPathItems.length; i++) {
if (item.layer.compoundPathItems[i].uuid == item.uuid) {
temp = item.layer.compoundPathItems[i - 1];
item.remove();
item = temp;
break;
}
}
// reinstate selection
item.selected = itemIsSelected;
for (var i = 0; i < selectedItems.length; i++)
selectedItems[i].selected = true;
}
for (var i = 0; i < item.pathItems.length; i++)
// add together the pathItems' areas
itemArea += item.pathItems[i].area;
}
else if (item.hasOwnProperty('area'))
// pathItem
itemArea = item.area;
else
// didn't calculate area for this item
return -1;
// area can be negative, and also
// it is good to round to 4 decimals
// due to expected tiny rounding errors
return round(Math.abs(itemArea / (unit * unit)), 4);
}
/**
* Rounds a number to `places` decimal places.
* @author m1b
* @version 2022-08-02
* @param {Number} num - the Number to round.
* @param {Number} [places] - round to this many decimal places.
* @return {Number} - the rounded Number.
*/
function round(num, places) {
places = Math.pow(10, places || 1);
return Math.round(num * places) / places;
}
})();