@Archibum @Jean-Marc,
Thanks for the responses, yes it was a gpt script that I was using. I’ve decided to have a look at it again.
I’ve managed to get close by editing the sub elements and moving the vertex of the floor but I don’t think my intersection of the floor points with the topo is working. I also think I should be adding more points onto the floor and then doing it that way.
This is what I have so far:
from Autodesk.Revit.DB import (
BuiltInCategory, XYZ, ReferenceIntersector,
FindReferenceTarget, Transaction, Options, Solid,
GeometryInstance, UV, SlabShapeEditor, SlabShapeVertex
)
from Autodesk.Revit.UI.Selection import ObjectType, ISelectionFilter
import clr
clr.AddReference("System")
from System.Collections.Generic import List
uidoc = __revit__.ActiveUIDocument
doc = uidoc.Document
class FloorSelectionFilter(ISelectionFilter):
def AllowElement(self, element):
return element.Category.Id.IntegerValue == int(BuiltInCategory.OST_Floors)
def AllowReference(self, refer, point):
return False
class TopoSelectionFilter(ISelectionFilter):
def AllowElement(self, element):
return element.Category.Id.IntegerValue == int(BuiltInCategory.OST_Topography)
def AllowReference(self, refer, point):
return False
try:
floor_selection_filter = FloorSelectionFilter()
selected_floor_ref = uidoc.Selection.PickObject(
ObjectType.Element,
floor_selection_filter,
'Select a floor to modify.'
)
selected_floor = doc.GetElement(selected_floor_ref.ElementId)
topo_selection_filter = TopoSelectionFilter()
selected_topo_ref = uidoc.Selection.PickObject(
ObjectType.Element,
topo_selection_filter,
'Select a topography surface.'
)
selected_topo = doc.GetElement(selected_topo_ref.ElementId)
t = Transaction(doc, "Modify Floor Shape")
t.Start()
boundary_points = []
options = Options()
options.ComputeReferences = True
options.IncludeNonVisibleObjects = True
geometry_element = selected_floor.get_Geometry(options)
for geometry_object in geometry_element:
if isinstance(geometry_object, Solid):
solid = geometry_object
for face in solid.Faces:
normal = face.ComputeNormal(UV(0.5, 0.5))
if abs(normal.Z) > 0.99 and normal.Z < 0:
edge_loops = face.EdgeLoops
for edgeArray in edge_loops:
for edge in edgeArray:
curve = edge.AsCurve()
start_point = curve.GetEndPoint(0)
boundary_points.append(start_point)
elif isinstance(geometry_object, GeometryInstance):
instance_geometry = geometry_object.GetInstanceGeometry()
for inst_geom_obj in instance_geometry:
if isinstance(inst_geom_obj, Solid):
solid = inst_geom_obj
for face in solid.Faces:
normal = face.ComputeNormal(UV(0.5, 0.5))
if abs(normal.Z) > 0.99 and normal.Z < 0:
edge_loops = face.EdgeLoops
for edgeArray in edge_loops:
for edge in edgeArray:
curve = edge.AsCurve()
start_point = curve.GetEndPoint(0)
boundary_points.append(start_point)
unique_points = []
for pt in boundary_points:
if not any(pt.IsAlmostEqualTo(existing_pt) for existing_pt in unique_points):
unique_points.append(pt)
print('Boundary points: ', unique_points)
direction_up = XYZ(0, 0, 1)
direction_down = XYZ(0, 0, -1)
reference_intersector = ReferenceIntersector(
selected_topo.Id,
FindReferenceTarget.Face,
doc.ActiveView
)
new_points = []
for point in unique_points:
results_up = reference_intersector.Find(point, direction_up)
results_down = reference_intersector.Find(point, direction_down)
intersection_point = None
if results_up:
intersection_point = results_up[0].GetIntersection().XYZPoint
elif results_down:
intersection_point = results_down[0].GetIntersection().XYZPoint
else:
intersection_point = point
new_points.append(intersection_point)
print('New points: ', new_points)
slab_shape_editor = selected_floor.SlabShapeEditor
slab_shape_editor.Enable()
for pt in unique_points:
slab_shape_editor.DrawPoint(pt)
vertices = slab_shape_editor.SlabShapeVertices
print('Vertices: ', vertices)
for vertex in vertices:
vertex_pt = vertex.Position
min_dist = None
closest_pt = None
for pt in new_points:
dist = vertex_pt.DistanceTo(pt)
if min_dist is None or dist < min_dist:
min_dist = dist
closest_pt = pt
print("Closest point: ", closest_pt.Z)
if closest_pt:
slab_shape_editor.ModifySubElement(vertex, closest_pt.Z)
t.Commit()
print("Floor shape modified successfully.")
except Exception as e:
import traceback
print("Selection cancelled or an error occurred: {}".format(e))
traceback.print_exc()
Thanks