samuelduchesne / pyumi

open and edit UMI projects with Python
4 stars 4 forks source link

open method does not add guid column #139

Open szvsw opened 2 years ago

szvsw commented 2 years ago

This is related to something in Umi for Rhino which is maybe a bug, but...

When you open a file in Umi and then save it, the features table in project.json gets overwritten, meaning original geojson data gets lost. There are some other problems with this which I will make a separate issue for.

Anyways:

When you call open on a an .umi file that was previously saved with Rhino, if you try to mutate parameters and then call update_umi_sqlite3(), the db update call falls because gdf_3m does not have a guid column.

The solution is to first add it based off the fid, as seen below adapted from what happens in the from_gdf method:

umi = UmiProject.open("umi_project_saved_with_rhino.umi")
def _try_add(series):
    obj = umi.file3dm.Objects.FindId(series[umi.fid])
    if obj:
        return obj.Attributes.Id
    else:
        raise KeyError(f"Could not find a rhino object")
umi.gdf_3dm["guid"] = umi.gdf_3dm.apply(_try_add, axis=1)

I think some variation of this should happen in the open classmethod so that the user is not responsible for it. All that you should need to do make updates to your umi project is update a column in the gdf and then call the db update fn (and the shoebox default settings fn, which maybe should be included in update_umi_sqlite3?).

So this would mean adding something like the following to the open method:

if "guid" not in self.gdf_3dm.columns:
   # create the guid column here

I can work on a pr to take care of this if you like.