Home Coding, Scripting, Shaders

Unskilled coder trying to find out if something is even possible

polycounter lvl 18
Offline / Send Message
Valandar polycounter lvl 18
So... I'm sitting here, with almost 200 files to repair for 3D printing (99.9% of the issues are solved by 'cap holes'), and need to have both obj and stl versions.

Is there any way to create a script for 3DS Max that will read in an obj, add a "cap holes" modifier, collapse the stack, re-export under the original file name, and then export again as an STL, then delete it from the scene and load in the next obj in the directory, eventually doing this to every obj file in the directory? And if there is, what resources would I use to create this script?

Replies

  • Klunk
    Offline / Send Message
    Klunk ngon master
    copy this into a new script, change the directory text to the directory you want process  and press ctrl-e

    (<br>&nbsp;&nbsp;&nbsp; fn getFilesRecursive root pattern =<br>&nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thedirs = #(root + "/*");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; join thedirs (GetDirectories (root+"/*"))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for d in thedirs do join thedirs (GetDirectories (d+"/*"));<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thefiles = #();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for f in thedirs do join thefiles (getFiles (f + pattern));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thefiles;<br>&nbsp;&nbsp;&nbsp; )<br><br>&nbsp;&nbsp;&nbsp; fn processfile filename = if getFilenameType filename == ".obj" do<br>&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; resetMaxFile&nbsp; #noPrompt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; importFile filename #noPrompt using:ObjImp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setCommandPanelTaskMode mode:#modify; -- addmodtoselection needs this to work<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select objects;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modPanel.addModToSelection (Cap_Holes()); -- cap the holes<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; convertToMesh objects; -- collapse the stack<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exportFile filename #noPrompt using:ObjExp -- overwrite the original and export as stl<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stlfilename = (getFilenamePath filename) + (getFilenameFile filename) + ".stl";<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exportFile stlfilename #noPrompt using:STL_Export; <br>&nbsp;&nbsp;&nbsp; )<br><br>&nbsp;&nbsp;&nbsp; FilesToProcess = getFilesRecursive "c:\\Temp" "*.obj"; -- change to the directory you want to process<br>&nbsp;&nbsp;&nbsp; for f in FilesToProcess do processfile f;<br>)

    backup first this hasn't been tested to any extent so we take no responsibility for what happens next :D
  • Valandar
    Offline / Send Message
    Valandar polycounter lvl 18
    Backup the directory, I assume... and thank you very much!

    Now... can you explain why this works? The last time I did any coding was in Pascal, back in spring of 1987...

    EDIT: Okay, I tried it, and it converted 35 out of roughly 200 then stopped. Aaaah.... apparantly it doesn't read if the OBJ has its extension in all capitals. Bulk Renamer, here I come!

    EDIT EDIT: It worked! Thank you very much! That was who knows how much drudgery avoided.
  • Klunk
    Offline / Send Message
    Klunk ngon master
    :D no probs

    first it collects (including sub directs) from the root dir all the file names with the filetype ",obj" into an array. I then iterates through each filename and processes that filename. The processing is as follows
    reset Max
    import the obj file using the filename
    set the command panel to modify
    select all the objects
    apply a cap holes modifier to them
    collapse the stacks
    export as obj
    export as stl

Sign In or Register to comment.