ScriptSpot

Forum topic · General Scripting

attach by geometry name

By short_cirkuit · 2024-09-19

Description

Hi guys can someone kindlt help me do a script that attachs by geometry name?

Comments (1)

Hi,

SimonBourgeois · 2025-02-09

this script will attach all objects that share the same name if they can be converted to poly. if you need it to work only on selected objects just replace "objects" by "selection" in line : " local objs = for o in objects where canConvertTo o Editable_Poly collect o"


(
	fn clusterAttach objArr =
	(
		j = 1
		
		while objArr.count > 1 do
		(                
			if isvalidnode objArr[j] and classof objArr[j] != Editable_Poly do converttopoly objArr[j]
					
			polyop.attach objArr[j] objArr[j+1]
			deleteItem objArr (j+1)
					
			j += 1
					
			if (j + 1) > objArr.count do j = 1
		)
		
		centerpivot objArr[1]
		return objArr[1]
	)
	fn Arraybyname Arr currentName = 
	(
		local outArr = #()
		for o in arr where isvalidnode o and o.name == currentName do append outArr o
		return outArr
	)
	fn getUniqueNames objArr = 
	(
		local nameSet = #()
		for o in objArr where isvalidnode o do
		(
			appendIfUnique nameSet o.name
		)
		return nameSet
	)
	undo "Attach by name" on 
	(
		max create mode
		with redraw off
		(
			
				local objs = for o in objects where canConvertTo o Editable_Poly collect o
				local uniqueNames = getUniqueNames objs

				for name in uniqueNames do
				(
					tmpArr = Arraybyname objs name
					if tmpArr.count > 1 do
					(
						clusterAttach tmpArr
					)
				)
			
		)
		redrawViews()
	)
)