FileObj.Read how to get imported objects or ids?

Hi @dale,

i’ve used Rhino.FileObj.Read to import an obj file. So far the meshes come in but how do i get the objects or object ids after reading ? The method just returns a boolean. I’ve tried rs.LastCreatedObjects() but this returned an empty list. Any hints ?

_
c.

Hi @clement,

The rs.LastCreatedObjects method only works when scripting Rhino commands using rs.Command.

Perhaps you can post some code that isn’t working the way you want and we can help?

– Dale

Hi @dale,

please see the example file below. The file_path needs to be adjusted to test:

Example.py (812 Bytes)

For now i get all obj ids before the import and compare with the ids after import. Is there maybe a less expensive way to find the imported objects ?

_
c.

Hi @clement,

How about this?

import Rhino
import scriptcontext as sc

def ImportObj(file_path_name):
    read_options = Rhino.FileIO.FileReadOptions()
    read_options.BatchMode = True
    read_options.ImportMode = True
    obj_options = Rhino.FileIO.FileObjReadOptions(read_options)
    obj_options.MapYtoZ = False
    
    sn_start = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
    
    rc = Rhino.FileIO.FileObj.Read(file_path_name, sc.doc, obj_options)
    if not rc: 
        print "Failed to import file"
        return
    sc.doc.Views.Redraw()
    
    sn_end = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
    
    new_ids = []
    for sn in range(sn_start, sn_end):
        rh_obj = sc.doc.Objects.Find(sn)
        if rh_obj:
            print(rh_obj.Id)
            new_ids.append(rh_obj.Id)
    return new_ids

file_path = r"C:\Users\Dale\Desktop\test.obj"
ImportObj(file_path)

– Dale

1 Like

Hi @dale, thank you. This is effective.
_
c.