Import 3dm or stl and return new nodes

Is it possible to run a python command to import a scene, (file type doesn’t really matter) and after import get a list of the new nodes?

I have used rs.Command("_-Insert {path} Objects Enter 0,0,0 1 0".format(path=path))
However to my knowledge that just returns Success or Fail.

Hi @hantic,

Here is the pattern I use to get what was added to the document:

import System
import Rhino
import scriptcontext as sc

def test_import_ply():
    
    path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
    filename = System.IO.Path.Combine(path, "test.ply")
    filename = chr(34)+ filename + chr(34) # double-quote
    
    # Get the runtime serial number of the next RhinoObject to be be created
    start_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
    
    Rhino.RhinoApp.RunScript("_-import " + filename + " _weld=_yes _weldangle=22.5 _splitdisjointmeshes=_yes _modelunits=_millimeters _enter", True)
    
    # Get the runtime serial number of the next RhinoObject to be be created
    end_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
    
    rh_objects = []
    for sn in range(start_sn, end_sn):
        rh_obj = sc.doc.Objects.Find(sn)
        if rh_obj:
          rh_objects.append(rh_obj)
    
    for rh_obj in rh_objects:
        print(rh_obj.ObjectType)

if __name__ == "__main__":
    test_import_ply()

– Dale

Awesome, thank you! This is perfect