ScriptSpot home

Forum topic · Scripts Wanted

HELP! - Need script that exports Vertex X,Y coordinates to textfile....

By Thomas Jarkowski · 2015-05-06

Description

Hello. I desperately need a script that can export vertex points X,Y coordinates to a textfile like .csv. Like the following...

1. Select a set of vertex points.
2. Run script.
3. Browse for a textfile output and name it.
4. A .csv file (or any textfile) is created with two columns X and Y for each vertex coordinate in relation to grid 0, 0 position in model.

Could someone help me with this script?

Thank you.

Comments (21)
Thomas Jarkowski

Hello again. I checked script now and it exports coordinates good. But the order of the exported x,y is not correct. Please check....

Script now........
3364.05 9382.2
9204.08 5014.29
8545.49 5190.76
7927.55 5478.91
7309.62 5767.06
6691.68 6055.21
6101.21 6396.12
5578.91 6834.38
5056.6 7272.65
4534.3 7710.91
4096.04 8233.21
3704.96 8791.73

Correct.............
3364.05 9382.2
3704.96 8791.73
4096.04 8233.21
4534.3 7710.91
5056.6 7272.65
5578.91 6834.38
6101.21 6396.12
6691.68 6055.21
7309.62 5767.06
7927.55 5478.91
8545.49 5190.76
9204.08 5014.29

It seems the script put the last coordinate first and then the order is reversed. This is important to change for the use I need the script for.

Would it be possible to adjust the script? Thank you.

Reply to Thomas Jarkowski
pixamoon

`

only way i see is just to sort positions before save.
I'm not sure if script can get points in the right order you need, but definitely can sort it before it saves to file.
I'll post new one later today.

Reply to pixamoon
pixamoon

`

ok, try this one:


csvFile = "c:\\text3.csv"
separator = " "  --- can be tab "\t" space " " or "|"		
	
fn FnCopmpare v1 v2 = (
	case of (
	(v1[1] < v2[1]) : -1
	(v1[1] > v2[1]) : 1
	default: 0
	)
)

if selection.count == 1 and classof $ == Editable_Poly do (
	arr = ($.GetSelection #Vertex) as Array
	if arr != undefined do (
		verArr = for i in arr collect #((polyOp.getVert $ i)[1], (polyOp.getVert $ i)[2])
		qsort verArr FnCopmpare
		for i=1 to verArr.count do verArr[i] = verArr[i][1] as string + separator + verArr[i][2] as string
		try((dotnetClass "System.IO.File").WriteAllLines csvFile verArr)catch()
	)
)
Thomas Jarkowski

I tried with one vertex... script gives me....

8060.24 -7757.49 (millimeters?)

Objects properties in 3ds max gives me....

X: 402.745 cm, Y: 429.476 cm

I can't seem to relate these two?

pixamoon

`

what kind of vertex points ? from mesh, edit poly or spline ?

Reply to pixamoon
Thomas Jarkowski

Editable poly it is...

I'm new to 3ds max but when I select the object, its a UV layer with texture.. it say in a box editable poly. When I select a vertex point it say the same.

Reply to Thomas Jarkowski
pixamoon

`

ha, so i guessed right and did this in free time...

here is a code:


csvFile = "c:\\text.csv"
separator = " "  --- can be tab "\t" space " " or "|"

if selection.count == 1 and classof $ == Editable_Poly do (
	arr = $.GetSelection #Vertex
	if arr != undefined do 
		verArr = for i in arr collect (($.getvertex i)[1] as string + separator + ($.getvertex i)[2] as string)
	try( (dotnetClass "System.IO.File").WriteAllLines csvFile verArr )catch()
	)

just change csvFile path and separator symbol, here I did space symbol " "
It works only for 1 selected object, if you want select more it need a for loop for each object

Hope it helps a bit,
Pixamoon

Reply to pixamoon
Thomas Jarkowski

Thanks very very much... but what do you mean one selected object? I have a plane as editable poly and some of the vertex points in this plane I need to select, and then export coordinates.

I will try the script.. thanks

Reply to Thomas Jarkowski
Thomas Jarkowski

Hello. I ran the script and it created a .csv. The content looked like this....

-6175.0 0.0
-506.207 9097.78
-506.207 7975.06
-408.355 6856.6
-506.207 5738.15
-890.202 4683.13
-1451.57 3710.82
-2012.93 2738.51
-2574.29 1766.2
-3135.66 793.887
-3929.55 7.23748e-005
-5052.27 0.0

But when I checked the "object properties" of the first vertex closest to 0, 0, I get the X and Y coordinates: X: 576,665 cm, Y: 909,778 cm.

this does not seem to match the csv file output. What can be wrong?

Ones again.. thanks for your help.

Reply to Thomas Jarkowski
Thomas Jarkowski

When looking at the coordinates in the file, I see that the first and the last have 0,0 in them.. this means the coordinates are in relation to the editable poly object as an isolated object, not the world grid in the model.

Would this be an easy fix? I need coordinates in relation to the full model 0,0 grid position?

Reply to pixamoon
pixamoon

`

oki, try this one: didn't have time to test it, but i think it should be it:


csvFile = "c:\\text2.csv"
separator = " "  --- can be tab "\t" space " " or "|"

if selection.count == 1 and classof $ == Editable_Poly do (
	arr = $.GetSelection #Vertex
	if arr != undefined do 
		verArr = for i in arr collect ((polyOp.getVert $ i)[1] as string + separator + (polyOp.getVert $ i)[2] as string)
	try( (dotnetClass "System.IO.File").WriteAllLines csvFile verArr )catch()
	)
Reply to pixamoon
Thomas Jarkowski

Thanks.. runned it but gor these numbers...

5202.83 -3730.04
8060.24 -7757.49
7409.35 -7453.97
6734.48 -7208.34
6040.77 -7022.46
5333.5 -6897.75
4626.23 -7022.46
3951.36 -6776.83
3765.48 -6083.12
3828.07 -5367.67
4187.16 -4745.71
4694.99 -4237.87

checked a vertex but the model coordinates are in cm and all are positive numbers. Checked on of the vertex numbers and got, X: 402,239, Y: 426,456. So these coordinates cant be right either.

sorry.. but is it fixable?

Reply to Thomas Jarkowski
pixamoon

`

can you check your System Unit (not display unit)

or can u send me some part of your scene to pixamoon@gmail.com

Reply to Thomas Jarkowski
pixamoon

`

oki, look like scripts saves in system units, and u have it as millimeters. Can u try to select one vertex and save it. then check result with your max scene.

I tried here with inches System Units and all looks good
Let me know

Reply to pixamoon
Thomas Jarkowski

ok.. but sorry I don't understand fully.. do you mean that in system unit setup 1 unit = 1 millimeter, as set... but even if output is in millimeters, the numbers don't match if transforming from millimeters to cm?

Reply to Thomas Jarkowski
Thomas Jarkowski

changed display unit to millimeters now also but still the same problem with output.. negative value also.

Reply to Thomas Jarkowski
pixamoon

`

I tried here few different meshes different scale etc, every time it saves good coordinate.

I think I'll need to see any part of your scene to find out what is wrong.

or try this... create box, convert it to editable poly, select vertex and run scripts...