Home Technical Talk

[Maxscript question] Defining save path and file name

polycounter lvl 6
Offline / Send Message
A-N-P polycounter lvl 6
Hey guys,

I've been working on a small script to make my workflow a little faster at work.

It's a multi .CNT (custom format) exporter.

I want it to export to the defined path using the model name as file name.

eg, C\Users\Greentooth\Desktop\Box001.CNT

and repeat this for every selected model in the scene.

I've been playing around for a few days trying to link up the path and file name but haven't had much luck with it. Hopefully someone can clear this up for me.

I've opened other scripts to see how they do it and they use '+' to add names together, but mine doesn't seem to like it.

Here's the dialog box:
3VzFN75.jpg

Here's the error I get:
aJis0K5.jpg

If someone could have a look over my code to see if I'm doing something incorrectly, that'd be a huge help :)

Thanks!
rollout exporter "Multi .CNT Exporter" width:350 height:140
(
			
			--rollout ui
			editText edt_path "Export Location:" labelOnTop:true
			button btn_browse "Browse..." width:100 height:20 pos:[13,45] 
			button btn_export "Export!" width:100 height:45 pos:[235,78] 
			GroupBox grp_info "Info" width:200 height:60 pos:[13,70] 
			--end rollout ui
			
			on edt_path entered newText do
			(
				savePath = newText
			)
			
			on btn_browse pressed do
			(
				folderPath = getSavePath()
				edt_path.text = folderPath
			)--end do
			
			on btn_export pressed do 
			(
				objName = $.name
				 exportPath = folderPath + objName
				for obj in ( selection as array ) do
				
				(
					sel = selection as array
					i=1

					For i = i to sel.count do 
					(
						Select sel[i]
						objname = $.name
					
						exportfile exportPath #noprompt selectedOnly:true using:ExporterPlugin.Classes[13]
					
					
					)--end selcount do
					
				)--end array do
				
			)--end pressed do		

		


)--end rollout

 createDialog exporter 

Replies

  • martinszeme
    Options
    Offline / Send Message
    martinszeme polycounter lvl 8
    I have no idea, but maybe you can have a peak how this guy did it: http://www.scriptspot.com/3ds-max/scripts/batch-exportimport ?
  • A-N-P
    Options
    Offline / Send Message
    A-N-P polycounter lvl 6
    That's one of the script I've had a look at and can't see what I'm doing differently other than what I've named stuff :(
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    because $ is the same as selection as array.
    If you have multiple objects selected, $ returns an array of all those objects. Hence you can't access the name with $.name.
    Also there is a scope issue, as you define folderpath under "on btn_browse pressed"
    folderpath is local variable, so it is undefined under on btn_export pressed. You have to redefine it.
  • A-N-P
    Options
    Offline / Send Message
    A-N-P polycounter lvl 6
    Thanks for the cleaner code Noors :)

    But I'm still getting the same error when I try to run the script :/

    -- No ""+"" function for undefined <<
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    Yeah sorry, was looking at itduring my death time in a league of legend match. Wait a minute.
  • 2cat
    Options
    Offline / Send Message
    2cat polycounter lvl 5
    Just throwing this out there: since it says "undefined", have you declared it as a string?
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    mmh i'm not able to get using:exporterPlugin.Classes[13] to work.
    What format do you want to save to? Iges ?
    We could simply define the extension.
    on btn_export pressed do 
                (
                    sel = selection as array
                    folderPath = edt_path.text --redefine folderPath here
                    theClasses =exporterPlugin.classes
                    
                    for obj in sel do --for each object in your selection
                    (
                        objName = obj.name    
                        exportPath = (folderPath +"\\"+ objName) 
                        select obj
                        exportfile exportPath #noprompt selectedOnly:true using:theClasses[13]
                    )
                )
    
  • A-N-P
    Options
    Offline / Send Message
    A-N-P polycounter lvl 6
    I haven't defined anything as a string (the script text is above)

    Other scripts don't define the names as strings so I don't understand why mine isn't working :( :P
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    It isn't defined at all. A block inside a "on button pressed" can't acces local variable from an other block. You have to redefine the path. See my code above. Then, you don't have to specifically define the type"as string", Max does it by itself.
  • A-N-P
    Options
    Offline / Send Message
    A-N-P polycounter lvl 6
    Class 13 is a custom format we have here at work. The new snippet you sent works a treat!

    Thank you very much for helping me out man, sorry to pull you from your LoL game :P

    Here's the final script in case anyone wants to use it (you will have to change the exporter plugin class)

    To see the list of classes you have type "exporterPlugin.classes" into the listener window to see what you have installed.

    Here's the final script:
    try ( destroyDialog exporter) catch () --destroys previous dialog if one is open
    
    rollout exporter "Multi .CNT Exporter" width:350 height:140 --creates rollout
    (
    			
    			--rollout ui
    			editText edt_path "Export Location:" labelOnTop:true
    			button btn_browse "Browse..." width:100 height:20 pos:[13,45] 
    			button btn_export "Export!" width:100 height:45 pos:[235,78] 
    			GroupBox grp_info "Info" width:200 height:60 pos:[13,70] 
    			--end rollout ui
    			
    			on btn_browse pressed do
    			(
    				folderPath = getSavePath()
    				edt_path.text = folderPath --copies savepath to text box above
    			)--end do
    			
    			on btn_export pressed do 
                (
                    sel = selection as array
                    folderPath = edt_path.text 
                    theClasses =exporterPlugin.classes
                    
                    for obj in sel do 
                    (
                        objName = obj.name    
                        exportPath = (folderPath +"\\"+ objName)
                        select obj
                        exportfile exportPath #noprompt selectedOnly:true using:theClasses[13]
                    )
                )
    )--end rollout
    
     createDialog exporter
    
Sign In or Register to comment.