Hey All,
I’ve been working with Rhino for a bit now, but it seems that there isn’t a way to place an imported file at the specified coordinates by default. I created this python script to bridge that gap, specifically for DXF imports in my case.
This will allow you to import a file, but before it does so it will ask you to pick coordinates. I plan to expand upon this simple tool, but it works well for my purposes. The viewport view is maintained after import as well. Speeds up my workflow quite a bit.
import rhinoscriptsyntax as rs
def import_to_point():
# Suspend viewport redraw
rs.EnableRedraw(False)
# Save the current view's name
original_view_name = rs.CurrentView()
# Save the current view state to a temporary named view
temp_view_name = "TempImportView"
rs.AddNamedView(temp_view_name)
# Prompt the user to pick a point
target_point = rs.GetPoint("Pick a point to place the imported file")
if not target_point:
return
# Ask the user for the file to be imported
filter = "All Files (*.*)|*.*||"
filename = rs.OpenFileName("Select file to import", filter)
if not filename:
return
# Import the file using the Rhino command
result = rs.Command('_-Import "{}" _Enter'.format(filename), False)
if not result:
print("Failed to import the file.")
return
# Find all objects created after running the import command
imported_objects = rs.LastCreatedObjects()
if not imported_objects:
print("No objects were imported.")
return
# Move the imported objects to the specified point
rs.MoveObjects(imported_objects, target_point)
# Restore the original view state from the named view
rs.RestoreNamedView(temp_view_name)
# Restore the original view's name
rs.RenameView(temp_view_name, original_view_name)
# Delete the temporary named view
rs.DeleteNamedView(temp_view_name)
# Enable viewport redraw
rs.EnableRedraw(True)
if __name__ == "__main__":
import_to_point()
Create an Alias or Button to trigger it and you’ve got quick imports.