Hi, I’m fairly new to Python but I’m trying to put something together that will cycle through layers/objects in a rhino project and run the shrink wrap function, As far as I can wrap function is being applied on the input meshes but nothing is being created or output.
The printed layers shows all layers in the model, and you can see each mesh being selected as part of the last few lines added for debugging.
Has anyone had any success using Mesh.ShrinkWrap ?
import rhinoscriptsyntax as rs
import Rhino as r
options = ("Layer Based", "Object Based")
WrapMethod = rs.ListBox(options, "Pick Wrap Method")
WrapRes = rs.GetReal("Wrap Resolution in meters", 2, 0.0)
WrapOffset = rs.GetReal("Wrap Offset (expansion) in meters", 0.0, 0.0)
layers_with_shrinkwrap = [] # Create an empty list to store layer names
if WrapMethod == "Object Based":
arrLayers = rs.LayerNames()
props = r.Geometry.ShrinkWrapParameters()
props.FillHolesInInputObjects = True
props.PolygonOptimization = 0
props.Offset = WrapOffset
props.TargetEdgeLength = WrapRes
for strLayer in arrLayers:
if not rs.IsLayerEmpty(strLayer):
rs.UnselectAllObjects()
objs = rs.ObjectsByLayer(strLayer)
if objs:
for obj in objs:
mesh = rs.coercemesh(obj)
if mesh:
result = r.Geometry.Mesh.ShrinkWrap(mesh, props)
if result:
layers_with_shrinkwrap.append(strLayer) # Add the layer name to the list
rs.SelectObject(obj) # Select the wrapped object for visualization
rs.Redraw() # Redraw the viewport to visualize the wrapped object
rs.UnselectAllObjects()
# Print the list of layers where ShrinkWrap was applied
print("Layers with ShrinkWrap applied:", layers_with_shrinkwrap)