Home Technical Talk

maxscript that exports UV as selection into photoshop

polycounter lvl 18
Offline / Send Message
dejawolf polycounter lvl 18
hi All, been working all day on this thing. its a script that exports an objects UVWs from 3ds max into photoshop as a selection. its currently very rough, mostly because i'm not a coder,
and because i started messing with javascript 2 days ago :P

its mostly for practice and proof of concept.
  1. if selection.count > 0 then
  2.  
  3. (
  4. output_file = createfile "C:UVWscript.js"
  5. docusize = 1024
  6. format "var docSize = %;n" docusize to:output_file--write to file
  7.  
  8. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
  9. --start of map vertex array. this goes into the V = Array(x,x,x) part.
  10. (
  11. format "var V% = Array(" i to:output_file--write to file
  12. mapvert = polyOp.getmapvert $ 1 i
  13.  
  14. --write the first map vertex
  15. arrayvert = mapvert[1]*docusize
  16. intarray = arrayvert as integer
  17. format "%," intarray to:output_file--write to file
  18. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
  19. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
  20. intarray = arrayvert as integer
  21. format "%" intarray to:output_file--write to file
  22. format ");n" to:output_file--write to file
  23. )--end for i
  24.  
  25. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
  26. --start of map face array. this is the
  27. (
  28. format "selRegion = Array(" to:output_file--write to file
  29. mapface = polyOp.getmapface $ 1 i
  30. for E = 1 to 4 do
  31. (
  32. arrayfacevert = mapface[E]
  33. format "V%"arrayfacevert to:output_file--write to file
  34. if E < 4 then ( format ","arrayfacevert to:output_file)
  35. )--end for E
  36. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
  37.  
  38. )--end for i
  39.  
  40. close output_file
  41. )--end if
  42.  

its also got several limitations currently.

1: doesn't work on anything else but quads
2: doesn't work on mesh objects, or primitives, or anything else that isn't a poly object.
3: 3ds max exports it into a .js file. to open it in photoshop, you need to click file>scripts>browse
4:oh forgot, for some reason photoshop acts as if the file is open even though i told it to close the script in max.
so you need to create another script file, and copy-paste the output into that.
5: painfully slow

5: i don't know if it works with anything else but max 8, but i doubt it does.
6: same goes for photoshop. i was using photoshop CS1 for this one.
7: you have to manually set the document size of the photoshop file. docusize = 1024
for example tells it that the photoshop document is a 1024x1024 map.

then browse to C: \ and open the UVWscript.js file

todo:

1: make it work with other things than just quads.
2: port it to VB, once i'm done with the proofing, and make it so that

ah well, got lots to do, i'll be messing with this thing for the next few hours.
i don't think my brain has ever hurt this much before...

Replies

  • Tumerboy
    Offline / Send Message
    Tumerboy polycounter lvl 17
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    meshu = polyOp.getmapface $ 1 1
    meshu[7]

    currently looking at some way to increase meshu[X] until it returns undefined, and then
    somehow break, and then save X into a variable.
  • gamedev
    Offline / Send Message
    gamedev polycounter lvl 12
    Wouldn't using the build in Render UV's w/ just seam edges selected be easier? Of course you'd need to then use the magic want in photoshop, but selecting big chunks is super easy.

    Cheers!
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    ok got something:

    while i < 10 do

    (
    i = i+1
    print "lal"
    if mapface == undefined then exit
    )
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    gamedev wrote: »
    Wouldn't using the build in Render UV's w/ just seam edges selected be easier? Of course you'd need to then use the magic want in photoshop, but selecting big chunks is super easy.

    Cheers!

    short answer: no.
    long answer: NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.

    edit: got it working with full polys now:
    1. if selection.count > 0 then
    2.  
    3. (
    4. output_file = createfile "C:Program Files (x86)AdobePhotoshop CSUVWscript.js"
    5. docusize = 1024
    6. format "var docSize = %;n" docusize to:output_file--write to file
    7.  
    8. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    9. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    10. (
    11. format "var V% = Array(" i to:output_file--write to file
    12. mapvert = polyOp.getmapvert $ 1 i
    13.  
    14. --write the first map vertex
    15. arrayvert = mapvert[1]*docusize
    16. intarray = arrayvert as integer
    17. format "%," intarray to:output_file--write to file
    18. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    19. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    20. intarray = arrayvert as integer
    21. format "%" intarray to:output_file--write to file
    22. format ");n" to:output_file--write to file
    23. )--end for i
    24.  
    25. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
    26. --start of map face array. this is the
    27. (
    28. format "selRegion = Array(" to:output_file--write to file
    29. mapface = polyOp.getmapface $ 1 i
    30. NumFaceCons = 0
    31. while i < 1000 do
    32. (
    33. i = i+1
    34. if mapface[i] == undefined then (NumFaceCons = i-1 exit)
    35. )
    36. for E = 1 to NumFaceCons do
    37. (
    38. arrayfacevert = mapface[E]
    39. format "V%"arrayfacevert to:output_file--write to file
    40. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    41. )--end for E
    42. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    43.  
    44. )--end for i
    45.  
    46. close output_file
    47. )--end if
    48.  
  • gamedev
    Offline / Send Message
    gamedev polycounter lvl 12
    hahah. Point taken good sir!
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    edit: fixed the bug:
    1. if selection.count > 0 then
    2.  
    3. (
    4. output_file = createfile "C:Program Files (x86)AdobePhotoshop CSUVWscript.js"
    5. docusize = 1024
    6. format "var docSize = %;n" docusize to:output_file--write to file
    7.  
    8. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    9. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    10. (
    11. format "var V% = Array(" i to:output_file--write to file
    12. mapvert = polyOp.getmapvert $ 1 i
    13.  
    14. --write the first map vertex
    15. arrayvert = mapvert[1]*docusize
    16. intarray = arrayvert as integer
    17. format "%," intarray to:output_file--write to file
    18. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    19. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    20. intarray = arrayvert as integer
    21. format "%" intarray to:output_file--write to file
    22. format ");n" to:output_file--write to file
    23. )--end for i
    24.  
    25. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
    26. --start of map face array. this is the
    27. (
    28. format "selRegion = Array(" to:output_file--write to file
    29. mapface = polyOp.getmapface $ 1 i
    30. NumFaceCons = 0
    31. F = 1
    32. while F < 50 do
    33. (
    34. F = F+1
    35. if mapface[F] == undefined then (NumFaceCons = F-1 exit)
    36. )
    37. for E = 1 to NumFaceCons do
    38. (
    39. arrayfacevert = mapface[E]
    40. format "V%"arrayfacevert to:output_file--write to file
    41. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    42. )--end for E
    43. NumFaceCons = 0
    44. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    45.  
    46. )--end for i
    47.  
    48. close output_file
    49. )--end if
    50.  

    now for optimization.

    oh, and here's a picture of the selection:

    photoshopselection.jpg

    1280 polygons, took some time to autoselect in photoshop :P
    but try and do THAT with the lasso tool in photoshop :D
  • Mark Dygert
    I'm not really sure I get the purpose of the script? Is it to transfer a selection from the UV editor to photoshop? If so, that's pretty handy nice work.

    I've always used a photoshop action that looks for specific colors that I have set to be the default in the render UV dialog box. I render a template, open it in photoshop, hit F12 and it puts the solid pieces on one layer, and the wires on another. It also sets up some folders and layers with names. I agree it can be a bit tedious to wand select all the shapes... so hopefully your script does what I think it does ha!

    /crosses fingers.
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    Vig wrote: »
    I'm not really sure I get the purpose of the script? Is it to transfer a selection from the UV editor to photoshop? If so, that's pretty handy nice work.

    I've always used a photoshop action that looks for specific colors that I have set to be the default in the render UV dialog box. I render a template, open it in photoshop, hit F12 and it puts the solid pieces on one layer, and the wires on another. It also sets up some folders and layers with names. I agree it can be a bit tedious to wand select all the shapes... so hopefully your script does what I think it does ha!

    /crosses fingers.

    pretty much, yeah, but i still need to simplify the operations.
    currently its probably as slow as rendering out a template of an object, and loading it into photoshop.
    ideally its going to be a single-click, and the UV selection is instantly in photoshop,
    but i think i might have hit the limit of what i can do with javascripting photoshop.
  • glib
    Psst, renderhjs already has a button that does this in his script (which also has a thread in this forum). Nice work though ;).

    [edit] I'm an idiot, I should have tried it first. renderhjs's just copies it to the clipboard, not any photoshop-side stuff. Ignore me!
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    so far, i've failed to find a way to improve the speed of the JS,
    but i added an "expand" function to it now, so that the borders are increased by 2 pixels:
    1. if selection.count > 0 then
    2.  
    3. (
    4. output_file = createfile "C:Program Files (x86)AdobePhotoshop CSUVWscript.js"
    5. docusize = 1024
    6. format "var docSize = %;n" docusize to:output_file--write to file
    7.  
    8. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    9. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    10. (
    11. format "var V% = Array(" i to:output_file--write to file
    12. mapvert = polyOp.getmapvert $ 1 i
    13.  
    14. --write the first map vertex
    15. arrayvert = mapvert[1]*docusize
    16. intarray = arrayvert as integer
    17. format "%," intarray to:output_file--write to file
    18. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    19. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    20. intarray = arrayvert as integer
    21. format "%" intarray to:output_file--write to file
    22. format ");n" to:output_file--write to file
    23. )--end for i
    24.  
    25. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
    26. --start of map face array. this is the
    27. (
    28. format "selRegion = Array(" to:output_file--write to file
    29. mapface = polyOp.getmapface $ 1 i
    30. NumFaceCons = 0
    31. F = 1
    32. while F < 50 do
    33. (
    34. F = F+1
    35. if mapface[F] == undefined then (NumFaceCons = F-1 exit)
    36. )
    37. for E = 1 to NumFaceCons do
    38. (
    39. arrayfacevert = mapface[E]
    40. format "V%"arrayfacevert to:output_file--write to file
    41. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    42. )--end for E
    43. NumFaceCons = 0
    44. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    45.  
    46. )--end for i
    47. format "activeDocument.selection.expand(2);n" to:output_file--write to file
    48. close output_file
    49. )--end if
    50.  

    i need some way to disable redraw in photoshop...
  • Tumerboy
    Offline / Send Message
    Tumerboy polycounter lvl 17
    don't worry glib, that's why my first post in this thread is blank :P

    Nice work Deja. Could definitely be useful for making good layer masks.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    if I understand it correctly the main flaw in adobes JS workflow is that you NEED to click each time the file > scripts > ... thingy?
    isn`t there a way by passing through some parameters to photoshop?

    e.g here is a maxscript that opens the current texture in photoshop using parameters that are passed through to photoshop
    http://www.scriptspot.com/3ds-max/photoshopselectedmaterial


    now if one could do the same with the scripts to be executed (e.g path to temporary script file) that would be nice. I was already searching but did not found anything yet.
  • Ryno
    Offline / Send Message
    Ryno polycounter lvl 18
    I'm not sure I'm following exactly what you are trying to do here. (Using Max 2009)

    In Unwrap UVW, you can do Tools > Render UVW Template > Mode (choose solid) > Render UV Template.

    This will export an image with solid blocks for the UV elements, and it also includes Alpha. This alpha can be loaded as a selection in Photoshop.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    @Ryno: a few cons:
    - not dynamic in size so you would have to define each time what resolution to use for the photoshop texture.
    - requires to select the UV template so that there is a selection
    - manually delete the layer afterwards after the selection

    in a ideal way you would have:
    - 3dsmax and photoshop running
    then you select the faces in the UV editor - run the script and you would get instantly the selection of that in photohop in the same texture document that matches the objects texture from 3dsmax.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 20
    http://www.zortech.de/uv2psScript.xhtml

    I remember someone posted this a while back. It seems to do exactly what you are doing. Not sure how fast it is, didn't try it yet - but from the video it seems to be very quick. Maybe you can take a look at it?
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    In photoshop, run the script by choosing File - Scripts - Browse... Select the script file from your <3dsmax root>scripts directory. Make sure the photoshop document you wish to use is open AND the active document. Alternatively, you can drag and drop the script file into Photoshop
    - I wish at least that could be avoided out of the box - without assigning shortcuts ect.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 20
    I think there must be a way, but I am pretty new to Photoshop scripting so I haven't found out yet.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    well like I mentioned before the script
    http://www.scriptspot.com/3ds-max/photoshopselectedmaterial
    is particlary interesting as it passes additional parameters to photoshop

    the snippet of the particular part I mean
    1. for b in bitmapsToLoad do (
    2. pathsToExec += """ + b + "" "
    3. )
    4. --DOSCommand execMe
    5. shellLaunch photoshopPath (""" + pathsToExec + """)

    some info about the command 'shellLaunch'
    http://www.cgarchitect.com/vb/4328-blow-up-net-render-2.html#post31906

    e.g
    1. shellLaunch "e:/t.avi" "/play /loop"
    launches the the t.avi file and tells the media player that supports the parameters /play /loop to play and loop the animation.
    So what I would like to know where to read up the parameters Photoshop supports. I am hoping that there might be one that supports to pass through a script to be executed which would solve the misery of the runScript thing in photoshop.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 20
    Ah! Droplets might help...?
    http://www.photoshoplab.com/droplets-for-the-lazy.html

    Also it's worth noting that if you save as a .jsx file and have #target photoshop in the script, it'll launch the app if it's not running. Might be possible to pass parameters to a script too?
    This is VBS example but may work for Javascript too...
    http://dreamweaverforum.info/photoshop-scripting/144009-re-passing-arguments-jsx-file-command-line.html
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    sorry for the wait, i finally managed to get empire total war working :P
    anyways i'm back, and i figured some way to launch the script from 3ds max.

    here's the modified maxscript first:
    1. macroScript saveUVstophotoshop category:"Dejascripts" tooltip:"unwrap UVWs into photoshop selection" Icon:#("GameTools",2)
    2. (
    3.  
    4. if selection.count > 0 then
    5. (
    6. output_file = createfile "C:UVWscript.js"
    7. docusize = 1024
    8. format "var docSize = %;n" docusize to:output_file--write to file
    9.  
    10. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    11. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    12. (
    13. format "var V% = Array(" i to:output_file--write to file
    14. mapvert = polyOp.getmapvert $ 1 i
    15.  
    16. --write the first map vertex
    17. arrayvert = mapvert[1]*docusize
    18. intarray = arrayvert as integer
    19. format "%," intarray to:output_file--write to file
    20. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    21. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    22. intarray = arrayvert as integer
    23. format "%" intarray to:output_file--write to file
    24. format ");n" to:output_file--write to file
    25. )--end for i
    26.  
    27. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
    28. --start of map face array. this is the portion that prints "selRegion = Array(VX,VX,VX.....);"
    29. (
    30. format "selRegion = Array(" to:output_file--write to file
    31. mapface = polyOp.getmapface $ 1 i
    32. NumFaceCons = 0
    33. F = 1
    34. while F < 50 do
    35. (
    36. F = F+1
    37. if mapface[F] == undefined then (NumFaceCons = F-1 exit)
    38. )
    39. for E = 1 to NumFaceCons do
    40. (
    41. arrayfacevert = mapface[E]
    42. format "V%"arrayfacevert to:output_file--write to file
    43. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    44. )--end for E
    45. NumFaceCons = 0
    46. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    47.  
    48. )--end for i
    49. format "activeDocument.selection.expand(2);n" to:output_file--write to file
    50. close output_file
    51. )--end if
    52.  
    53. shellLaunch "C:openscriptinphotoshop.exe" ""
    54. )

    and here's a link to the visual basic application (might only work with photoshop CS1, or on my computer)
    http://www.dejawolf.com/polycount/scripts/openscriptinphotoshop.rar

    put that stuff in C: \

    i found this in the photoshop CS scripting guide:


    Dim appRef As Photoshop.Application
    Set appRef = CreateObject("Photoshop.Application")
    appRef.DoJavaScriptFile ("D: \\Scripts\\MosaicTiles.js")

    just pasted that code into a visual basic console project, changed the name of the script and path, and added a reference for photoshop, and seems to run nicely.
    i'm now going to tinker and see if i can somehow get more stuff done in VB, and see if its faster too.
    oh btw, that console window will show up until the script is done "rendering" the UVs.
    and also, remember to have a picture open in photoshop, or it won't work.
    oh and don't forget to have an object selected in max too.
    very very hacky :P

    oh, and last, its now a macroscript, so you can run it from a button.
    but if you want to test if it works on your computer first, just put -- in front of the line that says macroscript.... etc.
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    i think i might have figured how to do selection with visual basic.
    now i just need to work around these VB 2008 incompatibility issues.. hrm.
    DAMN YOU MICROSOFT!
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    ok, got selection working in VB :)
    doesn't seem to be faster though.. hmm.
    guess i need to work on my selection algorithm then.
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    actually i think this whole scheme is faulty. i think i'll instead try and find out if i can paste
    a black and white image of the UV template that max has rendered, and load that into the photoshop selection quickmask area or something.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    might be faster yes :) and easier to code
  • Titus
    Offline / Send Message
    Titus polycounter lvl 14
    Aslo i render UVs into PNG with alpha channel and it looks in photoshop like separate layer, and you can also select only wire or solid elements ;)
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    made another script.
    this one exports the UVs as vectors into photoshop.
    it doesn't work on objects with more than 1000 polygons though, photoshop just throws an error.
    trying to figure out how to work around this currently:
    1. (
    2. if selection.count > 0 then
    3. (
    4. output_file = createfile "C:UVWscript.js"
    5. docusize = 1024
    6.  
    7. format"app.preferences.rulerUnits = Units.PIXELS;n" to:output_file--write to file
    8. format"app.preferences.typeUnits = TypeUnits.PIXELS;n" to:output_file--write to file
    9. format"app.displayDialogs = DialogModes.NO;n" to:output_file--write to file
    10. format"var docRef = app.activeDocument;n"to:output_file--write to file
    11. format"var letterSubPaths = new Array();n"to:output_file--write to file
    12. format"AddLetterHPath(letterSubPaths);n"to:output_file--write to file
    13.  
    14. format"nfunction AddLetterHPath(inOutSubpaths)n{n"to:output_file--write to file
    15.  
    16. --------------------------------------------------------------------------------------------
    17. --start of vertex operation portion
    18. --------------------------------------------------------------------------------------------
    19.  
    20. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    21. --start of map vertex array. this goes into the V = Array(x,x) part.
    22. (
    23. format "var V% = Array(" i to:output_file--write to file
    24. mapvert = polyOp.getmapvert $ 1 i
    25.  
    26. --write the first map vertex
    27. arrayvert = mapvert[1]*docusize
    28. intarray = arrayvert as integer
    29. format "%," intarray to:output_file--write to file
    30. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    31. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    32. intarray = arrayvert as integer
    33. format "%" intarray to:output_file--write to file
    34. format ");n" to:output_file--write to file
    35. )--end for i
    36.  
    37. ---------------------------------------------------------------------------------
    38. --start of face operations portion
    39. ---------------------------------------------------------------------------------
    40.  
    41. for i = 1 to NMF = polyOp.getNumMapfaces $ 1 do
    42. (
    43. format"var letterPoints = new Array();nn"to:output_file--write to file
    44. mapface = polyOp.getmapface $ 1 i--gets the currently active mapface in the array
    45. NumFaceCons = 0 --variable to hold the number of vertices in the map face array
    46. F = 1
    47. while F < 50 do-- loop that finds out how many vertices is in this map face array
    48. (
    49. F = F+1
    50. if mapface[F] == undefined then (NumFaceCons = F exit)
    51. )
    52.  
    53. for E = 1 to NumFaceCons do
    54. (
    55. UX = E-1
    56. arrayfacevert = mapface[E]
    57. if mapface[E] == undefined then (arrayfacevert = mapface[1])
    58. format " letterPoints[%] = new PathPointInfo;n" UX to:output_file
    59. format " letterPoints[%].kind = PointKind.CORNERPOINT;n" UX to:output_file
    60. format " letterPoints[%].anchor = V%;n" UX arrayfacevert to:output_file
    61. format " letterPoints[%].leftDirection = letterPoints[%].anchor;n" UX UX to:output_file
    62. format " letterPoints[%].rightDirection = letterPoints[%].anchor;nn"UX UX to:output_file
    63.  
    64. )--end for E
    65. NumFaceCons = 0
    66. format "var insertIndex = inOutSubpaths.length; ninOutSubpaths[insertIndex] = new SubPathInfo();n" to:output_file
    67. format "inOutSubpaths[insertIndex].operation = ShapeOperation.SHAPEXOR; ninOutSubpaths[insertIndex].closed = false;n" to:output_file
    68. format "inOutSubpaths[insertIndex].entireSubPath = letterPoints;nn" to:output_file
    69.  
    70. )--end for i
    71.  
    72.  
    73. format "}n" to:output_file
    74. format "var myPathItem = docRef.pathItems.add("", letterSubPaths);n" to:output_file
    75.  
    76. )
    77. )

    oh, and here's a modified UV selection script that only exports the selected UVs in 3ds max into photoshop.
    spent some hours banging my head into the wall trying to figure out how to make UVs render out into a render window. so far i can draw single pixels.
    1. --macroScript saveUVstophotoshop category:"Dejascripts" tooltip:"unwrap UVWs into photoshop selection" Icon:#("GameTools",2)
    2. (
    3. if selection.count > 0 then
    4. (
    5. output_file = createfile "C:UVWscript.js"
    6. docusize = 1024
    7.  
    8. format "activeDocument.selection.deselect();" docusize to:output_file--write to file
    9. format "var docSize = %;n" docusize to:output_file--write to file
    10.  
    11. --get the vertex selection first into the array I, and loop through it.
    12.  
    13. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    14. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    15. (
    16. format "var V% = Array(" i to:output_file--write to file
    17. mapvert = polyOp.getmapvert $ 1 i
    18.  
    19. --write the first map vertex
    20. arrayvert = mapvert[1]*docusize
    21. intarray = arrayvert as integer
    22. format "%," intarray to:output_file--write to file
    23. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    24. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    25. intarray = arrayvert as integer
    26. format "%" intarray to:output_file--write to file
    27. format ");n" to:output_file--write to file
    28. )--end for i
    29.  
    30. for i in polyOp.getFaceSelection $ do
    31. (
    32. --start of map face array. this is the portion that prints "selRegion = Array(VX,VX,VX.....);"
    33. format "selRegion = Array(" to:output_file--write to file
    34. mapface = polyOp.getmapface $ 1 i
    35. NumFaceCons = 0 --variable to hold number of vertices bound together by a map face
    36. F = 1
    37. while F < 50 do --loops through the number of vertices in a face to get the number of faces.
    38. (
    39. F = F+1
    40. if mapface[F] == undefined then (NumFaceCons = F-1 exit)
    41. )
    42. for E = 1 to NumFaceCons do
    43. (
    44. arrayfacevert = mapface[E]
    45. format "V%"arrayfacevert to:output_file--write to file
    46. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    47. )--end for E
    48. NumFaceCons = 0
    49. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    50.  
    51. )--end for i
    52. format "activeDocument.selection.expand(2);n" to:output_file--write to file
    53. close output_file
    54. )--end if
    55.  
    56. shellLaunch "C:openscriptinphotoshop.exe" ""
    57. )
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    some more modifications to the script:

    this time it will automatically figure out the size of your bitmap, based on the size of the diffuse texture applied to the selected object.
    1. macroScript saveUVstophotoshop category:"Dejascripts" tooltip:"unwrap UVWs into photoshop selection" Icon:#("GameTools",2)
    2. (
    3. if selection.count > 0 then
    4. (
    5. if $.material.maps[2].bitmap != undefined then
    6. (
    7. output_file = createfile "C:UVWscript.js"
    8. docusize = $.material.maps[2].bitmap.width
    9.  
    10. format "activeDocument.selection.deselect();" docusize to:output_file--write to file
    11. format "var docSize = %;n" docusize to:output_file--write to file
    12.  
    13. --get the vertex selection first into the array I, and loop through it.
    14.  
    15. for i = 1 to NMV = polyOp.getNumMapVerts $ 1 do
    16. --start of map vertex array. this goes into the V = Array(x,x,x) part.
    17. (
    18. format "var V% = Array(" i to:output_file--write to file
    19. mapvert = polyOp.getmapvert $ 1 i
    20.  
    21. --write the first map vertex
    22. arrayvert = mapvert[1]*docusize
    23. intarray = arrayvert as integer
    24. format "%," intarray to:output_file--write to file
    25. --write the second map vertex. this one is inverted, because of 3ds max's non-conformity!!
    26. arrayvert = (1-mapvert[2])*docusize--the mapvert is a value from 0 to 1
    27. intarray = arrayvert as integer
    28. format "%" intarray to:output_file--write to file
    29. format ");n" to:output_file--write to file
    30. )--end for i
    31.  
    32. for i in polyOp.getFaceSelection $ do
    33. (
    34. --start of map face array. this is the portion that prints "selRegion = Array(VX,VX,VX.....);"
    35. format "selRegion = Array(" to:output_file--write to file
    36. mapface = polyOp.getmapface $ 1 i
    37. NumFaceCons = 0 --variable to hold number of vertices bound together by a map face
    38. F = 1
    39. while F < 50 do --loops through the number of vertices in a face to get the number of faces.
    40. (
    41. F = F+1
    42. if mapface[F] == undefined then (NumFaceCons = F-1 exit)
    43. )
    44. for E = 1 to NumFaceCons do
    45. (
    46. arrayfacevert = mapface[E]
    47. format "V%"arrayfacevert to:output_file--write to file
    48. if E < NumFaceCons then ( format ","arrayfacevert to:output_file)
    49. )--end for E
    50. NumFaceCons = 0
    51. format ");n activeDocument.selection.select(selRegion, SelectionType.EXTEND);n" to:output_file--write to file
    52.  
    53. )--end for i
    54. format "activeDocument.selection.expand(2);n" to:output_file--write to file
    55. close output_file
    56. )--end if
    57.  
    58. shellLaunch "C:openscriptinphotoshop.exe" ""
    59. )--end undefined bitmap for selection
    60. )--end undefined selection
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    nice work man, I will have a look at this later and see how it works
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    renderhjs wrote: »
    nice work man, I will have a look at this later and see how it works

    thanks.
    its not a big change, just changed docusize = 1024 to docusize = $.material.maps[2].bitmap.width
Sign In or Register to comment.