Notifications
Clear all
[Closed] Formatting Vertex Coordinates
Dec 07, 2012 6:27 pm
I have the following code that gives me almost exactly what i need.
for obj in (selection as array) do
(
tmesh =snapshotAsMesh obj
(
num_verts = tmesh.numverts
for v = 1 to num_verts do
(
local coord = getVert tmesh v
format "% % %
" coord.x coord.y coord.z
)
)
)
Basically, for a box the output looks like this.
3.37598 -2.50928 0.0
3.89221 -2.50928 0.0
3.37598 -1.74463 0.0
3.89221 -1.74463 0.0
3.37598 -2.50928 0.59217
3.89221 -2.50928 0.59217
3.37598 -1.74463 0.59217
3.89221 -1.74463 0.59217
I need it to look like this:
3.37598 -2.50928 0.0,
3.89221 -2.50928 0.0,
3.37598 -1.74463 0.0,
3.89221 -1.74463 0.0,
3.37598 -2.50928 0.59217,
3.89221 -2.50928 0.59217,
3.37598 -1.74463 0.59217,
3.89221 -1.74463 0.59217
I can’t figure out how to put a comma at the end of the coordinate trio without it showing up on the last coordinate as well. Like this:
3.37598 -2.50928 0.0,
3.89221 -2.50928 0.0,
3.37598 -1.74463 0.0,
3.89221 -1.74463 0.0,
3.37598 -2.50928 0.59217,
3.89221 -2.50928 0.59217,
3.37598 -1.74463 0.59217,
3.89221 -1.74463 0.59217,
Any help would be greatly appreciated.
7 Replies
Dec 07, 2012 6:27 pm
That places a comma at the end of every coordinate. I need it to not put a comma on the last coordinate in the loop.
Is it possible to use if/then/else in this situation? I’m not sure how to implement it but something like this:
if v >= 1
then format "% % %,
" coord.x coord.y coord.z
else format "% % %
" coord.x coord.y coord.z
So, this way, the for loop would go through the count until it reaches the last coordinate and then formats it without putting the comma at the end.
Dec 07, 2012 6:27 pm
Test if v == num_verts then don’t add the comma.
for obj in (selection as array) do
(
tmesh =snapshotAsMesh obj
(
num_verts = tmesh.numverts
for v = 1 to num_verts do
(
local coord = getVert tmesh v
if v == num_verts then
(
format "% % %
" coord.x coord.y coord.z
)
else
(
format "% % %,
" coord.x coord.y coord.z
)
)
)
)
-Eric
Dec 07, 2012 6:27 pm
for obj in (selection as array) do
(
tmesh = snapshotAsMesh obj
num_verts = tmesh.numverts
for v = 1 to num_verts do
(
local coord = getVert tmesh v
format "% % %%
" coord.x coord.y coord.z (if v < num_verts then "," else "")
)
)