Array.append() or array.extend()?

ghpython

#1

I am trying to pass the intersection of some planes with a brep from a python script to an Extrude component, using the IntersectBreps() function of rhinoscriptsyntax and appending to an array, as shown in the screenshot:


The Extrude component is generating the error: “Data conversion failed from Goo to Geometry

The screenshot below shows how the data is received by the Extrude component:

The screenshot below shows how it looks like if just the planes are exported to the Extrude component and it extrudes them successfully:


But what is required is to have the intersection curves of these planes and the rhino geometry to be extruded.

If this extrusion is performed within the python script, it fails as show below:


The balloon error is as below:

How can the array of the results of rhinoscriptsyntax.IntersectBreps(brep1, brep2) be passed to the Extrude component OR this extrusion be performed within the python script itself?

Thank you.


#2

If you only need a flatten list of all intersections, it’s better to do it like this:

if(brepResult):
    breps.extend(brepResult)


dzentsu.gh (45.5 KB)


#3

Thank you @Mahdiyar.

It worked by replacing breps.append(brepResult) with breps.extend(brepResult)
if(brepResult): was necessary to avoid the TypeErrorException: NoneType is not iterable (as shown below)

Then I tried to extrude the resulting breps and create the array again as:
breps.extend(brepExtruded)
but it threw:
Runtime error (TypeErrorException): Guid is not iterable

Replacing extend with append worked this time though:

So now I’m confused as to which entities do extend and append apply to?


#4

rs.IntersectBreps() returns a list of guid whenever the input breps intersected each other.
rs.ExtrudeCurve() return a single guid whenever the extrusion was successful.
both of these functions return none if there was any problem.

If you want to add a list to another list you have to use extend but if you want to add a single item to a list you have to use append.


#5

Thanks @Mahdiyar, this clarifies it.

Even when there is just a single intersection?


#6

Yes, if there was a single intersection, this function would return a list with only one item in it.


#7

Okay. Thanks a lot! :slightly_smiling_face: