Notifications
Clear all

[Closed] Loading a string from an external file

Hey all,

I’m pretty sure this is going to be an easy one. I have an exporter script that i am building and i have to add alot of the code in the output file using strings. No problem there. What i would like to do is have a seperate file that the user can add to and the exporter will use the contents of that file when it builds the string. I have used stringstream with values before to do keyframes but not sure about this because the data (material callouts) the user will be adding looks like this:


 DEF BODY Material {
 	ambientColor 0.5 0.5 0.5
 	diffuseColor .156 .625 .977
 	specularColor 0.5 0.5 0.5
 	shininess .5
 		}
 DEF GLASS Material {
 	ambientColor .5 .5 .5
 	diffuseColor .3 .3 .3
 	specularColor.7 .7 .7
 	shininess .1
 	transparency .5
 		}
 

So the user would open up a text file and then just keep adding the different material callouts. Then when the exporter is run i could assign the contents of the text file to a string and then use format to put it in the exported file where it needs to go.
Hope that was clear…and i hope you guys can help…this is the very last small hurdle before i finish this thing. As always …thanks.

2 Replies

It’s not very clear, but I guess you want to read the text file and detect whether you read a new “DEF” or a property. Why don’t you use XML files ? They are easier to parse.

I’m just starting to put more time and effort into learning maxscript…its coming along. I’m basically trying to have a document that the end user can update with new materials like the ones above. like for instance if they wanted an interior material…they would add this to the bottom of the list:


   DEF INTERIOR Material {  	
 ambientColor 0.5 0.5 0.5  	
 diffuseColor .156 .625 .977  	
 specularColor 0.5 0.5 0.5  	
 shininess .5
 }
  

So when they run the exporter it will go into the text file and grab everything in it and assign it as a string value when exporting. This may not be the best way of doing this. The material callout list will always continue to grow so i’m trying to avoid having to update the script every time a new material needs to be added. Could filein be used for this?

Apologize for the newby questions…