ScriptSpot

Forum topic · General Scripting

Select Every Other Component of Selection

By biglittlepictures · 2020-02-11

Description

Currently I have a script to select every other object in a selection, it works well.

skipThisOne = 0
selectEveryOtherObject = #()
these = Selection as array
for thisObject in these do (
if skipThisOne == 0 do (appendIfUnique selectEveryOtherObject thisObject)
skipThisOne = abs (skipThisOne - 1)
) --end thisObject in these
select selectEveryOtherObject

I'd like to make it also work with subobjects if in subcomponent mode. I assume detecting mode is simple, but how to determine every other face edge or vert?

Any help appriciated.
-Joel

Comments (1)

.

miauu · 2020-02-15

Your code for objects selection can looks like this:


selObjsArr = selection as array
	selectEveryOtherObject = for i = 1 to selObjsArr.count by 2 collect selObjsArr[i]
	select selectEveryOtherObject 

For subobjects:


curO = selection[1]
	if classOf curO == editable_poly do
	(
		selSOArr = case subobjectlevel of
		(
			1: (polyop.getVertSelection curO) as array
			2: (polyop.getEdgeSelection curO) as array
			3: (polyop.getEdgeSelection curO) as array
			4: (polyop.getFaceSelection curO) as array
			5: (polyop.getFaceSelection curO) as array
		)
		
		soToSelArr = for i = 1 to selSOArr.count by 2 collect selSOArr[i]
		
		case subobjectlevel of
		(
			1: (polyop.setVertSelection curO soToSelArr) 
			2: (polyop.setEdgeSelection curO soToSelArr)
			3: (polyop.setEdgeSelection curO soToSelArr)
			4: (polyop.setFaceSelection curO soToSelArr) 
			5: (polyop.setFaceSelection curO soToSelArr) 
		)
	)

But, selected verts/edges/faces are stored in a bitarrays, which means that they are "sorted" and not stored in the order you selecting them.