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

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

Comment viewing options

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

Lol!! I had responded and

Lol!! I had responded and created the script in AREA the 05-12-2015...by a look...

http://forums.autodesk.com/t5/programming/help-need-script-that-exports-...

Thomas Jarkowski's picture

Hello again. I checked script

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.

pixamoon's picture

`

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.

pixamoon's picture

`

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's picture

I tried with one vertex...

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's picture

`

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

Thomas Jarkowski's picture

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.

pixamoon's picture

`

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

Thomas Jarkowski's picture

Thanks very very much... but

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

Thomas Jarkowski's picture

Hello. I ran the script and

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.

Comment viewing options

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