ScriptSpot

Forum topic · General Scripting

pivot

By artrender.info · 2013-06-03

Description

I know there are a lot of scripts for centering of the object pivot point, but it is so confusing which of them to download and use! I use now only 2 options putpivotcenter(SHIFT+P) and putpivotbottom(CTRL+P) from soulburnscript! But putpivotbottom doesn't put the pivot on the bottom if for example I created the object(let's say a box) in the front view, for example!

May be you could advise any that really work and easy to use! Thx friends!

Comments (19)

artrender.info · 2013-06-07

But I have an idea, how to make it work for groups! I will do it next week, because tomorrow morning I need to travel!

tassel · 2013-06-07

This don't work with groups, but this is something i made last year to a former work colleague. Just thought it might be useful for someone searching for pivot stuff.


-- Pivot Placer V1.0 - By Raymond H.Ingebretsen'2012

try(destroyDialog ::roll_pivottools)catch()

rollout roll_pivottools "Pivot Placer V1.0"
(
	-- UI Stuff!!!
	group "Place Pivot Z-Direction:"
	(
		button btn_CenterTopZ "Top Y" width:45 height:20 across:3
		button btn_CenterMiddleZ "Mid Y" width:45 height:20 
		button btn_CenterBottomZ "Bot Y" width:45 height:20 
	)
	
	group "Place Pivot X-Direction:"
	(
		button btn_CenterSideX "Side X" width:45 height:20 across:3
		button btn_CenterMiddleX "Mid X" width:45 height:20
		button btn_CenterSideOppositeX "Op.s X" width:45 height:20
	)
	
	group "Place Pivot Y-Direction:"
	(
		button btn_CenterFwdY "Fwd Y" width:45 height:20 across:3
		button btn_CenterMiddleY "Mid Y" width:45 height:20
		button btn_CenterAftY "Aft Y" width:45 height:20
	)
	
	
	-- Pivot in Z-Direction Top, Middle and Bottom
	on btn_CenterBottomZ pressed do
	(
		selection.pivot = [selection.center.x,selection.center.y,selection.min.z]
	)
	
	on btn_CenterMiddleZ pressed do
	(
		selection.pivot = [selection.center.x,selection.center.y,selection.center.z]
	)
	
	on btn_CenterTopZ pressed do
	(
		selection.pivot = [selection.center.x,selection.center.y,selection.max.z]
	)
	
	
	-- Pivot in X-Direction Side, Middle and Opposite
	on btn_CenterSideX pressed do
	(
		selection.pivot = [selection.min.x,selection.center.y,selection.center.z]
	)
	
	on btn_CenterMiddleX pressed do
	(
		selection.pivot = [selection.center.x,selection.center.y,selection.center.z]
	)
	
	on btn_CenterSideOppositeX pressed do
	(
		selection.pivot = [selection.max.x,selection.center.y,selection.center.z]
	)
	
	
	-- Pivot in Y-Direction Fwd, Middle and Aft
	on btn_CenterFwdY pressed do
	(
		selection.pivot = [selection.center.x,selection.min.y,selection.center.z]
	)
	
	on btn_CenterMiddleY pressed do
	(
		selection.pivot = [selection.center.x,selection.center.y,selection.center.z]
	)
	
	on btn_CenterAftY pressed do
	(
		selection.pivot = [selection.center.x,selection.max.y,selection.center.z]
	)

)

createDialog roll_pivottools height:155 width:170 pos:[200,250]
-- // EOF

artrender.info · 2013-06-07

it's very nice and easy to use!

tassel · 2013-06-07

I see i have a typo after renaming the buttons, you have to rename the Pivot Z-Direction buttons. :)

artrender.info · 2013-06-07

undefined
-- Error occurred in anonymous codeblock; filename: E:\Soft\scripts\x\Textures\; position: 54; line: 3
-- Unknown property: "transform" in undefined
-- Error occurred in anonymous codeblock; filename: E:\Soft\scripts\x\Textures\; position: 73; line: 4
-- Unknown property: "dir" in undefined
-- Error occurred in anonymous codeblock; filename: E:\Soft\scripts\x\Textures\; position: 120; line: 5
-- Runtime error: Invalid coordsys context: undefined
-- Error occurred in anonymous codeblock; filename: E:\Soft\scripts\x\Textures\; position: 155; line: 6
-- Frame:
-- No ""get"" function for undefined

barigazy · 2013-06-07

Hey Mike
This is the example not final code. Try in the listener to play

artrender.info · 2013-06-07

aa, ok, in fact I'm trying allways in the listener, little by little - first

delete $'Point*'
grp = $Group001
tm = grp.transform
grp_dir = grp.dir
lbb = in coordsys tm nodeLocalBoundingBox grp
pivot_center_pos = ((lbb[1]+lbb[2])/2)*tm

with a selected object and group, but I took this error, that's why! Srry, may be I was a little confused!

barigazy!

artrender.info · 2013-06-07

I don't understand, last time


obj = selection[1]
obj.pivot = [obj.center.x,obj.center.y,0] -- bottom position

was working for my groups, today it doesn't! Except this, it places the pivot at 0, but if my group is above or under 0?

barigazy · 2013-06-07

my bad.

-- this works in world coord system
obj = selection[1]
obj.pivot = [obj.center.x,obj.center.y,obj.min.z]
-- for node (local) coord system is other story :)

...the story continues

barigazy · 2013-06-07

Let say we have "Group001"
Now for if you change position rotation or scale of it then try this example

delete $'Point*'
grp = $Group001
tm = grp.transform
grp_dir = grp.dir
lbb = in coordsys tm nodeLocalBoundingBox grp
pivot_center_pos = ((lbb[1]+lbb[2])/2)*tm
pivot_bottom_pos = (pivot_center_pos - (((abs(lbb[1]-lbb[2]).z)*grp.scale/2)*grp_dir))
pivot_top_pos = (pivot_center_pos + (((abs(lbb[1]-lbb[2]).z)*grp.scale/2)*grp_dir))

point name:"PointBottom" pos:pivot_bottom_pos dir:grp_dir cross:off axistripod:on size:10 wirecolor:blue
point name:"PointCenter" pos:pivot_center_pos dir:grp_dir cross:off axistripod:on size:10 wirecolor:red
point name:"PointTop" pos:pivot_top_pos dir:grp_dir cross:off axistripod:on size:10 wirecolor:yellow

fajar · 2013-06-07

I wonder how i can put/set my group pivot at the center bottom, like barigazy script ?
does anyone know how to do that?

:)

barigazy · 2013-06-07

Come on fajar don't tell me you never try this :)

selection.pivot = [selection.center.x,selection.center.y,0]

but

artrender.info · 2013-06-03

I guess there was a way to check if an object needs to be applied reset xform, yes?
Will this also work for groups?

haha! yes, very easy!

artrender.info · 2013-06-03

In fact, I need only bottom pivot and middle! Thx for your answer!

barigazy · 2013-06-03

Even easyer. Come on you can do it better :)

obj = selection[1]
obj.pivot = obj.center -- center position
obj.pivot = [obj.center.x,obj.center.y,0] -- bottom position

hm

artrender.info · 2013-06-03

selection[1] is for the first object from selection, but this does not mean that this will be in the center of group, for example

thx

artrender.info · 2013-06-03

for reset xform, it really helped! Now my question is answered! You know a lot, Barigazy!

barigazy · 2013-06-03

You ask easy questions :)
Try the code that i send you in PM. You can easely collect all 27 positions for the pivot placement. Then you can create dropdown list or buttons that help you to send object pivot in right place of bbox.

barigazy · 2013-06-03

If you have been created object in front view then you need to reset xform to be able to use theses scripts again. I send you one example.