I’m writing a script that selects all objects with a certain name, and exports the selected objects with an origin based upon a bounding box of said objects.
The part where I’m struggling with is the last step - what method is there to ‘Export Selected with Origin’ as it were?
import rhinoscriptsyntax as rs
import os
rs.EnableRedraw(False)
# Get all objects
objs = rs.AllObjects(select=True)
# Create an empty list of names to add unique names to
namedelements = []
# Check if any objects were selected
if objs:
for obj in objs:
# Get the name of each object
name = rs.ObjectName(obj)
if name:
namedelements.append(name) if name not in namedelements else namedelements
else:
print("No objects selected.")
# Create a bounding box around each named set of objects, in order to create a new origin with which to export to (X and Y only... Z remains the same as world Z)
grouped = rs.ObjectsByName(name)
bounding_box = rs.BoundingBox(grouped)
if bounding_box:
brep = rs.AddBox(bounding_box)
min_point = bounding_box[0] # The minimum corner
max_point = bounding_box[6] # The maximum corner
centre = [(min_point[0] + max_point[0]) / 2,
(min_point[1] + max_point[1]) / 2,
(min_point[2] + max_point[2]) / 2]
filepath=r'"C:\{}.3dm"'.format(name)
ip = rs.coerce3dpoint([centre[0], centre[1], 2])
rs.Command('_-ExportWithOrigin {} {}'.format(ip,filepath))
rs.EnableRedraw(True)
Any help greatly apprecaited.
Working on Rhino 7 & Python 2.7