Rearrange list Challenge (Drawing Transmittal)

Hi all,

I am building a graph to create a drawing transmittal:

The difficulty comes when I have to rearrange the data extrated from the sheets:

Here my two questions:

  • How to add an element to a list to make sure each sublist has as many elements as revisions (in my example each sublist must have 3 elements)
  • How do I change the position of an element in a sublist so it matches the Revision Sequence.

As usual, thanks a lot for your help.

Hi Pablo

I suggest using Dynamo to extract the data, then something with a PIVOT function- such as Excel to present it in this format.

You could probably come up with a solution in Dynamo, although it might not be pretty

Andrew

Hi Andrew, that is what I currently have :slight_smile:

I was wondering if I could achieve the same result directly from Dynamo but that additional step is adding more complexity that I can handle.

Can you sketch what your final result would look like?

Hi Salvatore,

The result would look like this:

Then I can write that List of Sublist in Excel so it’ll look as the first image of my post.

Thanks!

@Pablo_Perez_Valdivia Well, we always like a good challenge :slight_smile:

This is my solution in Python:

Rev=IN[0]
Ind=IN[1]
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

import itertools

def MapList(lst):
	return map(lambda x:x-1, lst)

L=len(Rev)

MaxL=max([len(i) for i in Ind])
IndMinus1=[MapList(i) for i in Ind]

OUT=[]
for i in range(0,MaxL):
	OUT.append('-')

OUT=list(itertools.chain.from_iterable(itertools.repeat(OUT, L)))
OUT=[OUT[x:x+MaxL] for x in xrange(0, len(OUT), MaxL)]

for index,i in enumerate(OUT):
	for k,j in zip(Rev[index],IndMinus1[index]):
		i[j]=k
1 Like

I think I’ve shown how to do recursive replacement with DS before, but can’t seem to find the example. You can try this:

def replace1(a:var[], i:var[], v:var[]){
return = [Imperative]{
    for (x in GetKeys(i) )
    {
        a[i[x] - 1] = v[x];
    }
    return = a;
}};
4 Likes

Thanks Salvatore!

The more I see coding, the more I want lo learn.

Can you recommend me any guide,course,tutorial… to start learning Python?

Bravo @Dimitar_Venkov, so neat!

It works really well.

I’ll add soon a extra layer of complexity that I just come across.

Look here:

1 Like

Hi @Dimitar_Venkov,

I have tested your code in a real case where the Revisions Sequence aren’t consecutive numbers as follows:

We have just 3 Revision Sequence: 9, 12, 17. As these are numbers, when I apply your code, the result is not the desired: 5 sublist with 3 elements in each.

Would it be possible to renumber the Revision Sequence so it works with your code?

Thanks a lot Salvatore, I’m definitely going to start learning… I’m sure it’ll be a long journey.

SOLVED!!!

The Blue group renumbers the Revision Sequence with consecutive numbers and applies it to the Revision Sequence on sheets. Then I can use @Dimitar_Venkov’s code normally.

Again, thanks all for your help!

1 Like

Is my code working with your real case?

@Pablo_Perez_Valdivia Great! Sorry I just had a quick read to your post regarding the revision sequence.
My code wouldn’t work but it’ll needs some amendments.:slight_smile:

That’s correct @salvatoredragotta, I couldn’t make your code work either with the real case.

Now I’m adding some BumbleBee nodes to pass the info to an Excel file, almost done :slight_smile: