# 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.

## Comment viewing options ### I found a script (on this site) that does it

```fn MakePoly = (
constVerts = (polyop.getVertSelection \$) as array

sortedVerts = #()
append sortedVerts constVerts

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 != 0 and i != lastVert) and (finditem constVerts i != 0 and i != lastVert) then theRightEdge = i)
if theRightEdge == #() then exit
if theRightEdge != #() then ( if theRightEdge != thisVert then (theRightVert = theRightEdge) else (theRightVert = theRightEdge) )
if theRightVert == undefined then exit
if theRightVert == sortedVerts 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 != 0 and i != lastVert) and (finditem constVerts i != 0 and i != lastVert) then theRightEdge = i)
if theRightEdge == #() then exit
if theRightEdge != #() then ( if theRightEdge != thisVert then (theRightVert = theRightEdge) else (theRightVert = theRightEdge) )
if theRightVert == undefined then exit
if theRightVert == sortedVerts 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))
closestVert = stillMissing
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 != 0 and i != lastVert) and (finditem constVerts i != 0 and i != lastVert) then theRightEdge = i)
if theRightEdge == #() then exit
if theRightEdge != #() then ( if theRightEdge != thisVert then (theRightVert = theRightEdge) else (theRightVert = theRightEdge) )
if theRightVert == undefined then exit
if theRightVert == sortedVerts 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 \$

)``` ### .

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. ### Okay, I agree with you. It is

Okay, I agree with you. It is better to use the cap. Thank you But `polyOp.createPolygon \$ #{ , , , }` dont create polygon on oject (works with only isolate vertex)

AttachmentSize
31.07.gif 81.69 KB ### .

Creating polygon from four verts see the attached image.

AttachmentSize
nik.png 288.01 KB ### How to create vertices

How do you create vertices without the mesh? ### 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 ### 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.