Can I pay someone to write me two Python scripts that I need? Both involve selection methods

Hey, I’d like to commission two Python scripts that I need if someone can offer their services. What I need are described below:

  1. Firstly, a script that selects all objects on a layer that are intersecting with all objects of another layer. The user is prompted for each layer name. For example, let’s say a cube on “Layer 01” is intersecting with a mesh on “Layer 02”, and I only want to select the cube. With this script running, the user is prompted first for the layer that contains the objects they want to add to selection (e.g. Layer 01, which has a cube), but only if those objects are intersecting with a subsequently designated layer’s objects (Layer 02, which has a mesh). In this example, the cube would be selected after running this script, but not the mesh of course. Let’s say you had 80,000 polysurfaces on one layer that are overlapping a reference mesh on another layer, but only wanted to select the polysurfaces that touch the mesh – that’s why I need this script.

  2. The second script selects all objects that are in any way visible (from outside the extents of everything in the scene), from any direction. For example, let’s say you had 27 cubes, contiguously joined as a 3 by 3 by 3 amalgamation. This script when run would add the outside 26 cubes to the selection, leaving the hidden center cube unselected.

Let me know if you are interested, and we can talk! Thanks!

Hi Jason,

We already had contact via email, I reply here as well as it might be enough for you to get some help in getting started with python yourself and go from there.
Below a script that implements functionality 1: select 2 layers and find intersecting objects on first layer:

import rhinoscriptsyntax as rs


def SelectLayers():
    filter_layer = rs.GetLayer(title = 'select layer to filter by intersection')
    if not filter_layer: return None,None
    
    intersect_layer = rs.GetLayer(title = 'select layer with intersecting geometry')
    if not intersect_layer: return None,None
    
    return filter_layer,intersect_layer

def TestIntersection(obj,tester):
    # there are a few possible intersection methods in rhinoscriptsyntax
    # as an initial setup only a few intersections are handled
    # to make this script faster and more robuste best would be to intersect not with rhinoscriptsyntax
    # But use RhinoCommon methods instead.
    #
    #for now only rhinoscriptsyntax methods are used as an example below:
    
    # if both are breps ( (poly)surface or extrusion
    if rs.IsBrep(obj) and rs.IsBrep(tester):
        intersections = rs.IntersectBreps(obj,tester)
        if intersections : 
            #Delete intersections if they were made
            rs.DeleteObjects(intersections)
            return True

    if rs.IsMesh(obj) and rs.IsMesh(tester):
        intersections = rs.MeshMeshIntersection(obj,tester)
        if intersections : 
            #This method does not create a curve but returns a list of points
            #so nothing to delete
            return True
            
    #Mixed input needs to be handled different as is with curves.
    #if either is a mesh the other needs to be converted to a mesh as well
    
    #catchall return False
    return False
    
    
def Main():
    
    # run method to select 2 layers
    filter_layer,intersect_layer =  SelectLayers()
    if not filter_layer: return 
    
    # Get all objects on the layers (note that also hidden/locked are used)
    filter_objs = rs.ObjectsByLayer(filter_layer)
    intersect_objs  = rs.ObjectsByLayer(intersect_layer)
    
    # test if object on filter_layer intersects with any object on intersect layer
    intersecting_objs = []
    for obj in filter_objs:
        for tester in intersect_objs:
            # here the pseudo code is: does obj intersect with tester
            # I do not know the type of objects possible so
            # a more elaborate intersection methos is needed.
            if TestIntersection(obj,tester):
                intersecting_objs.append(obj)
                break #break out of for loop to prevent unneeded tests         
            
            
    if intersecting_objs:
        rs.SelectObjects(intersecting_objs)
    
Main()

Is this something that can get you started?

-Willem

1 Like

YAHA! Fantastic! This is exactly what I need, at least in part! Thank you Willem! Can I PayPal you some tip money for this? This is very helpful.