"Group with no dialog" script problem

hi
here is simple script which group object without naming dialog and with pivot at the bottom. nice one. but it just after grouping press undo it put selected objects down
why it happens and how to fix?

(
on isenabled return selection.count>1
on execute do (
local grname=selection[1].name
local grhead
if selection.count >1 do group selection name:(grname + "_01")
select $(grname + "_01")
for i in selection where (isgrouphead i) do
i.pivot = [($.max.x+$.min.x)/2, ($.max.y+$.min.y)/2, $.min.z]
)
)

thank you in advance

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
harumscarum's picture

same config. but do you Undo

same config.
but do you Undo right after Group? i mean problem is only if i group by mistake and want to undo this operation.

Arahnoid's picture

You are right

If I created 3 objects after grouped them and created a new object. After undo ungrouped objects fall down

I have deleted from script last 2 lines and second local variable. To be honest I didn't get why you need to change something in pivot after grouping :( perhaps this line of code make this problems.

This code works as I expected

(
  on isenabled return selection.count>1
  on execute do 
  (
    local grname=selection[1].name
    undo on
    (
      if selection.count >1 do group selection name:(grname + "_01")
    )
    select $(grname + "_01")
  )
)
harumscarum's picture

undo was working with source

undo was working with source script, but after undo all objects are dropping down. i guess because of pivot replacement

Arahnoid's picture

Strange

For me script works fine. After undo all objects remain in the same place
Win7x64, Max 2012 x64 (not Design version)

Arahnoid's picture

Hello harumscarum

I'm not sure if I've understand you right but if you want to have a undo for grouping you can add "undo on" in you script and it will allow to undo grouping
By the way great and usefool script :)
------------------------------------------------------------------------------

(
  on isenabled return selection.count>1
  on execute do 
  (
    local grname=selection[1].name
    local grhead
    undo on
    (
      if selection.count >1 do group selection name:(grname + "_01")
      select $(grname + "_01")
      for i in selection where (isgrouphead i) do
      i.pivot = [($.max.x+$.min.x)/2, ($.max.y+$.min.y)/2, $.min.z]
     )
  )
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.