Import Multiple DXF so that they do not overlap

One of our customers would like to import multiple DXF files into a single Rhino Document using Drag and Drop.

The current Rhino 7 behaviour when you drop and select “Import” will leave all of the geometry overlapping as shown below which is understandable as a developer but not as a user.

Could anyone suggest a method I could use to “catch” the import of the new geometry and scoot it over in the X direction so it doesn’t overlap.
I have handled the EndOpenDocument event but I am not sure which is the “new” geometry in the document and which is the old?

I could write a script to allow the user to select multiple files then import and move the geometry in the X. However the customer is (unfortunately!) quite set on using drag drop hence my conundrum and reaching out to you experts!

Test dxf files attached.

multi-dxf.zip (35.4 KB)
image

Hi @david.birch.uk ,
you can get the “most recent object” in the object table by using ObjectTable.MostRecentObject(). You can store the runtime serial number of the object. And then in the “EndOpenDocument” event handler, you can get the newly added objects by using ObjectTable.AllObjectSince() method.

Something like this:

            RhinoObject mostRecentObj = doc.Objects.MostRecentObject();
            uint recentObjSerialNumber = mostRecentObj.RuntimeSerialNumber;

            void OnEndOpenDocument(object sender, DocumentOpenEventArgs e)
            {
                RhinoObject[] newAddedObjects = doc.Objects.AllObjectsSince(recentObjSerialNumber);
                recentObjSerialNumber = doc.Objects.MostRecentObject().RuntimeSerialNumber;
            }
1 Like

Thank you @Darryl_Menezes That is a very neat trick.

How could i know when the Drag Drop event starts? e.g. i need to run your first two lines of code to get the Most RecentObject Prior to the loading of the first DXF file - is that right?

@david.birch.uk the RhinoDoc.BeginOpenDocument event is triggered, so you can subscribe to it and set the recent object in the handler.

            void OnBeginOpenDocument(object sender, DocumentOpenEventArgs e)
            {
                mostRecentObj = doc.Objects.MostRecentObject();
                recentObjSerialNumber = (mostRecentObj != null) ? mostRecentObj.RuntimeSerialNumber : 0;
            }
1 Like

Excellent! I will put this into practice

Really appreciate the help Darryl

1 Like