Notifications
Clear all

[Closed] select one vertex of each mesh elements

I have to select one (any) vertex of each element of geometry object, one element by one:
It’s easy for entire object, e.g just:$.EditablePoly.SetSelection #Vertex #{1}
but how to do it for each element of this same mesh object?

Let say we have a teapot which is one object composed of body,handle,spout,lid, which are elements of this mesh.
I want to select one vertice of each of these elements and repeat this operation for all elements.Select one vertice of first element , perform some operation, then select one vertice on next element etc.The point is I dont know what is the indexes of vertices of remaining elements and how to go through all elements.
Do somebody know how to code it and also how to check how mayny vertcies contain each element of mesh.

Code should look something like this:

for o in geometry objects do
convert o to edit poly
for o in o.elements do <—– I need help in this part, how run by all mesh elements of object(s)
if verticles amount>x then <— how to check how many verticles contain each element
select vertex x <— and this part, How to select one vertice of each element of object
do somthing – this is the place for my operation

7 Replies

polyop.getElementsUsingFace

check the mxs help… search this forum…

(
   fn collectVertElements node = if iskindof node PolyMeshObject or iskindof node Editable_Poly do
   (
 	  getelement = polyop.getelementsusingface 
 	  elements = #()
 	  
 	  faces = #{1..node.numfaces}
 	  while not faces.isEmpty do 
 	  for f in faces while
 	  (
 		  ee = getelement node f
 		  faces -= ee
 		  append elements ee
 		  off
 	  )
 	  do()
 	  elements
   )
  fn SelectVertFn node elements: =
  (
 	for cluster in elements do
 	(	
 		clusterverts  = (polyop.getvertsusingface node cluster) as array
 		
 		--for v in clusterverts do
 			--print (polyop.getvert node v)   -- position of all vertexes
 		
 		print (polyop.getvert node clusterverts[1]) -- the position of the first vertex of every element
 	)	
  ) 
  ee = collectVertElements $
  SelectVertFn $ elements:ee
 ) 

collect elements – By DenisT

Thanks Denis, it still great gap between getvertsusingface to what I need but indeed I it’s only option to use this command.
try2script – 100 x thank you for your script however I have problems to make it work.

I use this to run it:

for o in selection do
(
element=collectVertElements o
)

But it seems selection of vertex not changed. Maybe I do something wrong with this, correct me if I`m wrong.

(
   fn collectVertElements node = 
   (
 	  getelement = polyop.getelementsusingface 
 	  elements = #()
 	  
 	  faces = #{1..node.numfaces}
 	  while not faces.isEmpty do 
 	  for f in faces while
 	  (
 		  ee = getelement node f
 		  faces -= ee
 		  append elements ee
 		  off
 	  )
 	  do()
 	  elements
   )
  fn SelectVertFn node elements: =
  (
 	for cluster in elements do
 	(	
 		clusterverts  = (polyop.getvertsusingface node cluster) as array
 		
 		--for v in clusterverts do
 			--print (polyop.getvert node v)   -- position of all vertexes
 		
 		print (polyop.getvert node clusterverts[1]) -- the position of the first vertex of every element
 	)	
  ) 
  
  for s in selection where iskindof s PolyMeshObject or iskindof s Editable_Poly do
  (
 	ee = collectVertElements s
 	SelectVertFn s elements:ee
  )	 
 ) 

collect elements – By DenisT

I changed your function a little bit and work great, thank you.

because originally collect elements is my function i can also show the better way of how to collect one (first) vertex of every node element:

fn collectElementFirstVerts node = if iskindof node Editable_Poly do
 (
 	getelement = polyop.getelementsusingface 
 	geteverts = polyop.getfaceverts
 
 	faces = #{1..node.numfaces}
 	firstverts = #{} 
 	while not faces.isEmpty do for f in faces while
 	(
 		ee = getelement node f
 		faces -= ee
 		append firstverts (geteverts node f)[1]
 		off
 	)
 	do()
 	firstverts
 )
 $.selectedverts = (collectElementFirstVerts $)

there is no reason to collect elements if you need only a vertex

Yes, that’s true! Thank you Denis. You’re short and right