[Closed] get node names and CA from a file without opening it?
I’m trying to write something that will traverse a directory and come up with a list of node names and associated CA’s. My idea is to use the CA’s as a simple tagging system and be able to import all nodes that meet my criteria of tags.
I don’t understand CA’s well enough though. Is it possible to get a node name and list of CA’s without opening the file. I’ve tried fopen, but don’t understand the resulting output. Any help is much appreciated.
here is the basic idea so far:
struct StyleGuide
(
baseDirectory = "C:",
styles = #(),
files = #(), -- should be protected (later on)
fn setDirectory = (
baseDirectory = getSavepath()
),
fn getFilesFromFolder folder:baseDirectory = (
if folder == unsupplied or folder == undefined then folder = baseDirectory
files = #()
for f in ( getFiles( folder + "\\*" ) ) do (
if matchpattern f pattern:"*.max" then
append files f
)
for f in ( getDirectories( folder + "\\*" ) ) do (
getFilesFromFolder folder:f
)
for f in files do print f
-- for f in files do -- check file for nodes with custom attribute "StyleGuide = *"
)
)
Not that I’m aware of or have found. This is a big problem I have with max files. They are pretty much closed off binary files that need to be read in the correct manner… all byte/chunk binary reading stuff… Some people have tried :
http://neiltech.wordpress.com/2013/04/07/reverse-engineering-the-max-file-format/
So without going in that heavy programming direction there are some things that may help if you need to stick to maxscript.
There’s a maxscript function called something like ‘getFileNodes’ (the maxscript documentation is infuriatingly crap at searches…so i cant find it currently). However this function [whatever it’s called] will return a list of nodes in the file… however that is all the information you will get, just a string list.
The only other option i know of, from maxscript, is to xref the file in and then you can search the ref’d node tree for the data.
aXref – xrefs.addNewXRefFile “somefile.max”
aXref.tree.children– objects in the XRef Scene object,
However i’m not sure if all maxscript functions, like acessing CA data, will work if you pass them an xref node… they should, but this is Max…
However xref is pretty much like opening a file – it’s slow and will pop up dialogs that you may not want.
It would be nice if A’desk exposed some decent functions for this type of stuff… but they don’t.
People have gotten creative with writing data you need from a max file to custom filetypes [xml, json, custom binaries] so they can read that instead… but you need to make sure your custom files stay in sync with the max file.
Anyway hope that helps… sorry to be all doom and gloom.
It is possible doing it by reading the binary streams of the max file, as andylt1 says, but it is a bit of work. A very good explanation of how to start parsing max files can be found here: http://www.kaetemi.be/wp/2012/08/17/3ds-max-file-format-part-1-outer-file-format-ole2/
When you got that figured out it is time to start examining the scene tree. I can show an example of a teapot named TeapotWithCA that holds some scripted custom attributes named teapotData.
- First I find the teapot in the scene tree. In this case it is found as scene item nr. 376. It holds an reference to scene item nr. 374 in the datachunk with header 2035. (References are usually found in the datachunks with headers 2034 or 2035)
- Scene item 374 is a Teapot Standard Controllers object. It’s 2034 reference points at scene item 373 which is a ParamBlock item. In this case its a dead end. Comparing this teapot with CA to a teapot without shows that the teapot with CA has an extra child with header 21B0. This item holds another item with value:372.
- Looking up the 372 value in the scene tree leads to a CustAttribContainer item where the 2034 datachunk’s value is 371.
- Item 341 is an item named teapotData which is the name of my custom attributes.
The whole definition can be found in the stream named ScriptedCustAttribDefs:
So all in all it’s about chasing references from scene item to scene item.
That’s some great info haavard, many thanks.
How are you viewing that max data, is it a custom application?
Yeah, I followed the blog posted above to parse the maxfile. The fileAssetMetaData, summaryInformation and DocumentSummaryInformation streams are different though, the first is structured simply as a type and path dump, the latter two are structured storage sets, which was a pain to get working correctly using c#
Thanks for the responses. honestly writing a binary parser is above my head. Its a bummer this isn’t easier; I ended up throwing in the towel and opening every file in the directory tree.I guess I see why people are fans of the .dae format now. I’m just playing around with what I can do in maxscript. Still I’m very impressed with how much people have figured out to get around this limitation. Thanks so much for the info, I certainly will be looking further into xrefs, maybe containers, to see how much functionality they allow for.
Sure, it has been a long time since I touched it though. All you can do for now is snoop around in max files, which is kind of interesting. The plan was to add the ability to query a bunch of max files and e.g. repath data or find which files have specific objects etc, but I graduated and started working so not much time to spare
Here is the source, featuring 0 documentation and probably many bugs:
https://bitbucket.org/havardsc/maxfileparser
thanks =) I was wondering if I could get some info about the materials stored in the material editor of a max file scene without opening it. So let the snooping begin =)