about group reset xform

hi

i have a problem in working group.

i found group can not reset xform.
i would like to make resetxform about group.

example)

there is 100 groups.

my manual process.

1. ungroup
2. reset xform objects in group .
3. center pivot.
4. re group.

i would like to automate group .

thank you for reading .

Comments

Comment viewing options

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

...

fn resetXFormGroup obj convert:#poly = 
(
	local groupHead = if obj.parent == undefined and isGroupHead obj then obj
	else while obj.parent != undefined do obj = obj.parent
 
	if groupHead != undefined do
	(
		groupMembers = join #() groupHead
		if groupMembers.count > 0 do
		(
			geoMembers = for o in groupMembers where isKindOf o GeometryClass and canConvertTo o Editable_Mesh collect o
			if geoMembers.count > 0 do
			(
				resetXForm geoMembers
				case convert of
				(
					#poly: convertToPoly geoMembers
					#mesh: convertToMesh geoMembers
				)
			)
		)
	)
)

If you want to reset xform and convert all geometries to Poly use this line
 resetXFormGroup selection[1]
If you want to reset xform and convert all geometries to Mesh use this line
 resetXFormGroup selection[1] convert:#mesh

bga

dussla's picture

thank you for reply

hi barigazy .
really thank you for reply .
i test you rscript.
but there is problem
can you check attachef image

first image is manual work , that is good

but your image is still not .

pls can you compare file

AttachmentSize
xform.jpg 1015.78 KB
xform.max 5.02 MB
barigazy's picture

...

Object on top is the single object, you attached all elements and centralized pivot.
You didn't mention that.
The uilding on the bottom has multiple elements with offset pivot positions. My code only resets pivot orientation but not affect pivot position

bga

dussla's picture

i found this script and

i found this script and modified
but error

fn attachGroupMembers group = if isgrouphead group do
(
setGroupOpen group off
nodes = for node in (join #() group) where canconvertto node editable_poly collect node
converttopoly nodes

gname = group.name
explodeGroup group

for i = 1 to nodes.count do
(
centerpivot nodes[i]
ResetXForm nodes[i]
converttopoly nodes[i]
)

group nodes name:gname
)

for x in selection where (isgrouphead x) do
(
attachGroupMembers x

)

barigazy's picture

...

the problem is a bit more complicated when you need to consider nested groups
also, imported models from CAD sometimes have the same name. The code temporarily changes names of selected objects until calculation is done.

fn resetXFormGroup convert:#poly = if selection.count > 0 do
(
	mapped fn correctName node = (node.name = substring node.name 1 (node.name.count - 4))
	fn getChildrenNames list = (if list.count == 0 then #() else for c in list collect c.name)
	fn getNodeFrom list = for l in list where isValidNode (n = getNodeByName l) collect (n)
	fn getGroupHelpers list = (if list.count == 0 then #() else for g in list where isGroupHead g collect g.name)
	fn findParentGroup dict node = ((for k in dict.keys where findItem dict[k] node != 0 collect k)[1])
	local obj = selection[1] ; clearselection()
	local groupHead = if obj.parent == undefined and isGroupHead obj then obj else while obj.parent != undefined do obj = obj.parent
	if groupHead != undefined do
	(
		local groupKids = Dictionary #string, groupDummyKids = Dictionary #string
		local allGroupMebers = join #() groupHead, allGroupMeberNames = #(), cnt = 0
		local allGeoMembers = for o in allGroupMebers collect 
		(
			o.name += "_" + formattedPrint (cnt+=1) format:"0.3d" ; append allGroupMeberNames o.name
			if isKindOf o GeometryClass and canConvertTo o Editable_Mesh then o else dontcollect
		)
		local gh = groupHead.name
		for gm in allGroupMebers where isGroupHead gm do 
		(
			PutDictValue groupKids gm.name (getChildrenNames gm.children)
			PutDictValue groupDummyKids gm.name (getGroupHelpers gm.children)
		)
		if isOpenGroupHead groupHead do setGroupOpen groupHead off
		explodeGroup groupHead ; setInheritanceFlags allGeoMembers #none keepPos:on
		centerPivot allGeoMembers ; resetXform allGeoMembers
		case convert of
		(
			#poly: convertToPoly allGeoMembers
			#mesh: convertToMesh allGeoMembers
		)
		setInheritanceFlags allGeoMembers #all keepPos:on
		while (groupNoKids = for k in groupDummyKids.keys where k != gh and groupDummyKids[k].count == 0 collect k).count > 0 do
		( 
			for g in groupNoKids do
			(
				group (getNodeFrom groupKids[g]) name:g ; RemoveDictValue groupKids g ; RemoveDictValue groupDummyKids g
				p = findParentGroup groupDummyKids g
				groupDummyKids[p] = deleteItem groupDummyKids[p] (findItem groupDummyKids[p] g)
			)
		)
        group (getNodeFrom groupKids[gh]) name:gh ; RemoveDictValue groupKids gh ; RemoveDictValue groupDummyKids gh
	)
	correctName (getNodeFrom allGroupMeberNames) ; free groupKids ; free groupDummyKids ; free allGroupMebers ; free allGroupMeberNames 
)

You don't need to open the group, just select a closed group or any object (member) of the group and run the code
If you want objects to be converted to poly, just use this line of code
resetXFormGroup
For mesh output use this line
 resetXFormGroup convert:#mesh

bga

barigazy's picture

...

Or you can download

*.mcr

from here ;)

bga

dussla's picture

wow wow perpect

thank you for your effor .
really really thank you .

perpect

1 more question .

manysel = selection
clearselection()
for x in manysel where (isgrouphead x) do
(
select x
resetXFormGroup x convert:#mesh

)

this is error

i have a 300 group.
how can i do that ?

sorry for many ask.

really reall thank you.

barigazy's picture

...

select all 1000000 groups in your scene and group it. run the script and after it done, open group and delete group head

;)

bga

dussla's picture

Wow wow thank thank you

Wow very good idea
I am stupid man :)

Really really thank you
Really really

barigazy's picture

...

No problem.

Enjoy!

I didn't test it with larger scenes like yours, so if you come across some problems, please let me know

bga

Comment viewing options

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