select or link near objects

Hello everybody,

I'm looking for a script for the following problem:

You select an object and look for close by objects. The objects can be linked or just selected. So for each vertex of the selected object look if there is a objects pivot point close by (with a threshold) if yes, select this object.

Scenario: You have a branch of a tree with leaves. Everything is detached to individual objects. (see attachment)

Thanks in advance!

AttachmentSize
1.jpg60.76 KB

Comments

Comment viewing options

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

.

Run the code below:
Use the [Pick Objcet] button to pick the object to which you will compare all other objcets.
Set the threshold value in the spinner.
Press the [Find nearest objcets] button.
In the maxscript listener will be printed the index of the vertex and the nearest object.
If you want nearest object to be moved to the closest vertex turn on the checkbox.

(
	global rol_miauu
	try(destroyDialog rol_miauu)catch()
	rollout rol_miauu "miauu"
	(
		local mainObj = undefined
 
		pickbutton pbtn_pickObj "Pick object" width:140
		spinner spn_threshold "Threshold" range:[0,1e9,20] type:#worldunits
		checkBox chkBox_moveObjToVert "Move objects to vert"
		button btn_selectNearest "Find nearest objcets" width:140
 
		on pbtn_pickObj picked obj do
		(
			if classOf obj == Editable_Poly do
				mainObj = obj
		)
 
		on btn_selectNearest pressed do
		(
			if mainObj != undefined do with undo on
			(
				objsArr = for o in objects where o != mainObj collect o
				thresh = spn_threshold.value
				vertsBA = #{1..(mainObj.numVerts)}
 
				pairsArr = #()
 
				for v in vertsBA do
				(
					vPos = polyop.getVert mainObj v
					for i = objsArr.count to 1 by -1 where ((distance vPos objsArr[i].pos) <= thresh ) do
					(
						append pairsArr #(v, objsArr[i])
						if chkBox_moveObjToVert.checked do 
						(
							objsArr[i].pos = vPos
						)
						deleteItem objsArr i
					)
				)	
				if pairsArr.count != 0 do
				(
					print pairsArr	
				)	
			)
		)
	)
	createdialog rol_miauu
)

Comment viewing options

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