Min / max item at list and create new boundingbox python

Hi,

Can someone tell me how I can get the maximum and the minimum value from a (sub)list?
This is my input:

image

# einde code omrekenen revit feet naar huidig ingestelde document units
# Hieronder kan je dan gaan programmeren
# Gebruik boiler template

bbox = UnwrapElement(IN[0])

minpoint = []
maxpoint = []

#bbox min and maxpunt 
for b in bbox:
	b_min = []
	b_max = []
	for a in b:
		b_min.append(a.MinPoint) #Minpoint bbox
		b_max.append(a.MaxPoint) #Maxpoint bbox
	minpoint.append(b_min)	#liststructere
	maxpoint.append(b_max)	#liststructere
	

min_pointx = [] 
min_pointy = [] 
for min in minpoint:
	minx = []
	miny = []
	for m in min:
		minx.append(m.X) #X minpoint
		miny.append(m.Y) #Y minpoint
	min_pointx.append(min(minx))#liststructere
	min_pointy.append(min(miny))#liststructere


max_pointx = [] 
max_pointy = [] 
for max in maxpoint:
	maxx = []
	maxy = []
	for m in max:
		maxx.append(m.X) #X maxpoint	
		maxy.append(m.Y) #Y maxpoint	
	max_pointx.append(max(maxx))#liststructre
	max_pointy.append(max(maxy))#liststructre



OUT =  max_pointx

The min and max doesn’t work:

max_pointx.append(max(maxx))#liststructre
max_pointy.append(max(maxy))#liststructre

2022-05-05_15h24_02
Whats your imput?

its not working at all.

Boundingboxen in @L3

This works:


bbox = UnwrapElement(IN[0])

minpoint = []
maxpoint = []

#bbox min and maxpunt 
for b in bbox:
	b_min = []
	b_max = []
	for a in b:
		b_min.append(a.MinPoint) #Minpoint bbox
		b_max.append(a.MaxPoint) #Maxpoint bbox
	minpoint.append(b_min)	#liststructere
	maxpoint.append(b_max)	#liststructere
	

min_pointx = [] 
min_pointy = [] 
for min in minpoint:
	minx = []
	miny = []
	for m in min:
		minx.append(m.X) #X minpoint
		miny.append(m.Y) #Y mintpoint
	min_pointx.append(minx)#liststructere
	min_pointy.append(miny)#liststructere


max_pointx = [] 
max_pointy = [] 
for max in maxpoint:
	maxx = []
	maxy = []
	for m in max:
		maxx.append(m.X) #X maxpoint	
		maxy.append(m.Y) #Y maxpoint	
	max_pointx.append(maxx)#liststructre
	max_pointy.append(maxy)#liststructre



OUT =  max_pointx


OK

@Draxl_Andreas

chop your bbox list
image

What are you trying to do with this code? Specifically max(maxx) and max(maxy)? This is not a valid syntax.

I try to take the maximum item of that list.

1 Like

You’ve defined max as a list though. If you’re trying to use max() as a function you have to define the function and use a different name for either the list or the function. Otherwise you have list(item) which means nothing.

2 Likes

Thank you @Nick_Boyts

Does someone know how to create a def for maximum and minimum in a list?

Found a solution :slight_smile:

import heapq

p = IN[0]

maxout = []
s = 0
for i in p:
	maxout.append(heapq.nlargest(1, p[s]))	
	s += 1

minout = []
s=0
for i in p:
	minout.append(heapq.nsmallest(1, p[s]))	
	s += 1

OUT = maxout, minout
2 Likes

Hello,
an alternative
global_bbx

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

groupbbx = IN[0]
out = []
for lstbbx in groupbbx:
    glob_minX = min(lstbbx, key = lambda x : x.MinPoint.X).MinPoint.X
    glob_maxX = max(lstbbx, key = lambda x : x.MaxPoint.X).MaxPoint.X
    glob_minY = min(lstbbx, key = lambda x : x.MinPoint.Y).MinPoint.Y
    glob_maxY = max(lstbbx, key = lambda x : x.MaxPoint.Y).MaxPoint.Y
    glob_minZ = min(lstbbx, key = lambda x : x.MinPoint.Z).MinPoint.Z
    glob_maxZ = max(lstbbx, key = lambda x : x.MaxPoint.Z).MaxPoint.Z
    minpt = Point.ByCoordinates(glob_minX, glob_minY, glob_minZ)
    maxpt = Point.ByCoordinates(glob_maxX, glob_maxY, glob_maxZ)
    out.append(BoundingBox.ByCorners(minpt, maxpt))
OUT = out
3 Likes

Thank you! that is my end goal of this script.
I want to create new boxes and that is what you do! :slight_smile:

It is time to learn more about the lambda :slight_smile:

2 Likes