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.
Forum topic · General Scripting
By Nik · 2013-07-31
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.
I found a script (on this site) that does it
Nik · 2013-08-03
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 · 2013-07-31
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 · 2013-07-31
Okay, I agree with you. It is better to use the cap. Thank you
I know about cap
Nik · 2013-07-31
But
polyOp.createPolygon $ #{ , , , }dont create polygon on oject (works with only isolate vertex)
.
miauu · 2013-07-31
Creating polygon from four verts see the attached image.
How to create vertices
Felice · 2013-07-31
How do you create vertices without the mesh?
miauu · 2013-07-31
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.
Nik · 2013-08-02
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