Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Better way to collect objects created via rs.Command("Split")?

$
0
0

I am needing to use rhinoscriptsyntax to split a largish series of curves with some other objects. For various reasons it is too complex to script with RhinoCommon or rhinoscriptsyntax methods, so I am resorting to scripting the Rhino command - which works fine, but…

Getting the result of the scripted command involves invoking rs.LastCreatedObjects(). However, this returns a list of ONLY the objects actually split by the Split command. If there are objects that were not split, they are not included, even though they were selected as input to the Split command.

I need to have the result of the split operation plus anything originally selected but was not split. I have a way to do this, but it seems a bit of a kludge. Basically after the split, I run rs.IsObject on the original selection and grab any GUID that returns true - as the others have presumably been deleted when the originals were split. Just wondering if there is a better way is all… Below is just some test code.

import rhinoscriptsyntax as rs

lines=rs.GetObjects("Select lines",4,preselect=True)
pts=rs.GetObjects("Select points",1)

tg="Test_Group"
if not rs.IsGroup(tg): rs.AddGroup(tg)
rs.AddObjectsToGroup(pts,tg)

rs.SelectObjects(lines)
rs.Command("_Split -_SelGroup {} _Enter".format(tg))
rs.UnselectAllObjects()
to_select=rs.LastCreatedObjects(True)
print("Last created object count={}".format(len(to_select)))

for item in lines:
    if rs.IsObject(item):
        to_select.append(item)
        rs.SelectObject(item)
print("Total selected object count={}".format(len(to_select)))

Test file - split the lines with the points.
SplitTest.3dm (2.6 MB)

4 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles