ScriptSpot home

Forum topic · General Scripting

Mesh Attach Question

By Andrew Chooj · 2015-12-09

Description

For example I have a lot of meshes named "left" - left001, left002, left003.... left 099. And the same number of meshes called "right", from 001 to 099. (All meshes have modifiers). And I want to mesh-attach them in pair according the index - left001 with right001, left002 with right002... etc. How should I do this?

Comments (6)
pixamoon

`

try something like this:


(
	a_From = 1
	a_To = 99
	
	a_basename1 ="left"
	a_basename2 ="right"
	
	a_resultname ="left-right"
	
	for i = a_From to a_To do (
		local n3d = (formattedPrint i format:"03d")
		a1 = getnodebyname (a_basename1 + n3d)
		a2 = getnodebyname (a_basename2 + n3d )
		if a1 != undefined and a2 != undefined do (
			convertToMesh a1
			attach a1 a2
			--meshop.attach a1 a2 targetNode:a1
			a1.name = a_resultname + n3d
		)
	)
)
Reply to pixamoon
Andrew Chooj

Thanx, I'll try this code! And what if the nunber of meshes is different every time? Sometimes it's 025, and sometimes it's 125?

Reply to Andrew Chooj
pixamoon

`

just change a a_To = 125 or maximum

code also recognize no pair - and will skip that object

so if you change a_To = 999 - it should attach all found left and right pairs till 999

hope this makes sense

Reply to pixamoon
Andrew Chooj

Yes! Its working! Thanx again. But I've changed mesh-attach to poly-attach bacause of strange issue with normals, one of the objects was flipped every time. Now working fine!