Was just testing something this morning and ran across this. The help for rs.ShrinkTrimmedSurface() implies that it should accept either surfaces or polysurfaces.
However if I feed it a polysurface it fails. If I feed it a single surface it works. I used this to test:
import rhinoscriptsyntax as rs
msg="Select surfaces or polysurfaces to shrink"
objs=rs.GetObjects(msg,8+16,preselect=True)
if objs:
for obj in objs:
result=rs.ShrinkTrimmedSurface(obj,False)
print result
If you select the two closed polysurfaces in the file below, it fails and prints “None, None”
If you explode one or the other of the polysurfaces and select say the unshrunk horizontal surfaces of the result, it succeeds.
ShrinkTest.3dm (2.0 MB)
Upon further investigation and testing:
The underlying RC code for rs.ShrinkTrimmedSurface() is as follows:
brep = rhutil.coercebrep(object_id, True)
if not brep.Faces.ShrinkFaces(): return scriptcontext.errorhandler() #fails here if input is a multiface brep
rc = None
object_id = rhutil.coerceguid(object_id)
if create_copy:
oldobj = scriptcontext.doc.Objects.Find(object_id)
attr = oldobj.Attributes
rc = scriptcontext.doc.Objects.AddBrep(brep, attr)
else:
rc = scriptcontext.doc.Objects.Replace(object_id, brep)
scriptcontext.doc.Views.Redraw()
return rc
If I step into that function I see it is failing because brep.Faces.ShrinkFaces()
reports False if a polysurface is input that has at least one UNSHRUNK (i.e. natural) face. If all the faces are unshrunk, it succeeds and reports true.
I used this as a simplified test with the file below:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
msg="Select surfaces or polysurfaces to shrink"
objs=rs.GetObjects(msg,8+16,preselect=True)
if objs:
for obj in objs:
brep = rs.coercebrep(obj,True)
shrink=brep.Faces.ShrinkFaces()
if not shrink:
print "Shrink failed!"
else:
print "Shrink succeeded."
ShrinkTest2.3dm (1.9 MB)
What I haven’t yet determined is if it’s just the reporting that is bad - which causes the rs function to fail immediately - or if the surfaces are actually shrunk despite the False success/failure return. Will attempt to find that out next.
Edit:
And the answer is: it is the reporting that is incorrect, not the actual shrink function - which is kinda what I expected or this would have been found much earlier…
To test:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
msg="Select surfaces or polysurfaces to shrink"
objs=rs.GetObjects(msg,8+16,preselect=True)
if objs:
for obj in objs:
brep = rs.coercebrep(obj,True)
shrink=brep.Faces.ShrinkFaces()
if not shrink:
print "Shrink failed!"
else:
print "Shrink succeeded."
if brep:
sc.doc.Objects.Replace(obj,brep)
sc.doc.Views.Redraw()
If you run this on the any of the polysurfaces in the files above with at least one unshrunk face, it reports “Failed” but in fact the shrink has succeeded if you look at the result in the Rhino window.
So it is actually the RhinoCommon method BrepFaceList.ShrinkFaces that is partially broken, it actually succeeds but reports failed in this particular case.