Notifications
Clear all

[Closed] How to automate a close snapping?

When an object’s y position is close to a certain threshold, say just 0.5 (or adjustabe) apart from the ground level, I want to snap it down to 0, how do I write such script?
Thanks
Jack

7 Replies

Does this work

Utility CloseSnapping "Close Snapping" 
(
	Button snap "Snap" 
	
	on snap pressed do
	(
		
	   for i in 1 to selection.count do (
		  selection[i].pivot.y = 0.0
		  if (selection[i].pos.y < 0.5) then
			  selection[i].pos.y = 0.0 
		  
	   )
	)
)
  

The pos.y stuff doesn’t work.
Any ideas?
Thanks

I you place the pivot of your object to 0.0 on Y, the Y pos is then already placed to 0.0

Just delete “selection[i].pivot.y = 0.0”
Here is your working script :


  for i in 1 to selection.count do (
  		  if (selection[i].pos.y < 0.5) then
  			  selection[i].pos.y = 0.0
  	   )

Hi RicoZone,
I don’t know why the script doesn’t work as expected on my machine.
I just deleted the pivot point line, then deleted the if statement as well,
just set the current selection’s position to 30.0
But the object selected has no effect. It just stays as where it was.
Strange…
Thanks
Jack

Take care at your threshold value.
In your script : if value is less than 0.5 then the object moves to 0.0

If you want to move object greater than value 0.5, just invert the comparison “<” to “>”

or 
for i in 1 to selection.count do (
   			if (selection[i].pos.y > 0.5) then
   				selection[i].pos.y = 0.0
   		 )

Thanks RicoZone,
It works now.
But I need to set the pivot point at the lowest level of the object as a reference point.
Because the mesh will not sit in the middle of the center major grid line, it will
sit just right above it…hope you understand…
How do I set this up?

Hmm, BTW, can I set every object’s pivot position to the lowest part of it, lowest part means the vertex closest to 0 in the y-axis
Thanks
Jack

To place pivot to bottom of object :

obj.pivot = [obj.center.x, obj.center.y, obj.min.z]

more detail here :
http://forums.cgsociety.org/showthread.php?f=98&t=1188573

1 Reply
(@lucky6969c)
Joined: 10 months ago

Posts: 0

Ehh… That’s easy…
Thanks
Jack