Notifications
Clear all

[Closed] Select Vertex/Find current modifier

Ok, I’m missing something here. There should be some easy way to do this, and I can’t figure it out. Its probably obvious, and I’m just blind, but any help would be appreciated.

How do I find out what the currently selected modifier in the modify panel is, and select verticies from it? Or barring that, how do I select verts regardless of what they are in? The script I have so far looks like this:

--Finds Poles in the currently selected object.
--Eric Burnett, 27/06/04
fn findPoles = (
	try (
		sel = selection as array
		print sel.count
    		if (sel.count != 1) do throw "1"
		max modify mode
		if (numsubObjectLevels !=5) do throw "1"
		subobjectLevel = 1
		max select all
		verts = selection as array
		for i in verts do (
			--i.select
			--$.setSelection #Vertex i
		)
	) 
	catch (messageBox("improper Selection"))

Currently it switches to the vertex sub obj level of the currently selected modifier, selects all verts, then grabs that as an array. But I wish to be able to iterate through each individually, which means I need to be able to select them.

Thanks!

4 Replies
1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

modPanel.GetCurrentObject()

Returns the current object in the Modifier stack.
You could check for valid modifier before processing selections…


obj = $Box01
 
[font=Verdana]all_selections = for m in obj.modifiers where classof m == Mesh_select collect[/font]
[font=Verdana]  (getVertSelection obj m)
 

Assuming there are multiple Mesh_Select modifiers on top of the object called Box01, the code above will collect all vertex selections from them and return an array with a bitArray for every Mesh_Select modifier (counting from top to bottom).

The following code would create a new box and assign the collected selections from the first one to new Mesh_Select modifiers on the second one:


sp = Box()
for s = all_selections.count to 1 by -1 do

(
 
theMod = mesh_select()
 
addModifier sp theMod 
 
select sp
 
setVertSelection sp theMod all_selections[s]
 
)
 

Hope this helps.
Bobo

[/font]

Thanks bobo! I didn’t realize that getCurrentObject returned a modifier, not just the object. That made life much easier

Now one more question. I have it almost done…it works when used on modifiers, but if the base object is selected, it won’t actually select the verts. It is supposed to select the poles, as long as you are on an acceptiable modifier or the base object, but for some reason it selects nothing at the base…really odd.

--Finds Poles in the currently selected object.
--Eric Burnett, 27/06/04

--Grabs the correct modifier index
fn findMod = (
	a = 0
	for i = 1 to $.modifiers.count do (
		print (($.modifiers[i]) as string)
		print (modpanel.getCurrentObject() as string)
		if (($.modifiers[i]) as string) == (modpanel.getCurrentObject() as string) do (
			a = i
			 exit)
		
	)
	a = a
)


fn findPoles = (
	i = 1
	try (
		obj = $
		--Basic checking and prep...make sure only one object selected, and selected modifier is usable
		sel = selection as array
    	if (sel.count != 1) do throw "1"
		max modify mode
		if (numsubObjectLevels !=5) do throw "1"
		subobjectLevel = 1
		
		--find out if it is a modifier currently selected, if it is, find which modifier
		--(if finds modifiers with same name, stops at top one)
		i = findMod()
		
		poles = #()
		
		--set it up so that it is a single editiable poly with no modifiers for manipulation
		--Use 'undo on' so that can be returned to previous state
		--max select all
		print i
		undo on (
			if i != 0 then (
				if i > 1 do (
					for p = i - 1 to 1 by -1 do (
						deleteModifier $ p
					)
				)
			)
			else for p = obj.modifiers.count to 1 by -1 do (
				deleteModifier $ p
			)
					
					
			select (convertToPoly($))
			
			--create array of all vertex indices that have more than 4 edges 
			for a = 1 to (getVertSelection $).count do (
				polyOp.setVertSelection $ #(a)
				$.convertSelection #Vertex #Edge
				if ((getEdgeSelection obj)as array).count > 4 do append poles a
			)

		)
		
		--return to previous state, then select polar verticies and go to vertex sub object mode
		max undo
		print poles
		select obj
		if i != 0 then modpanel.setCurrentObject obj.modifiers[i]
		else modpanel.setCurrentObject $.baseObject
		subobjectLevel = 1
		
		if i != 0 then setVertSelection obj obj.modifiers[i] poles
		else polyop.setVertSelection obj poles           ----This line doesn't work!!!
	) 
	catch (messageBox("Improper Selection"))

)

Couple of questions and some comments:

What class is the object you are processing?
If it is NOT EPoly, you cannot expect it to work on base level as you convert to EPoly at a certain point, but then undo so at the end, the object is not guaranteed to be EPoly, and polyop.setVertSelection would fail.

You should consider checking the class of the base object and using setVertSelection or polyop.setVertSelection based on the result of the check.

Also, the function findMod looks mighty strange. Instead of converting to string (?!), why don’t you just compare the current modPanel object with the modifiers on the stack? Or even better, you could use the function

 

fn findMod obj = ( try(modpanel.getModifierIndex obj (modpanel.getCurrentObject()))catch(0) )


Odd. it works now. I am sure I was working with an epoly, because I just loaded the test file from last time that I saved, and it worked fine. There must have been something left in memory from one of my tests that required me to restart max, and I didn’t notice. Bizzare. Thanks for the help though.

And about your findMod method, thank you very much!!! That works even for modifiers with the same name! I did not know how to do that before. Too many functions to learn :D.

Always a pleasure to learn from you Bobo.

And for anyone who wants it: my final script is attached. Kinda slow when running meshes beyond 1000 verts, but give it time and it will complete. Now set up so you can run it, then add it to key or quad from “Eric’s Scripts”.