I all,
i’m testing some python code in Dynamo and i’m receiving different result depending on wheter i use my dictonaries or not. whichs i to link the face to there walls and also the uvs to the walls to that the faces.
any ideas on what happens differently here?
list result in revit:
dictonarie result in revit:
In green the points generated by the dinctonarie script.
It seems like there are rows and coloms of points missing…
code with list:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
items = UnwrapElement(IN[0])
if not hasattr(items, '__iter__'):
items = [items]
Faces = []
for item in items:
extSide = HostObjectUtils.GetSideFaces(item,ShellLayerType.Exterior)
for e in extSide:
extFace = item.GetGeometryObjectFromReference(e)
Faces.append(extFace)
intSide = HostObjectUtils.GetSideFaces(item,ShellLayerType.Interior)
for i in intSide:
intFace = item.GetGeometryObjectFromReference(i)
Faces.append(intFace)
Points = []
directions = []
for face in Faces:
bboxUV = face.GetBoundingBox()
u_interval = (bboxUV.Max.U - bboxUV.Min.U) / 9
v_interval = (bboxUV.Max.V - bboxUV.Min.V) / 9
for i in range(10):
u = bboxUV.Min.U + i * u_interval
for j in range(10):
v = bboxUV.Min.V + j * v_interval
uv = UV(u, v)
if face.IsInside(uv):
Points.append(Point.Create(face.Evaluate(uv)).ToProtoType())
directions.append(face.ComputeNormal(uv).ToVector())
else:
# If the UV point is outside the face, adjust it
for d in range(1, 10):
# Try moving the point towards the center of the face
adjusted_uv = UV(u - d * u_interval / 10, v - d * v_interval / 10)
if face.IsInside(adjusted_uv):
Points.append(Point.Create(face.Evaluate(adjusted_uv)).ToProtoType())
directions.append(face.ComputeNormal(adjusted_uv).ToVector())
break
# Output
OUT = Points, directions
code wit dicontaries:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("System")
import System
from System.Collections.Generic import List
# collect walls in model
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
faces = []
valid_walls = {}
# Iterate through all walls to find intersections
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
for wall in walls:
wall_faces = []
# get interiorface
extside = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Exterior)
for e in extside:
extface = wall.GetGeometryObjectFromReference(e)
if extface == None:
continue
else:
wall_faces.append(extface)
# get exteriorface
intside = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Interior)
for i in intside:
intface = wall.GetGeometryObjectFromReference(i)
if intface == None:
continue
else:
wall_faces.append(intface)
# Add wall_faces to general faces list
if len(wall_faces) > 0:
valid_walls[wall] = wall_faces
# create points grid for each face
# create dictionary to store checkpoints in
wall_uvs = {}
points = []
# determin precision of the check
precision = 10
for wall , faces in valid_walls.items():
# create entry in disctionary for the wall
wall_uvs[wall] = []
for face in faces:
# create list to store all points of each face in
face_uvs = []
# get min & max UV for each face and determin the interval based on the presicion
bboxUV = face.GetBoundingBox()
u_interval = (bboxUV.Max.U - bboxUV.Min.U) / precision-1
v_interval = (bboxUV.Max.V - bboxUV.Min.V) / precision-1
# create pointgrid for the face
for i in range(precision):
u = bboxUV.Min.U + i * u_interval
for j in range(precision):
v = bboxUV.Min.V + j * v_interval
uv = UV(u, v)
# check if points are on the face
if face.IsInside(uv):
face_uvs.append(Point.Create(face.Evaluate(uv)).ToProtoType())
else:
# if the UV-point is outside the face, adjust it
for d in range (1, precision):
# Try moving the point towards the center of the face
adjusted_uv = UV(u - d * u_interval / precision, v - d * v_interval / precision)
if face.IsInside(adjusted_uv):
face_uvs.append(Point.Create(face.Evaluate(uv)).ToProtoType())
break
# add points of face to dict entry of the wall
points.append(face_uvs)
wall_uvs[wall].append(face_uvs)
# Output
OUT = points




