Move imported geometry to a specific point in space macro

Dear All,

Is there a way to move a selection from it’s bounding box center to a fixed point which is not the world origin?

I have repetitive tasks whereby I import .dwg files which are often far from the rhino origin. I run this macro to select them and move them to World 0:

"
_SelAll
ZS
_Move
_Pause
_Pause 0
ZS
"

Problem is I have to manually select the point from which to move the geometry and, once the macro is complete, I still have to move them to another point manually. Can this be achieved with a Macro or is it a job for a script?

Thank you!

This script should help…
MoveObjsCtrToPickPoint.py (541 Bytes)

Perhaps I haven’t explained myself clearly.

What I’d wish is for a script is to:

  1. Select all the geometry.
  2. Automatically instantiate a move operation automatically picking the point to move from as the geometry’s bounding box center.
  3. Automatically move said geometry to the world origin.

OK, I misunderstood your initial request as wanting to move your objects from their combined bounding box center to a picked point, not world 0. Here is a simple script for moving to world 0.

MoveObjsCtrToW0.py (444 Bytes)

I have modified it so that the script also automatically selects all visible objects, however it also moves locked objects for some reason.

"!_-RunPythonScript (

“”“Simple script to move selected objects from their bounding box center to W0.
Script by Mitch Heynick 05.12.22 MODIFIED”“”

import rhinoscriptsyntax as rs

def MoveObjsCtrToW0():
objs=rs.VisibleObjects(view=None, select=False, include_lights=False, include_grips=False)
if not objs: return
orig=rs.coerce3dpoint([0,0,0])
bb=rs.BoundingBox(objs)
bb_ctr=(bb[0]+bb[6])/2
rs.EnableRedraw(False)
rs.MoveObjects(objs,orig-bb_ctr)
MoveObjsCtrToW0()

)

Use rs.NormalObjects() instead of rs.VisibleObjects().

MoveNormalObjsCtrToW0.py (486 Bytes)

Hello,

Thank you. However, despite my efforts in trying to fix it, the script still does not move geometry to world 0.

There’s nothing to ‘fix’ as far as I can see - it works here.

Unless you are looking for each individual object to be moved from it’s bounding box center to World 0 rather than the combined bounding box of all of the objects. Again, your explanation is not clear. The script below will do that.

MoveNormalObjsEachCtrToW0.py (525 Bytes)

I am indeed trying to move multiple object to world 0 keeping their structure.

However this happens:

Your last script does indeed work, but, as expected, puts every single object at 0.

EDIT:

I believe there may be a block instance with a basepoint far in the distance. I cleared everything up and retried the script from earlier, getting this message:

I remember seeing that issue a while back, just can’t seem to find it.
Alternatives:

import scriptcontext as sc
sc.doc.Views.EnableRedraw(False, False, False)
rs.EnableRedraw = False

bool is not callable' for rs.EnableRedraw()

Bizarre, I have never seen this one before…

looks like @Gijs has though…

Funny that the last script works, but the previous ones don’t though. They all have the same line.

@nicolocostan99 Are you working in Rhino 7 only when this failed?

A Pc reboot fixed the issue, weird. Anyhow, even if after having exploded all blocks and having reset the model basepoint manually to 0, the objects still do not move to W0. They behave exactly the same as shown in the pictures above. What may be the problem?

@Gijs

@nicolocostan99 Are you working in Rhino 7 only when this failed?

Yes I am

Can you post a sample file where it does not work for you? At least that way someone here can test/analyze.

Sample-file_W0py.3dm (1.2 MB)

On your posted file above, the script works correctly here.

rs.NormalObjects() will take all selectable objects and the script will calculate the collective bounding box of those. What you maybe have is a selectable point at the origin? That gets included in the collective bounding box calculation. .

This is the danger of using a script that automatically selects all selectable objects - you might have something in there - maybe even far off in space somewhere - that you haven’t realized is there and gets selected too.