Hi,
I want to add in my M2Doc report the result table with the individual metrics:
how can I access this data?
Or: Alternative: I list all SGs with the evaluation results:
Up to now I was not able to find these values.
Thanks,
Sven
Hi Sven,
If you have multiple SGs and individual metrics activated on the Cover Sheet, then you will have to call certain methods with the SG as argument - there are no dedicated properties for that (could be many...). See in the help: Ansys medini™ analyze Metamodel Documentation > Failure Mode Effect and Diagnostic Analysis > FMEDA Worksheet Structure > Search further down for "individualMetrics"
You could access a value directly with "eval" like this (see here) - but that only works with defining the index of the SG within the Javascript, not with an M2Doc for loop. (We plan to introduce a 2nd parameter for the eval service in the future.)
At the moment, for more flexibility you will need to create Javascript M2Doc services.
Regards,
Nils
Hi Nils,
I had similar use-case. Was notaware about eval.
Anyways I played with it abit and even parametrized the eval function with combination of an AQL stringand m2doc for loop.
Trick is that the eval functiontakes string as an input so no issue to pass the m2doc value throughmanipulated string. It could be done through string concatenation or throughString.replace(from,to) or even String replaceAll(from,to)For convenience I opted to place '_NR_' stringto then replaced by number ( id of SG) using AQL myDC.safetyGoal->indexOf(sg).note that final argument has to be string so needs to be converted to string->I used AQL x.toString().
Example for the case of the safetygoal of an dc worksheet
{m:for sg | myDC.safetyGoal}Safety Related FIT{m:let gidString = myDC.safetyGoal->indexOf(sg).toString()}{m: myDC.eval('self.getTotalSafetyRelatedFailureRate(self.safetyGoal.get(_NR_));\n'.replace('_NR_',gidString))}{m:endlet goal id}{m:endfor dc safety goals}
The same can be done event without m:let …
{m:for sg | myDC.safetyGoal}Safety Related FIT{m: myDC.eval('self.getTotalSafetyRelatedFailureRate(self.safetyGoal.get(_NR_));\n'.replace('_NR_', myDC.safetyGoal->indexOf(sg).toString()))}{m:endfor dc safety goals}
And here is an example even without replace using AQL native to string conversion
{m:for sg | myDC.safetyGoal}Safety Related FIT{m: myDC.eval('self.getTotalSafetyRelatedFailureRate(self.safetyGoal.get('+myDC.safetyGoal->indexOf(sg)+'));\n'}{m:endfor dc safety goals}
Note there are severalcharacter that needs to be escaped :
' "TEXT" ' ->OBJ.eval(' \"TEXT\"')
' "TEXT\nnewline_JS_TEXT" \n self;' -> OBJ.eval(' \"TEXT\\n newline_JS_TEXT" \n self;')
Resulting eval stringargument:
"TEXT\nnewline_JS_TEXT"
self;
Happy Reporting,
Marian
Hi Marian,
Nice tweak, thanks for sharing! I wasn't aware that the JS can directly access other variables.
In order to avoid the need for these tweaks, we will allow more parameters for eval() in 2024R2. :-)
HINils ,
justto clarify the "access" directly the m2doc variable. It isbecause I passed a value (index) in between the string code snippetfor eval() . It is not physically passing object but a string. Anyway it could be done passing a mediniIdentifier and suing finder withfilter on meidniIdentifier inside of eval().
Inthe meantime, I have played around more with eval() trying to figure out how toimplement "real" local template variable concept. Without let..endlet(Teaser trailer you can expect a separated article on that topic form me).
Hereare my observations. (2024R1)
Object type( object.eval())
Description
Integer,String
Service not supported
Null, MetaClass
Service supported but problems with finder , load
Emf object instance
Works without any issues
AQL collection
Not supported ().eval() , works only on first objects m, resth having an issue
AQL collection operation
Not supported ()->eval()
Therewere some cases where it worked only partially. or instance problems withload() and finder ..
Pleasetake a look and use attached word template to see more details.
PS:I have just noticed the Jan's post about planned enhancements for 24R2, notsure whether it will also address the cases in the providedtemplate. Looking forward for the next release to see evalenhancements.
Happyreporting,
Hi All,
A small update.
So with 24R2 the Evaluation service is now possible to be called on any Object ( string, integer, Collection).
Thanks for extension!
I have tested it out and have some observations, that may be useful for others.
There some differences compared to a regular JS execution.
Capabilities of the service are little bit different depending on the context that is caller.
The operators
The __homedir ,__tool_version , ... JS objects
The load("")
Error: java.lang.IllegalStateException: unable to obtain calling script file - cannot resolve relative file name
The finder
//m2doc query to create a Scoped Finder for a given Eval service inside of the m2doc template file// the AQL query will ALWAYS yeild a single project (Owner of the M2Doc checklist)//the JS Gobal.projects will list ALL open medini projects//example use eval & finder to list all TAGGED objects with tag 'PENDING-TASK' {m: ''.eval('var finder = Global.getFinder(p2);\n finder.findByTag(\'PENDING-TASK\').asList()',projectmodel::MediniProject.allInstances()->first())->sep('\n')}// now using Mediniproject as a Context{m: (projectmodel::MediniProject.allInstances()->first()).eval('finder.findByTag(\'PENDING-TASK\').asList()')->sep('\n')}
The bind ( aka $EXPERIMENTAL$ pragma)
({ evalm2: function(/*Object*/self2,/*String*/script) { var self = self2; return eval(script); },})