2

I need to put some code in a MaxScript that will take data from parts of a .txt (or maybe CSV) file and use it to name exported objects etc.

So far iv'e only been using listener to work out scripts and so this is beyond me right now.

Any help appreciated, thanks!

Adam
  • 59
  • 8

4 Answers4

1

Here is a nice short example of opening and parsing a csv file: https://forums.autodesk.com/t5/3ds-max-programming/need-maxscript-help-reading-values-from-a-csv/td-p/4823113

Hoser
  • 749
  • 8
  • 12
  • Is there any benifit to using a CSV over a text file just so i'm aware please? – Adam Jun 11 '19 at 13:10
  • I guess in terms of parsing it might be more predictable. And it's easier to deal with if your data comes from Excel. Otherwise there's probably no real added benefit. – Hoser Jun 12 '19 at 14:12
  • Thanks, I get what you mean. I have managed to get it working so far with "readAllLines". I may need to work out how to reference certain Cells at some point though which may be tricky – Adam Jun 12 '19 at 14:21
0

I would suggest to take a look at FileStream. You should be able to open and read your file using it :)

https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/3DSMax-MAXScript/files/GUID-BB041082-3EEF-4576-9D69-5B258A59065E-htm.html

Jeremy
  • 357
  • 1
  • 6
0

So I have got this far:

adata = (dotnetClass "System.IO.File").ReadAllLines "Job_Log.csv"

print adata

exportFile ((maxfilepath + "\Assets\" ) + "adata" + "_123") #noPrompt selectedOnly:true using:ExporterPlugin.classes[14]

It exports to the correct path and the second line prints the data/name in the .csv file ok, but I cant get that value to be the name it exports as.

It just comes out as "adata_123.obj" instead

Any Ideas?

Adam
  • 59
  • 8
0

This is because in your export line you have adata between double quotes which instead of using your variable use the string value "adata". Try using this snippet instead

assetPath = PathConfig.AppendPath maxfilepath "Assets"
fileName = (adata as string) + "_123"
fullPath = PathConfig.AppendPath assetPath fileName
exportFile fullPath #noPrompt selectedOnly:true using:ExporterPlugin.classes[14]

Note: The "as string" and the bracket might not be necessary on the second line if your variable is already a string.

Jeremy
  • 357
  • 1
  • 6