Moving an object from one point to another

My current script will place a block at the closest point on a line when given an input object. What I’d like to do is move the chosen object to that closest point instead of creating a new block reference and I feel like I’ve gotten pretty close in my attempts but I think coordinate systems are tripping me up.

Shouldn’t the vector I’ve created be translating the coordinates of the block towards the line as desired? It moves the block instead along a vector that seems to be equal to model space origin > new point, that is, it moves the block up and right instead of back and left. Is there a simpler way to set a blocks coordinates in the model space? I don’t seem to have as simple a method as is available for geometry via the Geometry.Transform node.

Hi
See this

Hi @glasnoct,

This explanation might help.

I saw that thread in my searches prior but the move is relative to the current location. How do I move the object to a specified model space coordinate or compute a coordinate system that results in moving the block to the model space coordinate? That was my attempt with the vector but it doesn’t produce the result I wanted.

You’d need to figure out the X and Y shift from the current location to the desired location and then create the transform coordinate system with the origin located at those coordinates.

Example:

Current location = (100, 100)
Desired location = (20, 20)
Origin of transform coordinate system = (-80, -80)

Thus the vector method I’ve been trying from the start, yes?

For future reference here’s the solution I came up with should someone else inevitably run into this conundrum:

  1. generate a vector from the beginning location and the destination
  2. create an “empty” CoordinateSystem
  3. translate the system by the vector and use the result as the input for the Object.Transform node

Seems a rather hacky solution to something I’d think would have an OOTB solution but as long as it works…

Yes, but I think the issue was that you were translating the coordinate system of the block reference to its desired location instead of creating a new coordinate system with the shift. Here’s an equivalent method of what you outlined above.

As a side note, the background of all of this is transform matrices, which is how objects are transformed programmatically in AutoCAD. Dynamo just uses a Coordinate System object to do the same thing.

2 Likes