Combine sublists of View element items from 2 lists with ironpython2.7 of Dynamo

For example, all the lists are made of Revit views. if viewsPF contains sublists [[view1, view2, view3], [view4, view5, view6]] and viewsFF contains sublists [[view7, view8, view9], [view10, view11, view12]] , the resulting viewlist will be a list of sublists [[view1, view2, view3, view7, view8, view9], [view4, view5, view6, view10, view11, view12]] .

I tried this, code but it does not work the operator +, what else can I do to get the result?

viewlist = [pf + ff for pf, ff in zip(viewsPF, viewsFF)]

I am using ironpython 2.7 in a Dynamo 2.4 of Revit 2019, I get a warning that operator + does not like the 3DView element or similar.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line viewlist = [pf + ff for pf, ff in zip(viewsPF, viewsFF)]
, in <module>
TypeError: unsupported operand type(s) for +: 'View3D' and 'View3D'

This should work. What kind of objects are the views?

The other option is to step through each item and add it to the initial sublist.

1 Like

I am using ironpython 2.7 in a Dynamo 2.4 of Revit 2019, I get a warning that operator + does not like the 3DView element or similar.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line viewlist = [pf + ff for pf, ff in zip(viewsPF, viewsFF)]
, in <module>
TypeError: unsupported operand type(s) for +: 'View3D' and 'View3D'

Can you show us your code and inputs? The error says it’s an issue with the view objects, but it should be combining the lists so something seems off.

Does the second option work for you?

Nothing works I resolved creating dictionaries instead, this looks very basic stuff but wasted more time ever

Without context of your data Nick has given a generally functional solution. Can’t see yours so marking it as the fix. If youre frustrated at dynamo having errors and need a project specific fix we generally need to see more specific examples of the issues. My guess is you have inconsistent sublist structure and some lists may be a single 3d view vs a list of them, so its not an iterable/addable object to other lists.

3 Likes

the lists are same number of items and type of elements which are views, so the problem are not the lists or their items, it is something about the ironpython or the ugly dynamo behaviours.

I resolved with a code that looks like this:

from System.Collections.Generic import *
views = Dictionary[str, object]()
views1 = []
views2 = []
views[name] = (views1 + views2)

is it, though?

what conclusion can I take then? it works in cpython3 or newer versions of dynamo

the error clearly indicates that you are trying to concatenate 2 objects (which should be lists?) that are not lists or another iterable element, as @GavinCrump said

Ironpython or Dynamo are not culprits here

5 Likes

suppose are the items inside the sublists that I want to merge in a sublist? maybe the code is wrong is doing something else.

I got 2 lists, each list is made of sublists that contain view elements, so the first sublist items of list1 and first sublist items of list 2 must be a new combined sublist for the new list trying to achieve, and the same for any sublist

Why not just post a picture of your graph with the nodes and inputs visible as asked multiple times?
This feels like someone arguing with a mechanic over the phone what the cause of that weird rattling sound the car is making is…

1 Like

An example


# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
listA = IN[0]
listB = IN[1]

# Place your code below this line

# Assign your output to the OUT variable.
OUT = [i + j if hasattr(i, "__iter__") else [i, j] for i, j in zip(listA, listB)]

another solution


import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

def concat(*args):
    if all(hasattr(x, "__iter__") for x in args):
        return sum(list(args), [])
    else:
        return args

# The inputs to this node will be stored as a list in the IN variables.
listA = IN[0]
listB = IN[1]

# Place your code below this line

# Assign your output to the OUT variable.

OUT = [concat(i, j) for i, j in zip(listA, listB)]
5 Likes