how to make a polygon from vertices selection >3?

I have such code

(
arrVert = (vert_sel=(polyOp.getVertSelection $.baseobject) as array) -- array of vertices
polyOp.createPolygon $ arrVert
)

And created face only from 3 vertices, and I would like to make a polygon from vertices selection >3.

Comments

Comment viewing options

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

I found a script (on this site) that does it

fn MakePoly = (
	constVerts = (polyop.getVertSelection $) as array
 
	sortedVerts = #()
	append sortedVerts constVerts[1]
 
	stillGood = true
	Tcount = 0
 
	while stillGood do
	(
		thisVert = sortedVerts[sortedVerts.count]
		try (lastVert = sortedVerts[sortedVerts.count - 1])
		catch (lastVert = -1)
		theseEdges = (polyop.getEdgesUsingVert $ thisvert) as array
		theseEdgesVerts = for i in theseEdges collect ((polyop.getVertsUsingEdge $ i)as array)
		theRightEdge = #()
		for i in theseEdgesVerts do (if (finditem constVerts i[1] != 0 and i[1] != lastVert) and (finditem constVerts i[2] != 0 and i[2] != lastVert) then theRightEdge = i)
		if theRightEdge == #() then exit
		if theRightEdge != #() then ( if theRightEdge[1] != thisVert then (theRightVert = theRightEdge[1]) else (theRightVert = theRightEdge[2]) )
		if theRightVert == undefined then exit
		if theRightVert == sortedVerts[1] then stillGood = false else append sortedVerts theRightVert
		Tcount += 1
		if Tcount > 10 then stillGood = false
	)
 
	Tcount = 0
	if sortedVerts.count != constVerts then
	(
		sortedVerts = for i in sortedVerts.count to 1 by -1 collect sortedVerts[i]
		while stillGood do
		(
			thisVert = sortedVerts[sortedVerts.count]
			try (lastVert = sortedVerts[sortedVerts.count - 1])
			catch (lastVert = -1)
			theseEdges = (polyop.getEdgesUsingVert $ thisvert) as array
			theseEdgesVerts = for i in theseEdges collect ((polyop.getVertsUsingEdge $ i)as array)
			theRightEdge = #()
			for i in theseEdgesVerts do (if (finditem constVerts i[1] != 0 and i[1] != lastVert) and (finditem constVerts i[2] != 0 and i[2] != lastVert) then theRightEdge = i)
			if theRightEdge == #() then exit
			if theRightEdge != #() then ( if theRightEdge[1] != thisVert then (theRightVert = theRightEdge[1]) else (theRightVert = theRightEdge[2]) )
			if theRightVert == undefined then exit
			if theRightVert == sortedVerts[1] then stillGood = false else append sortedVerts theRightVert
			Tcount += 1
			if Tcount > 10 then stillGood = false
		)
	)
	Tcount = 0
	while sortedVerts.count != constVerts.count do
	(
		stillMissing = #()
		stillMissing = (constVerts as bitarray - sortedVerts as bitarray) as array
		print"Then"
		print stillMissing
		shortestDistance = length ((polyop.getVert $ sortedVerts[sortedVerts.count])-(polyop.getVert $ stillMissing[1]))
		closestVert = stillMissing[1]
		for i in stillMissing do if (length ((polyop.getVert $ sortedVerts[sortedVerts.count]) - (polyop.getVert $ i))) < shortestDistance then closestVert = i
		append sortedVerts closestVert
		while stillGood do
		(
			thisVert = sortedVerts[sortedVerts.count]
			try (lastVert = sortedVerts[sortedVerts.count - 1])
			catch (lastVert = -1)
			theseEdges = (polyop.getEdgesUsingVert $ thisvert) as array
			theseEdgesVerts = for i in theseEdges collect ((polyop.getVertsUsingEdge $ i)as array)
			theRightEdge = #()
			for i in theseEdgesVerts do (if (finditem constVerts i[1] != 0 and i[1] != lastVert) and (finditem constVerts i[2] != 0 and i[2] != lastVert) then theRightEdge = i)
			if theRightEdge == #() then exit
			if theRightEdge != #() then ( if theRightEdge[1] != thisVert then (theRightVert = theRightEdge[1]) else (theRightVert = theRightEdge[2]) )
			if theRightVert == undefined then exit
			if theRightVert == sortedVerts[1] then stillGood = false else append sortedVerts theRightVert
			Tcount += 1
			if Tcount > 10 then stillGood = false
		)
		Tcount+=1
		if Tcount > 30 then exit	
	)
	print "END"
	print sortedVerts
 
	if (polyop.createpolygon $ sortedVerts) == undefined then 
	(
	polyop.createpolygon $ (for i in sortedVerts.count to 1 by -1 collect sortedVerts[i])
	)
	update $
 
)
miauu's picture

.

Why you don't want to use Cap Poly? This is the easies method.

polyOp.createPolygon $ #(177, 145, 146, 178)

creates polygon on oject. See the attached image.
Don't use bitarray to store the selected verts. In bitarray the verts are sorted from the lower to higher vert index.
To use polyOp.createPolygon to create face from 4 verts, you have to store the selected verts in an array, where the verts are sorted in proper order. See the image - did you see the verts indexes and how I sort the verts in the array that is passed to polyOp.createPolygon. The verts order is essential when you wants to create 4 sided polygon.

Nik's picture

Okay, I agree with you. It is

Okay, I agree with you. It is better to use the cap. Thank you

Nik's picture

I know about cap

But polyOp.createPolygon $ #{ , , , } dont create polygon on oject (works with only isolate vertex)

AttachmentSize
31.07.gif 81.69 KB
miauu's picture

.

Creating polygon from four verts see the attached image.

AttachmentSize
nik.png 288.01 KB
Felice's picture

How to create vertices

How do you create vertices without the mesh?

Nik's picture

If class of object ==

If class of object == editable_mesh or editable_poly then \
Enable sub-object vertex ➜ go to righr-panel settings ➜ Create ➜ pick to viewport for create vertices

miauu's picture

You have to have a mesh.

You have to have a mesh. Create a plane, convert it to mesh, delete all verts and you will have an empty mesh and can start adding verts where you want.

Comment viewing options

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