Is it possible to trim a pictureframe with Python without losing the picture?

Ok so I have to import some pictureframes in Rhino page layout and then trim some parts of them using python.

but every command I use trim the surface and discard the texture, those are the one I tried :


I know it’s possible with rs.command(Trim) but in case someone has already resolved this problem please enlighten me.

The fact that rs.TrimSurface and rs.TrimBrep do not work correct with picture frames is a bug. I’ve reported this as a bug.

Here is a version of rs.TrimSurface that should work with picture frames.

import scriptcontext
import rhinoscriptsyntax as rs
import Rhino

def TrimSurfaceEx(surface_id, direction, interval, delete_input=True):
    surface = rs.coercesurface(surface_id, True)
    obj = rs.coercerhinoobject(surface_id, True, True)
    u = surface.Domain(0)
    v = surface.Domain(1)
    if direction==0:
        u[0] = interval[0]
        u[1] = interval[1]
        v[0] = interval[0]
        v[1] = interval[1]
    new_surface = surface.Trim(u,v)
    if new_surface:
        if delete_input:
            scriptcontext.doc.Objects.Replace(obj.Id, new_surface)
            rc = surface_id
            attr = obj.Attributes
            rc = scriptcontext.doc.Objects.AddSurface(new_surface)
        return rc

# Test...
surface = rs.GetObject("Select surface to split", rs.filter.surface)
if surface:
    domain_u = rs.SurfaceDomain(surface, 0)
    domain_u = (domain_u[1] - domain_u[0]) * 0.25, domain_u[1]
    TrimSurfaceEx(surface, 0, domain_u, True )

Thanks for reporting the bug Dale and for the help however there is still a problem, your script trim the surface but picture is shrinked not trimed, this is an undesired behavior that dosen’t happend with the manual command. maybe it’s important to specify it in the bug report, I made this graph and hope it explain better the problem :

in the meanwhile if there is another solution I’m interested.

I didn’t even notice this - sorry for the run around.

Rhino.Geometry.Surface.Trim actually shrinks the underlying surface. So, this is never going to work correctly with a picture frame object. Note, rs.TrimSurface calls ``Rhino.Geometry.Surface.Trim```

On the other hand, Rhino.Geometry.Brep.Trim, which is called by rs.TrimBrep should work. But the underlying function is incorrectly shrinking the underlying surface of the trimmed face. This is a bug.

Sorry I don’t have another solution for you. Hopefully this fix makes it into SR12.

Ok thanks Dale, for now I’m bypassing this by using

rs.Command(’-_Split’ + " SelID " + str(surface) + ’ _Enter’ + " SelID " + str(cuve) + ’ _Enter’)