check Selected Vertices in polyop

hey Folks,
Im working on a bigger Script right now and need to check for vertices if they are selected. I would love to stay in the Editable_Poly Environment. To be concrete, I try to iterate through this :

for refVIndex=1 to refObj.GetNumVertices() by 1 do(

)--but my mesh is big so this is way to time consuming. So i try to find a way to iterate through all my selected Vertices. But i also use my refVIndex to create vertices in order at some part in the script so simply using a function which differs in structure will create bad results.

Any help would be appreciated
Greeting EliDerDeli

Comments

Comment viewing options

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

.

there's no difference in performance when we need to do a couple of these checks
here's a little test

(
 
	delete objects
 
	obj = plane widthsegments:200 lengthsegments:200
	addModifier obj (TurboSmooth iterations:2)
	convertToMesh obj
 
	sel = #{1..obj.numverts}
	seed 132465
	ba  = (for v in sel where random 0.0 1.0 < 0.5 collect v) as BitArray
	checks = 4
 
	for i = 1 to 6 do (
 
		format "-----------\nchecks: %\n--------\n" (int (pow checks i))
 
		gc();t1=timestamp();hf = heapfree
 
			for i=1 to pow checks i do (ba * sel).numberset == ba.numberset
 
		format "Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
 
 
		gc();t1=timestamp();hf = heapfree
 
			for i=1 to pow checks i do (ba - sel).isEmpty
 
		format "Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
 
 
		gc();t1=timestamp();hf = heapfree
 
			for i=1 to pow checks i do (ba * -sel).isEmpty
 
		format "Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
 
	)
 
)


-----------
checks: 4
--------
Time: 0.002sec. Mem: 320L
Time: 0.002sec. Mem: 320L
Time: 0.001sec. Mem: 576L
-----------
checks: 16
--------
Time: 0.005sec. Mem: 1088L
Time: 0.003sec. Mem: 1088L
Time: 0.004sec. Mem: 2112L
-----------
checks: 64
--------
Time: 0.016sec. Mem: 4160L
Time: 0.007sec. Mem: 4160L
Time: 0.01sec. Mem: 8256L
-----------
checks: 256
--------
Time: 0.06sec. Mem: 16448L
Time: 0.026sec. Mem: 16448L
Time: 0.037sec. Mem: 32832L
-----------
checks: 1024
--------
Time: 0.254sec. Mem: 65600L
Time: 0.14sec. Mem: 65600L
Time: 0.188sec. Mem: 131136L
-----------
checks: 4096
--------
Time: 1.068sec. Mem: 272816L
Time: 0.597sec. Mem: 272816L
Time: 0.806sec. Mem: 542136L

miauu's picture

.

So, in this case everything is personal coding style. :)

miauu's picture

.

If I understand you correctly you want to know if a vertex with certain index is among selected vertices. Instead of using a loop use bitarray operations:

Let say that you want to know if vertex 15 is selected.

(
	myObj = selection[1]
	refVertIdx = 15
	if classOf myObj == Editable_Poly do
	(
		--	"get only selected vertices"
		selVertsBA = polyop.getVertSelection myObj
 
		if (selVertsBA * #{refVertIdx}).isEmpty then
			print "ref vert is not selected"
		else
			print "ref vert is selected"		
	)	
)
EliderDeli's picture

Perfect thank you very much,

Perfect thank you very much, that will help a lot :)

jahman's picture

.

there's no need to find intersection

if (polyop.getVertSelection myObj)[index] then print "selected" else print "not selected"
miauu's picture

.

Is this work for two or more verts that have to be checked if they are selected?

jahman's picture

.

for multiple indexes I'd check it like this

(vertsToCheck - vertsToCheckAgainst).isEmpty
miauu's picture

.

Is there any benefits to use "-" instead of "*"?

jahman's picture

.

.numberset is slower in general
(ba * ba2).numberset == ba.numberset

miauu's picture

.

I know, but sometimes, by habit, I use .numberset. :)

Comment viewing options

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