So far my solution to this problem has been iterating through each address in the function address space and counting the number of bytes. However, if there's anyway where when dealing with function objects I could get the function size in bytes without needing to iterate over its address space that would be great!
Especially frustrating since "Function Size" is right there in the GUI, but I just can't figure out how to pull that out via the flat api.
This is what the GUI is doing:
So you could do something like getFunctionAt(addr).getBody().getNumAddresses() from your script.
Most helpful comment
This is what the GUI is doing:
https://github.com/NationalSecurityAgency/ghidra/blob/8b67e3c1e506a8c6d89ae90b715acd1dff4cf9e4/Ghidra/Features/Base/src/main/java/ghidra/util/table/field/FunctionBodySizeTableColumn.java#L34
So you could do something like
getFunctionAt(addr).getBody().getNumAddresses()from your script.