Hi @stevebaer,
today a was trying to do what is described in the OP. I have an object id and a file path to a Rhino file. I want to import only the object using the id and import it along with it’s attributes (Layer, Color etc) in my currently opened Rhino 5 file. After loading the file like this:
f = Rhino.FileIO.File3dm.Read(file_name)
it seems i cannot search the object table of my file for the object id using f.Objects.Find(obj_id)
. So i iterate over the object table of the file, one by one, check if it matches my obj_id
and import the geometry along with its attributes using:
for i in xrange(f.Objects.Count):
obj = f.Objects.Item[i]
if obj.Attributes.ObjectId == obj_id:
geo = f.Objects.Item[i].Geometry
attr = f.Objects.Item[i].Attributes
scriptcontext.doc.Objects.Add(geo, attr)
However, this does not create the layer the object was placed on. The object is imported on the layer which is having the same index as the one defined in the object attributes.
If i iterate over f.Layers
in the file, which is an File3dmLayerTable
(does not appear in the RhinoCommon docs yet), i can use the layer index of the object attributes to find the layer name the object is on. I thought i then can just get the layer path from the layer in the file and create the layer myself in the opened Rhino file, then get the index and add the object i want to this layer.
But i have no idea how i easily can get the full layer path for this layer. If my object layer is nested below multiple other layers in the file, i need to get all its parent layer(s). To get the first parent of the layer i got from the LayerIndex
of the object attributes i can use this:
layer = f.Layers[attr.LayerIndex]
parent_layer_id = layer.ParentLayerId
i cannot search for other parents of the parent_layer_id
. It seems that the Find
method which is available for an opened documents layer table is not available for the File3dmLayerTable
. I tried it like so:
f.Layers.Find(parent_layer_id, True)
which tells me: ‘File3dmLayerTable’ object has no attribute ‘Find’
To get the full layer path of a layer in an opened doc, i normaly would use this:
path = layer.FullPath
But this returns just the layer name, not the full path. My layer is a sub layer. I think this is a bug. I see there has been a similar report for a related issue on Mac. Is this supposed to work on Rhino 5 windows ?
EDIT: In V6, the full path is returned…but there are other problems iterating the obj table…
_
c.