M2DOC - get unit from a datatype

Hi,
I try to extract with M2DOC information from data package.
I used the LA template from IFE M2DOC example.
On my model, when I use the AQL command into the interpreter:
I get the answer “m/s”
But when I try to get it via M2DOC
I had the following error :
Speed is a physical quantity expressed in Invalid query statement: Feature unit not found in EClass DataType

Hi,
The problem arise on this expression {m:data.unit}, there is no feature unit. You can use the interpreter and completion (CTRL+SPACE) to see what features are available. Or you can try just {m:data} it should print the string representation of the object and list feature name a value pairs.
regards,
Yvan Lussaud.

Thank you Yvan…
The problem is that M2Doc does not understand your test and consider that data can be any kind of dataType element.
You need to adapt a little bit your code to make sure that data is only of kind PhysicalQuantity.
Can you try:
{m:for data | package.ownedDataTypes}
{m:if data->filter(datatype::PhysicalQuantity)->size() > 0}
{m:data.name} is a physical quantity expressed in {m:data->filter(datatype::PhysicalQuantity).unit.name}
{m:endif}
{m:endfor}

Thank you Aurélien ! It works !
In fact I found that test to isolate physical quantity into the datatype list. I can split them into several for loop (one for physical quantity, one for enumerate and so on…) with a specific filter. But if you have a tips to get the class of an object…
Thank you again

To let M2Doc (underlying AQL) infers the type by itself you can try:
{m:for data | package.ownedDataTypes}
{m:if data.oclIsKindOf(datatype::PhysicalQuantity)}
{m:data.name} is a physical quantity expressed in {m:data.unit.name}
{m:endif}
{m:endfor}
An if you want to only iterate over datatype::PhysicalQuantity you can use:
{m:for data | package.ownedDataTypes->filter(datatype::PhysicalQuantity)}
{m:data.name} is a physical quantity expressed in {m:data.unit.name}
{m:endfor}
The type should also be inferred in this case.
To get the class of an object you can use {m:data.eClass().name}
regards,
Yvan Lussaud.

Thank you for your reply