Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Runtime error: Storage cannot be opened for write

Runtime error: Storage cannot be opened for write

Anonymous
Not applicable
1,546 Views
4 Replies
Message 1 of 5

Runtime error: Storage cannot be opened for write

Anonymous
Not applicable

I am ultimately trying to call CustomFileStream.writeStream.

<bool>writeStream <filename>fileName
	<string>streamName <string>content
	persistent:<bool> noLoadOnSceneLoad:<bool>
	append:<bool>
	persistent default value: true
	noLoadOnSceneLoad default value: false
	append default value: false

 However, I am getting this error:

 Runtime error: Storage cannot be opened for write: <my filepath> 

 I have tried running 3DSMax in administrator mode, and I have tried opening a file with a "w+" mode, but that only produces other errors.  Any help would be appreciated.  My script is below:

 

utility testDataStream "Test Data Stream" (
	Global Dir, new_file
	button testButton "Test Data Stream!"
	button choose_directory "Save file as..." 

	on choose_directory pressed do
	(
		print "choose directory"
		Dir = getSaveFileName caption:"streamData..." \
		types:"Text (*.txt)|*.txt|Excel(*.csv)|*.csv|All Files (*.*)|*.*" \
		historyCategory: "Previus Path Save file..."
		print "print directory:"
		print Dir
	)
 
	
	on testButton pressed do (
		try (
			new_file = createfile Dir
			--filename = getOpenFileName types:"*.txt"
			print "post filename"
			--opened_file = openFile filename mode:"w+"
			print "opened the file"
			if(new_file != undefined) do (
				format "testing file stream...\n" to:new_file 
				--filename = getFileAttribute new_file #directory
				print "write to the stream!"
				directory = Dir as string
				--print opened_file
				CustomFileStream.writeStream directory "testDataStream_param" "my content" persistent:false noLoadOnSceneLoad:false append:false
			)
		) catch (
			format "*** % ***\n" (getCurrentException())
			print "error in creating/writing to file"
		)
		print "done"
	)

 My program output currently is 

 

"post filename"
"opened the file"
"write to the stream!"
*** -- Runtime error: Storage cannot be opened for write: C:\Users\...\test25.txt ***
"error in creating/writing to file"
"done"
0 Likes
1,547 Views
4 Replies
Replies (4)
Message 2 of 5

jakub.holik
Participant
Participant

Hi there,

I just had the same problem in Max 2021 and found a solution. In case anyone else stumbles here looking for it:

There are two interfaces exposed in maxscript CustomFileStream a CustomSceneStreamManager. The the second can work with streams on currently opened scene while the first should be able to work on any file. You can create stream with either of these using CustomFileStream.WriteStream or CustomSceneStreamManager.CreateStream. Documentation states that both can create persistent streams able to survive scene saves and loads and both should do it by default, however it didn't work for me using CustomFileStream.WriteStream even when I specified it explicitly. So the stream got created, I could read it immediately after, but it disappeared on scene save. CustomSceneStreamManager.CreateStream works as documented and expected 😉

 

TLDR: Use CustomSceneStreamManager.CreateStream instead of CustomFileStream.WriteStream

 

Message 3 of 5

robert_bowen
Explorer
Explorer

Where can the settings for these two different FileStreatm modes be found, and how do you ensure you're using the correct one?

0 Likes
Message 4 of 5

jakub.holik
Participant
Participant

Hi Robert,

 

As I wrote, these are not settings but interfaces. Just use this one for creation of streams and you should be golden: http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=GUID-ED92EB20-5E7E-4FC3-81CA-9454D38F97B1 . The downside is, you need to have the scene opened while creating the stream. You can read the stream either with this interface or use the other one: http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=GUID-54E22731-0A26-4156-8515-369866D380EB.

 

K.

Message 5 of 5

robert_bowen
Explorer
Explorer

I see. I guess I didn't know the lingo well enough to know the difference. Thanks!

0 Likes