Dynamo: Listing per Element

Dynamo: Listing per Element

mdugas
Participant Participant
4,076 Views
8 Replies
Message 1 of 9

Dynamo: Listing per Element

mdugas
Participant
Participant

I am working with a custom node that returns all the Ancillary Ids of the Elements selected.  My issue is that it just creates a single list of all parameters.  Since each Element can have a different number of Ancillary Ids, I need to list these per Element.  Then I can access them per list, per index number. Below I have only added the List.Chop node to show how I need the list from the Python Script to look; that is not intended to be part of the script. 

 

python list.JPG

 

I understand the append is just adding the next Ancillary Id to the list.  But I am struggling to find a way to break up the list per Element as I need?  Not sure if I need to use a Count or maybe create a second list???

 

ancillary node.JPG

 

0 Likes
Accepted solutions (1)
4,077 Views
8 Replies
Replies (8)
Message 2 of 9

stewart_skyler
Enthusiast
Enthusiast

Create another list that you append Ancillaries to inside your for loop.

 

for element in elements:
    Ancillary = element.GetPartAncillaryUsage()
    sub_list = []
    for ancillaryIds in Ancillary:
        ancillaryId = ancillaryIds.AncillaryId
        sublist.append(ancillaryId)
    Ancillary.append(sublist)

 

0 Likes
Message 3 of 9

mdugas
Participant
Participant

Thanks for the input.  That is exactly what I was looking for.  I did try the code as you wrote it but I am getting a undefined name so I will have to play with the syntax to see if I can figure it out.  If someone sees the issue before I can catch it, please let me know.  Thanks again

sublist.jpg

0 Likes
Message 4 of 9

mdugas
Participant
Participant

I was able to remove the underscore in line 36 and get the error cleared but now I have a new error.  Again I am using the wrong syntax because it looks like it is looking for the attribute "append" which does not exist.  I am just trying to list the ancillary Id's per element...  😞

sub list 2.jpg

0 Likes
Message 5 of 9

stewart_skyler
Enthusiast
Enthusiast
Accepted solution

Ah, sorry, I just retyped your code out on the spot, looks like I made a mistake. "Ancillary.append" should be "Ancillaries.append"

 

Basically what's happening is instead of appending to the python list you made on line 26, I was trying to use the python method of "append" on an iCollection, which, of course, doesn't work because iCollections don't have an append method. 

Also, make sure you unindent "Ancillaries.append" otherwise you'll end up with the same output, just nested in another list.

 

 

for element in elements:
    Ancillary = element.GetPartAncillaryUsage()
    sublist = []
    for ancillaryIds in Ancillary:
        ancillaryId = ancillaryIds.AncillaryId
        sublist.append(ancillaryId)
    Ancillaries.append(sublist)

 

 

0 Likes
Message 6 of 9

mdugas
Participant
Participant

Once again you have been a big help!  If I can be so bold as to ask for one more piece of advice?  Besides the ancillary ID, there are 5 more pieces of info I need to report in my list from this same element.  Should I attempt to pull all the items with the same script, or alter the script and run separate scripts for each piece of data I need? 

Example: I want to pull 6 pieces of data from each ancillary.  Is it easier to work with the data from one script where the 6 pieces are just in a single row divided by commas OR alter the script 6 times to report the same data for each element separately and pull from the individual lists later when I put this info into shared parameters?  I am concerned that having all the data in one row and not indexed may be a pain later on....

0 Likes
Message 7 of 9

stewart_skyler
Enthusiast
Enthusiast

This is a bit harder to answer without knowing what exactly you're trying to accomplish. I personally tend to pull all the data at the same time, if I can, but there are always exceptions. Part of coding is learning different ways to deal with and manage your data, and what the best way to do it is for each application. 🙂

0 Likes
Message 8 of 9

mdugas
Participant
Participant

I get it..  Thanks again for the help.  Much appreciated🙂

Message 9 of 9

stewart_skyler
Enthusiast
Enthusiast

No problem. Best of luck on the rest of your script!