I have a fence line that is at 45degrees to the green axis and I have multiple objects on that plane and I now want to align all of them to the fence by moving them along the red axis until they touch the line. Is there a script or plug in that will do this?
Its a simplified variation on the optimum packing problem.
Hello, there are a few align plugins available such as fredo6’s Mam or curic align but I’m not sure they would allow aligning to an edge and I don’t have my computer to try it out. Maybe curic align would do if you first change your axes according to your line
There’s a way that I think would work, although tricky.
You’ll need the dropGC plugin (free)
And now comes the tricky part : turn your 45° line into a vertical plane (tall enough and deep enough to cover up all the items it needs to ‘catch’) select everything and rotate 90 degrees locking the rotate tool onto green. (Anticlockwise if with the same point of view than your screenshot) Then select all groups or components you want to align and use the dropgc plugin.
Rotate everything back 90 degrees.
Perhaps someone will think of another plugin that would do it with more ease - without having to rotate the whole thing - but that’s all I’m thinking of right now
dropGC does give the sort of behaviour i’m after but it would be so much better if i didn’t need to change the axis. I would also prefer to use a 2d line as opposed to a plane.
If this can’t be done then your idea migh be my best option.
For me it would be a key function to automate this as I have to do it manually in every Sketchup project I create.
Would it be a complicated script? I’m failry proficient coder on other platforms but never Ruby. I know it can be hard to quantify but I could try to do it myself or commission someone to do it for me, just trying to get a feel for the effort involved.
This code seems to work. (If there’s nothing between the line and groups or components)
#moves each group or component instance in selection
#to the closest point in red axis direction
module Rtches
module RayTest
model = Sketchup.active_model
model.start_operation('Movement', true)
sel = model.selection
sel.each do |s|
if s.respond_to? (:definition)
point = s.bounds.corner(0)
ray = [point, Geom::Vector3d.new(-1, 0, 0)]
item = model.raytest(ray, false)
new_transformation = Geom::Transformation.new(item[0])
#s.move!(new_transformation)
s.transformation = new_transformation
end
end
model.commit_operation
end
end
Rtches::RayTest