Home Coding, Scripting, Shaders

MAXScript out geometry data to text file multi meshes

PSok
polycounter lvl 4
Offline / Send Message
PSok polycounter lvl 4
Hello.
I'm Trying to code geometry data to .txt file. For 1 mesh my script working but for 2 or more i have an error. "-- Unknown property: "name" in $selection"
Can anybody help me with that?


tmesh = snapshotAsMesh selection[1]<br>out_name = ((GetDir #export)+"/test.txt")<br>out_file = createfile out_name<br>format " Name:%" $.name&nbsp; to:out_file<br><br>close out_file<br>delete tmesh<br>edit out_name

Replies

  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    "$.name" doesn't know what to do because you're not specifying what objects name to get. You need to loop through the objects and get all their names, like such:

    out_name = ((GetDir #export)+"/test.txt")
    out_file = createfile out_name
    for curObj in (selection as array) do (format "Name:% \n" curObj.name to:out_file)
    close out_file
  • PSok
    Offline / Send Message
    PSok polycounter lvl 4
    Thank you very much!
    Is it possible to save file on Desktop? In function GetDir I only get folders for default path 3dsmax
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Yep. You can get the desktop directory like this:

    out_name = (getDirectories ((systemTools.getEnvVariable("USERPROFILE"))+"/Desktop"))[1]
  • PSok
    Offline / Send Message
    PSok polycounter lvl 4
    Still I have no idea how maxscript can save it to desktop, Im trying to add /text.txt to end of line but still get error

    out_name = (getDirectories ((systemTools.getEnvVariable("USERPROFILE"))+"/Desktop/text.txt"))
    out_file = createfile out_name
    for curObj in (selection as array) do (format "Name:% \n" curObj.name to:out_file)
    close out_file



  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Because getDirectories returns an array, you'd get the first element and then add the file name afterwards:

    out_name = (getDirectories ((systemTools.getEnvVariable("USERPROFILE"))+"/Desktop"))[1] + "test.txt"
  • PSok
    Offline / Send Message
    PSok polycounter lvl 4
    Thank you for your help, script work well now.

    out_name = (getDirectories ((systemTools.getEnvVariable("USERPROFILE"))+"/Desktop"))[1] + "test.txt"
    out_file = createfile out_name
    for curObj in (selection as array) do (format "% \n X:%" curObj.name curObj.pos.controller[1].value to:out_file)
    close out_file

    I want to export result of position with comma "," instead of dot "." It is possible without changing a regional setting in Windows?

  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    For that, you could loop through the values individual characters as a string and replace the periods with commas;

    out_name = (getDirectories ((systemTools.getEnvVariable("USERPROFILE"))+"/Desktop"))[1] + "test.txt"
    out_file = createfile out_name
    for curObj in (selection as array) do (
        posX = (curObj.pos.x) as string
        for i=1 to posX.count do (if posX[i] == "." do posX[i] = ",")
        format "%\nX:%\n" curObj.name posX to:out_file
    )
    close out_file

    Also, when getting the x axis position, besides getting it from the controller you can simply do curObj.pos.x or curObj.pos[1]
  • PSok
    Offline / Send Message
    PSok polycounter lvl 4
    thank you for your help, but your script for multiple objects don't work. I'm trying to resolve without success :(
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Oops, left a '$' in there instead of 'curObj'. Edited the above with fix.
  • PSok
    Offline / Send Message
    PSok polycounter lvl 4
    Thanks! I learned a lot =)
Sign In or Register to comment.