ScriptSpot

Forum topic · Scripts Wanted

Get CV Curve Control points position

By arhshine · 2013-10-22

Description

Hello, I need a script..a simple one i think but having no experience in MaxScript this is way over my head.I need it to save the position (x,y,z) of CV points of a CV_Curve to any file that i can read (txt,csv..or any).I will be forever grateful! Thank you.

Comments (10)

thank you !

arhshine · 2013-10-22

I am truly grateful.After one copy/pastes about 300 coordinates from one place to another one by one, you really start to appreciate having a script that is able to do this.

barigazy · 2013-10-22

And for that reason knowing MXS is good. :)
I started to learn it because I had a similar probem

arhshine · 2013-10-22

YOU are my hero ! Thank you !

barigazy · 2013-10-22

And to write to .txt use next snippet (Change folder path if u want)

txtFile = createFile @"c:\Temp\CV_Poss.txt"
for c in selection where isKindOf c NURBSCurveshape do
(
nSet = getNURBSSet c
for i = 1 to nSet.numObjects do
(
for p = 1 to nSet[i].numCVs do
format "Curve_name: % ; Curve_#No: % ; CV: % ; CV_Pos: %\n" c.name i p ((getCV nSet[i] p).pos*c.transform) to:txtFile
)
)
close txtFile

one more thing

arhshine · 2013-10-22

If it`s not too much trouble, i was wondering, can the returned values be somehow formatted in the text file ? Right now they look like this ( example [44.0106,-31.4628,0] ). Unfortunately the application in which i need to bring them has the Y-axis as Up-axis and this means i have to edit them one by one to replace Z with the Y.Is there a solution to this ? Thank you.

barigazy · 2013-10-22

Like this

txtFile = createFile @"c:\Temp\CV_Poss.txt"
for c in selection where isKindOf c NURBSCurveshape do
(
nSet = getNURBSSet c
for i = 1 to nSet.numObjects do
(
for p = 1 to nSet[i].numCVs do
pos = ((getCV nSet[i] p).pos*c.transform)
format "%\n" (point3 pos.x pos.z pos.y) to:txtFile
)
)
close txtFile

arhshine · 2013-10-22

I might not be doing something right.It doesn't work, i get this message "-- Unknown property: "x" in undefined"

barigazy · 2013-10-22

Damn parentheses :). Try now

txtFile = createFile @"c:\Temp\CV_Poss.txt"
for c in selection where isKindOf c NURBSCurveshape do
(
nSet = getNURBSSet c
for i = 1 to nSet.numObjects do
(
for p = 1 to nSet[i].numCVs do
(
pos = ((getCV nSet[i] p).pos*c.transform)
format "%\n" (point3 pos.x pos.z pos.y) to:txtFile
)
)
)
close txtFile

Yep

arhshine · 2013-10-22

That did it.It works ! Thank you once again.

barigazy · 2013-10-22

I never played with this before.
To save position to .txt file is easy part but to find CV positions is not.
This is first part.
I created two CV_Curve and then attach. Anyway this is the code which will print some info in Listener

if selection.count != 0 do for c in selection where isKindOf c NURBSCurveshape do
(
nSet = getNURBSSet c
for i = 1 to nSet.numObjects do
(
for p = 1 to nSet[i].numCVs do
format "Curve_name: % ; Curve_#No: % ; CV: % ; CV_Pos: %\n" c.name i p ((getCV nSet[i] p).pos*c.transform)
)
)