Batch Import .stp files into 3ds max 2020

Batch Import .stp files into 3ds max 2020

Roger.Bastow
Participant Participant
2,600 Views
10 Replies
Message 1 of 11

Batch Import .stp files into 3ds max 2020

Roger.Bastow
Participant
Participant

Hi, this is my first post and I really hope someone could help. 😃

 

I need to Batch import about 2000 .stp files into 3DS max 2020. Is there a script that would cover this, or could someone support in writing one?

 

Kind regards

Roger

0 Likes
2,601 Views
10 Replies
Replies (10)
Message 2 of 11

miauuuu
Collaborator
Collaborator

I don't have .step files to test the code. IF the extensions of your file is .stp you have to modify the code(replace .step with .stp).

The script allows you to select folder where step files are located. You can't select step files separately.

 

 

(
	function GetFilesRecursive root pattern =
	(        
		dir_array = GetDirectories (root+"\*")
		for d in dir_array do
			join dir_array (GetDirectories (d+"*"))    
		
		my_files = #()                
		for f in dir_array do
			join my_files (getFiles (f + pattern))
				
		my_files
	)
	
	dir = getSavePath caption:"Select the directory" initialDir:"$scenes"
	if dir != undefined do
	(
		filesArr = #()
		filesArr = getFiles (dir+"\*" + ".step")
		subFiles = GetFilesRecursive dir ("*" + ".step")
		if subFiles.count != 0 then
		(
			msg = "The selected folder has subfolders!\n"
			msg += "Do you want to include the files from the subfolders too?"
			if queryBox  msg title:"Sub-folders found" do
				join filesArr subFiles
		)
		
		if filesArr.count != 0 do
		(
			for f in filesArr do
			(
				importFile f #noPrompt
			)
		)
	)
)

 

https://miauu-maxscript.com/
0 Likes
Message 3 of 11

jetboy_hrn1990
Community Visitor
Community Visitor

 Thank you.
I change to  extension to STL. This Script Work STL files. STP cant include.

0 Likes
Message 4 of 11

miauuuu
Collaborator
Collaborator

Just tested on max2020 with some STP files downloaded from the internet and the script does work:

 

(
	function GetFilesRecursive root pattern =
	(        
		dir_array = GetDirectories (root+"\*")
		for d in dir_array do
			join dir_array (GetDirectories (d+"*"))    
		
		my_files = #()                
		for f in dir_array do
			join my_files (getFiles (f + pattern))
				
		my_files
	)
	
	dir = getSavePath caption:"Select the directory" initialDir:"$scenes"
	if dir != undefined do
	(
		filesArr = #()
		filesArr = getFiles (dir+"\*" + ".stp")
		subFiles = GetFilesRecursive dir ("*" + ".stp")
		if subFiles.count != 0 then
		(
			msg = "The selected folder has subfolders!\n"
			msg += "Do you want to include the files from the subfolders too?"
			if queryBox  msg title:"Sub-folders found" do
				join filesArr subFiles
		)
		
		if filesArr.count != 0 do
		(
			for f in filesArr do
			(
				importFile f #noPrompt
			)
		)
	)
)
https://miauu-maxscript.com/
0 Likes
Message 5 of 11

denisT.MaxDoctor
Advisor
Advisor
getfiles "c:/temp/*" recurse:on

 

getfiles has an option #recurse. You don't need a custom method for recursion.

0 Likes
Message 6 of 11

miauuuu
Collaborator
Collaborator

I know. 🙂

This was a copy-paste from a very old code.

https://miauu-maxscript.com/
0 Likes
Message 7 of 11

denisT.MaxDoctor
Advisor
Advisor

@miauuuu wrote:

I know. 🙂

This was a copy-paste from a very old code.


be modern ☝️😎

0 Likes
Message 8 of 11

miauuuu
Collaborator
Collaborator

OK. 🙂

 

(	
	dir = getSavePath caption:"Select the directory" initialDir:"$scenes"
	if dir != undefined do
	(
		filesArr = getFiles (dir+"\*" + ".stp")
		files02Arr = getFiles (dir+"\*" + ".stp") recurse:on
		if files02Arr.count > filesArr.count do
		(
			msg = "The selected folder has subfolders!\n"
			msg += "Do you want to include the files from the subfolders too?"
			if queryBox  msg title:"Sub-folders found" do filesArr = files02Arr 
		)
		if filesArr.count != 0 do
		(
			for f in filesArr do importFile f #noPrompt
		)
	)
)
https://miauu-maxscript.com/
0 Likes
Message 9 of 11

denisT.MaxDoctor
Advisor
Advisor

 

 

(	
	recurse = on
	dir = getSavePath caption:"Select the directory" 
	if dir != undefined do
	(
		path = pathconfig.appendpath dir "*.stp" 
		filesArr = getFiles path recurse:recurse
		for file in filesArr do importFile file #noPrompt
	)
)

 

initialdir

doesfileexist -- I was wrong!

pathconfig.appendpath

if filearr.count != 0

🙂

 
0 Likes
Message 10 of 11

miauuuu
Collaborator
Collaborator

What if we want to tell the user that there are subfolders with .stp files and to ask if those files has to be included?

https://miauu-maxscript.com/
0 Likes
Message 11 of 11

denisT.MaxDoctor
Advisor
Advisor

To the question of how to select files for batch processing - recursively or not. In general, it doesn't matter, but batch processing in any case implies preliminary preparation, and in practice, it makes no sense to give options during the process, but it is enough to set conditions in advance.