Ordering Representation

I am extracting Representation in my M2Doc export

{ m:for f | self.eAllContents() }
{ m:for rep | f.representationByDescriptionName(‘Logical Architecture Blank’)}
{ m:rep.name}
{ m:endfor }
{ m:endfor }

I receive files in a random order
I would like to order them,
One solution should be to put the order in the file name … Ugly but simple (no external list to handle)
So could look like
001[LAB] …
002[LAB] …
010[LAB] …
011[LAB] …
020[LAB] …
021[LAB] …

with the smart idea to keep some empty numbers between number for the futur :smirk:

but how can I sort from smallest to greatest the names issued of my for :
{ m:for rep | f.representationByDescriptionName(‘Logical Architecture Blank’)}

Thanks in advance for ideas

You can sort using an AQL expression, for instance:

f.representationByDescriptionName(‘Logical Architecture Blank’)->sortedBy(r | r.name)

If you want to sort all representations you need to do it in one for loop:

self.eAllContents().representationByDescriptionName(‘Logical Architecture Blank’)->sortedBy(r | r.name)

You can also replace the r.name to sort on other criterion.

It works !!! Great ! thank you !
I am now going to try to use another field not to pollute the title

I Talked too fast
I works very well for Logical Architecture Blank but not for Exchange Scenario
{ m:for rep | f.representationByDescriptionName(‘Logical Architecture Blank’)->sortedBy (r | r.name)}
it works fine

001[LAB]
002[LAB]
003[LAB]
004[LAB]

{ m:for rep | f.representationByDescriptionName(’‘Component Exchanges Scenario’)->sortedBy (r | r.name)}
it is the same order that without the SortBy …

I have the feeling that in first case I am sorting a list => ok
and in second I am sorting element of the list per element of the list : sorting itself so no real sorting ???

I anybody have an idea :persevere:

You should probably sort representations all at once:

I tested your proposal and Capella goes into infinite loop, I crashed the program …
I put the “self” a the element after the .aird (at the same level of Representation per category)
I had this problem several time yesterdays, I guess I do something wrong

in the code I am using For loop

{ m:for f | self.eAllContents()}
{ m:for rep | f.representationByDescriptionName(‘Logical Architecture Blank’)->sortedBy (r | r.name)}
{ m:rep.name }
{ m:endfor }

Like this I have the feeling to better control the items rep and can access it several times

If you have a stack trace in your error log I would like to see it. Maybe we go into an out of memory here. Also there is a missing endfor, and I fixed an issue in the parser recently that could explain the infinit loop in the parser.

But with two loops nothing prove you will get f elements in the rep.name order.

An other way to get all representations would be to navigate de DAnalysis object:

rep.getDescriptor().eContainer(viewpoint::DAnalysis).ownedViews.ownedRepresentationDescriptors

You can store the expression value in a variable using a let. Lets call it descriptors. Then you can filter on the representation description name and sort by the representation name:

descriptors->select(d | d.description.name = ‘Logical Architecture Blank’).representation->sortedBy(r | r.name)

this will give you a list of representation. You can then loop over this list and to get the element f in your previous example you can use:

representation.target

All put together:

{m:let descriptors = rep.getDescriptor().eContainer(viewpoint::DAnalysis).ownedViews.ownedRepresentationDescriptors }
  { m:for representation | descriptors->select(d | d.description.name = 'Logical Architecture Blank').representation->sortedBy(r | r.name) }
    { m:representation.name }
    { m:representation.target }
  { m:endfor }

  { m:for representation | descriptors->select(d | d.description.name = 'Component Exchanges Scenario').representation->sortedBy(r | r.name) }
    { m:representation.name }
    { m:representation.target }
  { m:endfor }
{ m:endlet }
Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.