Random move components?
-
Is there a plugin which can move components (or groups) randomly in a given direction? I have a lot of components in a model which I like to move slightly up or down, but each of them differently far (or at least with great diversion). So if there is something like that or something similar with which I can achieve this goal without having to position them all manually, please tell me. If not, maybe someone can make a plugin which can do this? I imagine being able to give a range in which the object shall be moved (for example between 0 and 1m, also allowing negative values for reverse movement) and then specify the axis on which this movement shall happen. It is not important for my project but maybe it would be possible to choose even two or all three axes, in which case the object would be placed somewhere within a specific 2- or 3-dimensional aream, depending on the distance values. I think it might be useful to have something like that in certain occasions.
-
I needed something similar, so I threw together this one-liner. First ruby code I've ever written, so I'm sure it's possible to make it more elegant.
Sketchup.active_model.selection.each do |block| block.transform!(Geom;;Transformation.translation(Geom;;Vector3d.new(0,0,3*rand(6)))) end
As written, it takes each component in the selection, and moves it a random multiple of 3 between 0 and 18 along the Z axis.
-
Hi thanks for the code sniped
I learned how to ask for a random coordinate.
I am kind of using a variation of this but with the method “move!” for a game I am trying to make. Here is the thread… http://forums.sketchucation.com/viewtopic.php?f=180&t=48043
-
Scale and rotate Multiple by Chris Fullmer ?
-
This little code (slightly changed for my purpose) worked nicely for me, thanks a lot !
But to go a step further ... does anybody know how to randomly rotate elements in a similar way ? i've tried a Geom::Transformation.rotation but as it's my first try in ruby, i've no idea of whats going wrong
-
@eram said:
does anybody know how to randomly rotate elements in a similar way ?
Rotation requires a point, a vector, and an angle. The point + vector tells us the axis of rotation. Do you want to rotate objects around the origin? Around their "center"? (Which center? Orthocenter? Center of gravity? Something else?) Do you want to rotate just around the Z axis (like spinning a top) or some other random axis (like rolling a bowling ball with side spin)?
This will get you rotation around the Z access at the origin by a random angle:
Sketchup.active_model.selection.each do |block| block.transform!(Geom::Transformation.rotation(Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0,0,1), rand(2*Math::PI))) end
-
Hi!
I applied the script by Snoyes but it certainly creates an undo stack - quite big when I randomly move lots of entities. I know that ThomThom once wrote an article about keeping undo stack clean:http://www.thomthom.net/thoughts/2014/06/sketchup-extensions-ux-dont-break-undo/
but I don't know how to apply it to a certain operation. How would this script look with ThomThom's improvement?
By the way, this could be a plugin request. I didn't find any plugin, neither free nor commercial, to randomly move a bunch of entities. E.g. you choose minimum and maximum move and axes to move along.
-
Ok, I resolved that by myself. I should have used Ruby Code Editor instead of Ruby Console.
Advertisement