XML exporter

bernardo's picture

hello everyone... its my time to start to learn objective C and the cocoa realms... i'll be trying to make an Structure exporter to XML file.

if anyone wants to join in please do...

will be back soon bern

dust's picture
Re: XML exporter

file tools or structure tools saves a structure to file in binary plist format. (.plist) being kind of inherently xml sort of depending on the serialization method.

there are a ton of ways to do this with cocoa, core foundation, c, and strings etc. the idea if you want to roll your own is to write a string line by line down to file in a for keys in dictionary loop. the cool thing is you don't even need to do this. ;)

when your saving your data or in this case copying data down to file cocoa has some really cool automatic features like automatic.

xmlData writeToFile:path atomically:YES

to serialize your data down to xml automatically you would do something like this.

pay attention to this part

NSPropertyListXMLFormat_v1_0 

what kineme structure tools is doing is this and if you want to generically use your xml in a data base then the above mentioned method of serialization is the way to go.

NSPropertyListBinaryFormat_v1_0

so make sure to write a file automatically and serialize something like this.

 
 
//.h
@property bool inputWriteFile;
@property NSString* inputFilePath;
@property NSMutableDictionary* inputStructure;
 
 
//.m execute
 
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:2];
 
for (keys in self.inputStructure) {
[rootObj setObject:self.inputStrucutre forKey:keys];}
 
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj];
 
NSString *path = self.inputFilePath;
 
 
NSData *xmlData;
NSString *error;
 
xmlData = [NSPropertyListSerialization dataFromPropertyList:plist
                                       format:NSPropertyListXMLFormat_v1_0
                                       errorDescription:&error];
if(xmlData) {
    NSLog(@"No error creating XML data.");
    [xmlData writeToFile:path atomically:YES];
}
else {
    NSLog(error);
    [error release];
}

so some thing to take into consideration are the indexing of the structure. meaning dictionary doesn't pull the correct order all the time.

to get around this you can use a nsarray as you can automatically write an nsarray just like you can a nsdictionary.

basically you would be making the qc strucutre a type nsarray and just use copy array to dictionary method. or loop through your array using objectAtIndex[i] where i is your key. once it is in a dictionary you can sort by key in acceding or descending orders etc..

or you could try to simply assign your qc struct like this and forget copy to dictionaries and sorting etc...

id plist = [NSPropertyListSerialization dataFromPropertyList:(id)self.inputStruture];

the later probably being the fastest solution. what your doing is assigning the data in the property list your qc structure by type of id; id being the format qc makes it structure in which can vary. example a get mesh component may be a different type (id) of array than that you can get from a queue etc...

so maybe and this is theory as i have not tested it yet but more than likely the id that qc decides to hold its structure is in a xml (plist) friendly format meaning there may be no need to store it in another ivar to assign or serialize.

now to try the later mentioned serialization don't use qc's dictionary methods for declaring and naming ports as it is not necessary. as simply declaring @dynamic inputStructure creates your in out ports from the @property getters and setters. so change...

 @property(assign) NSDictionary* inputStructure;
 
//to
 
@property(assign) id inputStructure

if that works then you can assign your qc input output dictionary and serialize the plugin if you like. hope this helps or consult apple docs on this subject....

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/P...

bernardo's picture
Re: XML exporter

yes yes yes dust i am looking at it right now trying as we speak´be bqack soon

bernardo's picture
Re: XML exporter

hi dust what kind is the variable keys in: for (keys in self.inputStructure) {

bernardo's picture
Re: XML exporter

NSString...

dust's picture
Re: XML exporter

opps forgot you would want to say id keys; the for keys in structure. by saying for keys in structure is like a regular for loop, but with dictionaries the index's are keys so they could be words not numbers so you can't go

for(i=0;i<structure.length;i++){}

or well you can but you would have to copy to an nsarray and then loop by index length.

there is also fast enumeration for dictionaries. all your doing is looping through the whole dictionary like a regular for or while loop etc...

NSEnumerator *enumerator = [self.inputStructure keyEnumerator];
id key;
 
while ((key = [enumerator nextObject])) {
    /* code that uses the returned key */
}

this is assuming that your structure from qc is a dictionary, for enumeration that is. i'm pretty sure the qc default is a dictionary so i don't think you will have to loop through anything. just assign self.inputStructure to your plist like i mentioned in the latter part of code above.

it took me a bit to grasp for key in struct or a for each loop. i'm like no i want to do this with [i]; it speeds things up but like i said you will have to compare the structures once you have wrote them to file to make sure the order is the same.

dust's picture
Re: XML exporter

if you need help my skype is "ter.maximus" and aim is "dvjdust" my gtalk and facetime is "dustin.oconnor@gmail.com" i pretty much wrote the code for you here but i left out a few things so you may need some help not sure if you have built a plugin yet or not.

dust's picture
Re: XML exporter

you can use the log and return the id of the input qc structure to see what it is. sorry i haven't actually made one of these kineme did a good job with there structure to file patch so i use that. a good idea for upgrade to structure to file patch would be to add xml ascii format instead of binary format. what are you actually trying to do. make a xml file and use it in database or something ?

bernardo's picture
Re: XML exporter

hi dust i sent the invite in gmaill.....

bernardo's picture
Re: XML exporter

yes dust i think i export the structures to plist and i gets all messed up so i wanna make rightfully ordered my structs ar XYZ points in a 3d space so i decide to build my own

dust's picture
Re: XML exporter

here is a working executable function.

- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
 
   BOOL writter = self.inputWrite;
   if(writter) 
   {
      NSString * error;
 
      NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:2];
 
      NSDictionary *childDict;
 
        childDict = [NSDictionary dictionaryWithDictionary:(NSDictionary*)self.inputStructure];
 
      [rootObj setObject:childDict forKey:@"root"];
 
        id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj
                                               format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
 
      NSString *path = self.inputPath;
      [plist writeToFile:path atomically:YES];
 
   }
 
      return YES;
}

if you want to make sure everything is ordered use a timestamp for key and sort the dictionary descending or acceding before you write to disk. actually a predicate sort term input might be cool. test it out...

gtoledo3's picture
Re: XML exporter

If that's what you are trying to accomplish, consider your logic.

If you are exporting to XML, you are writing strings. Then, when you bring this XML back into QC, instead of dealing with structure, you are taking strings, and converting them back to structure. I can't stress how inefficient this is enough (though possible). If it must be, then it must be, but I am not aware of any reason why this would ever be a good idea for dealing with structures of coordinates.

If your coordinates are "jumbling up", you may not be creating them in a way that will maintain order when you "bring them back into" QC. Sometimes, within QC, this won't make a difference, but will exhibit itself when trying things like you're doing (or even within QC, in certain scenarios).

Try something like this before your gnashing of the teeth:

function (__structure vars) main (__number inputNumber[4])
{
     var result = new Object();
     var array = new Array();
 
 
   array[0] = inputNumber[0];
   array[1] = inputNumber[1];
   array[2] = inputNumber[2];
   array[3] = inputNumber[3];
 
        result.vars = array;
   return result;
}

This will make it so that the structure that is written will always maintain order within a given index. If you write this to a Queue, it should reload fine as well. Seriously do yourself a favor and try this first, unless I'm totally misunderstanding your problem.

Also, "structure to xml" is somewhat of a meaningless phrase, or overly general.

bernardo's picture
Re: XML exporter

oh well gToledo3, i have to disagree with you on this: Also, "structure to xml" is somewhat of a meaningless phrase, or overly general. its crucial for me l for my project because i am not just using in qc but in other softwares such as 3dsmax (PC) and other....

i already tried it and the problem persists as i have no way to use the coords between comps and so on... and also i wanna create a small database for my coords so that i can reuse them in another instances...

the problem with NSDictionary it seems is that there is no way to reorder them... i already went the javascript way with this:

function (__structure outSorted, __number len) main (__structure inUnSorted, __number count)
{
   var result = new Object();
   var tempArray_sorted = new Array();
   if (!_testMode){
 
   //var tempArray_sorted = new Array();
    tempArray_sorted = inUnSorted.sort();
 
   for (i= 0; i < inUnSorted.length; i++)
      {
         tempArray_sorted[i] = new Array();
         tempArray_sorted[i][0] = inUnSorted[i][0];
         tempArray_sorted[i][1] = inUnSorted[i][3];
         tempArray_sorted[i][2] = inUnSorted[i][1];
         tempArray_sorted[i][3] = inUnSorted[i][4];
         tempArray_sorted[i][4] = inUnSorted[i][2];
      }
      var _len = inUnSorted.length;
      result.len = _len;
      result.outSorted = tempArray_sorted;
   }
    return result;
}

but it stopped working when i attached it to Kineme GL lines ...... the game continues...

bernardo's picture
Re: XML exporter - Paths or not Paths

hey dust for now it works ok and still trying to add a timestamp right now fighting the relative file path thing so that no problem is raised when ~/ path is entered or just the file name or a full path...

 NSString *path = self.inputPath;
      if([path length] != 0)
      {
         // is it an absolute path?  if so, don't do anything
         if([path characterAtIndex:0] != '/')
         {
         //NSString* path = [[NSBundle mainBundle] path];
         NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
         NSLog(@"current BUNDLE path : %@", bundlePath);
 
         path = [NSString stringWithFormat:@"%@/%@",bundlePath,path];
 
         //stringWithFormat:@"%@/%@"
         }
 
         else
         {   // it is a ~ directory, expand it
 
               path = [path stringByExpandingTildeInPath];
         }
 
 
      }
 
      [plist writeToFile:path atomically:YES];
      NSLog(@"current path : %@", path);

but i am getting an error it loads the path of quartzcomposer and not the composition....

gtoledo3's picture
Re: XML exporter

bernardo wrote:
yes dust i think i export the structures to plist and i gets all messed up so i wanna make rightfully ordered my structs ar XYZ points in a 3d space so i decide to build my own

....[sigh]....

bernardo's picture
Re: XML exporter

?

dust's picture
Re: XML exporter - Paths or not Paths

you can write a path like this.

path = self.inputPath; [path self.inputPath];

this is what is causing the path to be qc.... [[NSBundle mainBundle] path]

forget path... just do this !

[plist writeToFile:self.inputPath atomically:YES]

bernardo's picture
Re: XML exporter - Paths or not Paths Composition-relative...

well i got it working with tilted paths and non tilted paths, except Composition-relative paths where i would only enter the name of the file... and save within te composition dir....

bern

bernardo's picture
Re: XML exporter - Paths or not Paths

yes and this does not work in any of the cases only for full paths... still searching i got this from spark Toby harris titler:

in the m. file

[QCPatchController setValue:[[NSBundle mainBundle] resourcePath] forKeyPath:@"patch.ResourceFolderPath.value"];

just don' know how to implement...

dust's picture
Re: XML exporter

just to be clear this exports a plist file in ascii xml formatting not stepped not binary etc..

george there are to many needs for xml to ignore your comment. like one use is qc wouldn't work without xml as the graph needs it...the whole qc model would collapse without xml.

there are so many useful things an xml exporter could be used for george. i thought it was a good idea and not difficult for me to help bernado as i spent last summer using xml for a mobile iphone internship so i pretty much got xml down in cocoa and unity etc... i found my self writing xml files with kineme text writer as strings from qc to test my mobile apps rss etc..

arguably george you have a point as there are much better ways than xml as we all know xml is not that fast and json or some other fancy technology. xml does however leverage a universal standard in formatting that makes it highly useful for inter application cross platform communications etc..

right now i'm writing thinking about using the xml to store image data for training models of patterns. like haar with open cv uses. have tried with kineme's plist writer and am able to save a float4 down to plist but can not read it for some reason. the formatting is a bit different as its not a dictionary its an array but an array should be compatible with plist ?

goerge there are to many good reasons why someone would want an xml exporter in qc. don't really know what say you must be having a bad day. have you had your coffee yet ?

dust's picture
Re: XML exporter

like i originally wrote and the thing you questioned about (for in loop) needs to be put in the code or actually enumeration needs to be used. basically you store your keys into a separate array then use that array to order your dictionary before writing the file. here i will change the executable a bit. it seems you need to [release error] if you can not write the file which is unconventional and normally you wouldn't need to release an error message but with writing properties you need to. its pretty simple i will make another executable for you rather than writing the code into here from my head. ;)

bernardo's picture
Re: XML exporter

:) i am looking at the NSXMLDocument Class Reference docs right now.... to see if it helps right now... missed your comment

dust's picture
Re: XML exporter

i use nsxml to parse rss normally but im sure there are some goodies in there like caching data etc..

here is an executable that keeps order. by copying the keys to an array and using a selector of "caseInsensitiveCompare" see "localizedCaseInsensitiveCompare" for different sort return options.

so grab the keys from the input structure. a qc structure uses keys whether you make them or not. actually if you just assign the qc struct to the plist like..

 id plist = [NSPropertyListSerialization dataFromPropertyList:(id)self.inputStructure
                                                            format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

you will keep the order but the xml will include the key in the returned saved structure. so you would have to use all odd index's for iterating to get your ordered values. so by saving the keys and sorting them you can then add your values to a second array by the sorted key index which in turn you can use to write your xml file in the correct order.

this code inside a for in or enumeration loop will adds the values to the ordered array from the qc structure by sorted keys.

 index addObject:[self.inputStructure objectForKey: [sortedKeys objectAtIndex:i]]];

here is the executable and a project file to test with..

- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
 
    BOOL writer = self.inputWrite;
    if(writer) 
    {
        NSString * error;
 
      NSEnumerator *enumerator = [self.inputStructure keyEnumerator];
      id key;
 
      NSMutableArray *index = [[NSMutableArray alloc] init];
 
      NSArray *myKeys = [self.inputStructure allKeys];
      NSArray *sortedKeys = [myKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
 
      int i = 0;
      while ((key = [enumerator nextObject])) {
          {
             [index addObject:[self.inputStructure objectForKey: [sortedKeys objectAtIndex:i]]];
 
             i++;
         }
      }
 
 
        id plist = [NSPropertyListSerialization dataFromPropertyList:(id)index
                                                              format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
 
 
      if(plist) {
         NSLog(@"No error creating XML data.");
         [plist writeToFile:self.inputPath atomically:YES];
      }
      else {
         NSLog(error);
         [error release];
      }
 
 
 
    }
 
   return YES;
}
PreviewAttachmentSize
amorim_xml.zip2.37 MB
ordered_xml.qtz24.33 KB

gtoledo3's picture
Re: XML exporter

1- XML has formatting and standardization that is pointless to induce (in my opinion), when txt file writing is already available, and a cross-platform file type.

For example, are tags going to be added to the struct? If so, why, if not, why not? Sounds like a question there isn't an answer for, hmm?

2- The struct / vert info that is trying to be read, and is coming back in a "wrong" order, wasn't written the correct way.

3- Structs that use only numbered indices (ala array) are going to be be faster than keyed name structs.

4- These structs can be reordered, but also can be made to load correctly ( my sample js writes the struct in a way that won't "jumble").

5- Structs in QC are barely fast enough to be doing useful vert/normal/color, etc info, much less converting it all from string. Can you draw a sphere, or maybe a model? I'm sure. Will you be looking at seconds go by on your wristwatch, or get up to go get a breath of fresh air and still have QC trying to deal with a whole models worth of verts? Likely for substantial work.

6- When I write that it's slow, it's because I've actually done this already.

I see this as someone who is using the tools available incorrectly, and then decides that a new tool is needed.

Now, do I think it's good to have an xml writer, in general? Sure.

This is like watching someone invent the pen because they are certain that the pencil doesn't work, but the pencil needs to be sharpened, not because they need an indelible mark.

dust's picture
Re: XML exporter

in the event you want to use associative keys and not index's i suggest maybe just copying the qc strucutre to a dictionary and writing one file that is your dictionary and another file that is sorted order of keys. that way you could access a particular value by key but if you need an ordered dictionary you can use the qc sort patch to sort the dictionary plist with the sorted keys array file. give it try tell me if it works for you.

bernardo's picture
Re: XML exporter

well i'll try to answer the best i can i don't like the font size though... are those quotes from what?

wel te first question... as Qc is for data maipulation you should be able to add tags so that another prog can read also: check NSXMLDocument is a must...

2 - it was written i the best order available including pre-parsing it via the javascript above before writting the plist file.

3 - speed is a matter of time.. just wait and it will be fast enough

4 - resaid

5 - well i import a xml structure that was 22mb long for a Kineme gl quad structure patch and it was behaving at 22fps that was fast for me...

6 - slow is a matter of speed, yesterday was fast enough

i must disagree with your conclusion. stop throwing dust and bring some resolution to the problem.

as for the pencil thing ... nasa your famous space agency paid really huge amounts for a ballpen that worked in space due to gravity unawareness... the russians used a pencil... i use carandache....

as for the tools used incorrectly i started by saying that i am learning objectiv C cocoa realms for me....

dust's picture
Re: XML exporter

didn't know you where so against xml george but agreed there are better protocols. i have been liking tho mo for passing objects around in addition to osc etc...

the issue that bernado is dealing with is that a qc struct is inherently a nsdictionary. an nsdictionary does not keep ordering and uses keys that are strings so using a key XYZ works as the char code value for x is less than y etc.. but if you XYZW as key strings it messes the order as W comes before X in char code.

even in qc with java script when assign a structure to an array the order gets messed up. where you actually have to loop through the qc structure and assign the values to your new javascript array. that is sort of the issue when dealing with dealing the nsdictionary.

i think using a timestamp as key is good approach to this problem as well, as its very easy to do a predicate sort based on event time stamps.

bernardo's picture
Re: XML exporter

hey dust really a big thanks i am working on a version using NSXMLDocument to be able to export with tags... to import it on another prgs.... will be back tomorrow... i allready got the export process workin but the sorting is all wrong... keep hitting it and learning alot. really thanks 3d if need just ask for it...

bernardo's picture
Re: XML exporter

and the path problems will go on

simply how to get the composition-relative path into an NSString so that i can use to save there

thks

dust's picture
Re: XML exporter

Quote:
For example, are tags going to be added to the struct? If so, why, if not, why not? Sounds like a question there isn't an answer for, hmm?

the tags look like this when you output an ordered array.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
   <string>dust</string>
   <string>is</string>
   <string>ordering</string>
   <string>structures</string>
</array>
</plist>

certainly you can wrap that whole array in a dict and key you use for that the dictionary will become the tag. so if i put the qc strucutre into a dictionary with the associative key root the xml will print as root tag followed by which is dictionary followed and so on down the line. maybe i'm not understanding the question.

sure there may be some bugs as you got to test these things right now it seems to be ordering fine by using a kineme structure maker. getting it to work with kineme named structure maker is the next step but i think this is a rarely used feature for doing qc work as iterating by index is usually what you want to do.

dust's picture
Re: XML exporter

well the composition relative path would be where ever the comp is located in which case you would want to use an absolute path to get to that directory. otherwise you can step out of the relative plugin path by using ../.../...../ etc... just remember that if you need a relative path to the plugin it is inside the qc application bundle but if you need a relative path to a composition its best to put the composition into the repository and use comp info to pull a path. why does @"~/Desktop/" not work ?

dust's picture
Re: XML exporter

if you got any rigged 3d models you have made i could use them in the iphone game i'm making. i try to make everything myself. low poly for realtime under 2000 verts rrrrrr.

so if you got any models suited for that type of thing i could use them. i'm getting tired of using a model of my self even though i made my self young and invisible i mean beautiful i could always use more. i don't use 3d max but i use maya and cheetah. cheetah being better with vertex skinning in my opinion.

i mean any type of assets that you have made could help. i find asset creation in the art of interactive game design to be the most time consuming.

gtoledo3's picture
Re: XML exporter

I'm not against xml. I think that a re-read of my posts would clarify that.

A QC struct is not inherently a dictionary. QC structs are backed in multiple ways that we don't see, and abstracted and represented in multiple ways within QC.

One can create an array that stays in order already. This is the point I am making, with great futility apparently. I'm not being a stick in the mud, or criticizing xml.

If I want to keep track of a list of vec4's I can create them as 1, 2, 3, 4 knowing that x=1, y=2, z=3, w=4, eg, making an Array, ala the sample JS I posted. When I load a structure created like this, it loads in the correct order. If I manipulate it within QC in way that people complain about "why is this out of order" when they are using x/y/z/w instead of 1/2/3/4, it stays in order. One can already do this without a new patch. I was simply trying to point out the most direct route.

If I write the structure x,y,z,w, it's not crazy to expect it to come back in the order it does, because one would be expected to be utilizing keys to get the info that you want. Who cares if it lines up 1, 2, 3, 4? All that matters is if the first index x, y, z, w comes back as index 1, if you're creating struct that way (to QC, or even in other scenarios/systems). This is why one needs to make the "keys" numeric, and create the array in this way (or in a similarly applicable way).

Eh, forgive me if I haven't explained myself well yet again, or if I've misworded anything in this post so that it's unclear.

Making an xml exporter doesn't solve the fundamentally non-working premise.

gtoledo3's picture
Re: XML exporter

The big type is because I write a "#" symbol. Sometimes I forget that the code here does that. Writing the "#" symbol in front of numbers is a habit.

-1- I don't think we're following each other. My point is that if one is creating an xml file, which is string, then it brings up a salient question. This question is, should one be converting the structure to the correct string format within QC, including the actual header? That seems absurd, though it seems like you contemplate that kind of heavy lifting as being reasonable. Then, I'm not convinced about autoformatting either, though what Dust has described as his result seems reasonable at first read.

-2- I'm not convinced that you are using functional javascript if you're having a problem maintaining order, since I know that this is possible already.

-3- What is that supposed to mean? "Just wait and it will be fast enough?" Wait for what? For QC to get a rewrite so that it doesn't take a crap anytime it tries to load a big file, and subsequently parse it? You got 22fps, but how long did it take to load if you try to immediately render every bit of xml info as a vertex? Did it not hiccup, or beachball? If not, that's actually really awesome.

22fps what? At what res? 22fps is meaningless.

-4- errrr....

-5/6- Hey, if it's fast enough for your project, awesome. My greater point was only about structures, keeping them in order, loading them, and that all of that is already possible with all of the rigamorole of a new plugin. Secondly, structures in QC as is are pretty arguably not fast. I would be really interested to hear an argument counter this. By extension, taking string, and converting it to structure is commensurately bad idea territory, unless you just have to do it. It sounds like you do, but again, correct structure creation and txt are already available to you. An xml exporter is a cool idea, but I don't think it inherently solves your problem.

I'm not throwing any dust. I'm trying to bring resolution to your problem by teaching you how to create a structure that stays in order, and saving you time of writing a plugin (which I will probably benefit from), but which likely won't solve your problem, to which I am getting a really grateful response.

Frankly, I don't even know what to say about the nasa comment. I'm not nationalistic, and I find your citing an example of bureaucratic incompetence, and making it a nationalistic thing (as IF there is a government in existence that doesn't suffer from the foibles of humanity), is in poor taste. Lets keep the conversation out of the gutter. I'm a fan of strong language, but lets keep this place free of politics, religion, and lolcats.

dust's picture
Re: XML exporter

Quote:
A QC struct is not inherently a dictionary. QC structs are backed in multiple ways that we don't see, and abstracted and represented in multiple ways within QC.

yes george qc deals with structures in multiple ways. but this thread isn't about maintaing order of structures within qc it is about dealing with structures in a plugin context.

for the sake of argument a QC Structure is a NSDictionary when dealing within a plug-in context.

try this in the log.

NSLog(@"a qc struct is of type %@", [self.inputStrucutre class]);

it prints...

2010-10-31 07:50:07.040 Quartz Composer[1228:a0f] a <qc struct> is of type NSCFDictionary

qc reports a float4 structure as a qc stream next index down the line is a NSCFArray. that is inside qc but a qc stream in a plugin context is a NSCFDictionary which is a NSDictionary the CF standing for core foundation. i don't want to get into a polymorphic debate over what a structure inherently is but this is what your dealing with in a plugin. so it really doesn't matter what qc thinks.

as an example this executable saves a float4 down to an xml file. in the blink of an eye you can save over 300,000 pieces of data or iterations. i'm talking a low res image as an example. thats (320 times 240) times 4. last time i tried to queue up and iterate over 1000 times with an iteration patch qc beach balled. so there is some power in using plugins and open cl as opposed to doing everything visually.

the difference here is there is that a float4 keys are nsnumbers and not strings like most keys are. so the executable at the bottom of the page is dealing with keys that are strings and ordering them. and this one deals with keys that are numbers and ordering them.

so you see it is irrelevant to how you make your structure in qc because an nsdictionary doesn't hold its ordering period. there are fancy libraries and sub class methods people use to re format dictionaries but the key is knowing your key's data types.

- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
 
    BOOL writer = self.inputWrite;
    if(writer) 
    {
        NSString * error;
      NSLog(@"a <qc struct> is of type %@",[self.inputStructure class]);
 
 
NSEnumerator *enumerator = [self.inputStructure keyEnumerator];
 
id key;
 
NSMutableArray *index = [[NSMutableArray alloc] init];
 
int i = 0;
 
while ((key = [enumerator nextObject])) {
 
NSNumber *dex = [NSNumber numberWithInt:i];
               [index addObject:[self.inputStructure objectForKey:dex]];   
 
 
                  i++;
 
            }
 
 
            id plist = [NSPropertyListSerialization dataFromPropertyList:(id)index
                                                     format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
 
 
            if(plist) {
               NSLog(@"No error creating XML data.");
               [plist writeToFile:self.inputPath atomically:YES];
            }
            else {
               NSLog(error);
               [error release];
            }
 
 
 
         }
 
         return YES;
      }

gtoledo3's picture
Re: XML exporter

The structure holds order if you number it.

bernardo's picture
Re: XML exporter

well you should revise your strong lsnguage. As for nations, if the example may not have the best for that i am sorry but they werethr only ones attending the space race.. It seems to me that rendering an xml that is not ordered is useless its a markup language if its not ordered its not a language. Now for making arrays to number them thats is still useless for the tags that make the xml are not thereas u can see in dust xml. As i said before it may not solve the world but solves my needs and soon someone elses..

bernardo's picture
Re: XML exporter

hey dust... I have somethings here can u tell me more about the game or mail me or something?

bernardo's picture
Re: XML exporter

well been thinking about this and found out maybe stupid but this: plist - property list... so the property must be set somewhere.... and its inside the tags... wich for me is no go....

dust's picture
Re: XML exporter

you can assign your ordered property list to an nsxml document and set custom tags that way or write a string formatter with objects set to be tags inside the enumerator. do you have example of the format you need it in.

usefuldesign.au's picture
Re: XML exporter

I feel like this is a cream-pie fight so I waited for things to cool off before commenting :-). By way of a prophylactic I do think XML is extremely useful*. I think we all know what makes it universal and binary/OS agnostic is also what makes it larger and slower than binaries. This may or may not be an issue depending on everything.

Having said that, the code you've posted bernardo has a bad line: "tempArray_sorted = inUnSorted.sort();"

I've commented why in the attached .qtz comp.

The comp I posted will sort a 'scrambled' associative dictionary structure into a sorted array structure.

I've found when looping arrays and setting values they can go out of order at times but I can't actually find an example comp so maybe I'm dreaming that! Obviously if you declare a new Object() then it's an associated dictionary and is scrambled. That's how I made the test structure that gets sorted in the following JS patch.

function (__structure Sorted) main (__structure UnSorted)
{
    var result = new Object();
    var tempArray_sorted = new Array();
    if (!_testMode)
    {
 
//   var tempArray_sorted = new Array();
//   WRONG!!  tempArray_sorted = inUnSorted.sort(); 
//   Above line is doubley confused. Sort function doesn't *return* the resultant sorted structure it just directs the method to do it (one way street). 
//   N.B. A line like "array_A = array_B;" would only create a pointer value in array_A not copy array_B's elements into array_A. 
 
          for (i in UnSorted)
           {
               tempArray_sorted[i] = new Array();
               A = UnSorted [i];
               for (j in A)
               {
                  tempArray_sorted[i][j] = UnSorted[i][j];
               }
               Log(i)
           }
          result.Sorted = tempArray_sorted;


The trick is the for (i in whatever_object) {} loop. 'i' gets assigned the key of the object item, which in this case is a number as text, and we use that number (Javascript casts it automatically to a number) to put it into the right element of the sorted array. This has always worked for me.

* eg: HTML. XML is more powerful (b/c of nested key tags) than unstructured text files, CSV files etc etc. Rest my case ;-).

PreviewAttachmentSize
Sort nested arrays.qtz28.16 KB

gtoledo3's picture
Re: XML exporter

Using numbering is exactly what I've been pointing out all this time.

bernardo's picture
Re: XML exporter

ah thanks usefuldesgin will check it out late night... as for the main reason for this post is a XML exporter that is:

stick a Structure (NSCFDictionary) into a processor patch and save it to XML, no xml plist. simple plain XML.

now this has some problems... i rather sort the NSDictionary inside the plugin than outside it. now the tags are the problem.... i have to rename them accordingly to the NSDictionary tree. still digging... baby steps baby steps in CREAM PIE hell yeah!!!!

bernardo's picture
Re: XML exporter

hi dust i think i have something: like this:

<line>
   <pie1>
   <X> value    </X>
   <Y> value   </Y>
   <Z> value   </Z>
   </pie1>
   <pie2>
   <X> value   </X>
   <Y> value   </Y>
   <Z> value   </Z>
   </pie2>
</line>

but i will see if NSDictionary returns a number for a certain Index and usit as tag...

gtoledo3's picture
Re: XML exporter

Maybe I'm entirely wrong, but aren't you using this to render vertices? I thought you refer to this. Verts are represented as an array, not a dictionary.

"yes dust i think i export the structures to plist and i gets all messed up so i wanna make rightfully ordered my structs ar XYZ points in a 3d space so i decide to build my own"

I guess maybe this doesn't relate to QC vertices, or the way mesh creator works, or the info that anything expects to see, and I've read too much into this. A mesh creator expects to see an array, not dictionary. So, if I wanted to alter a bunch of points from a model, save them, and reload, one uses a numbered array.

What does "no xml plist" mean? No header?

I don't know why I'm still chiming in on this one at this point. I'm just puzzled because this is an activity I've done (eg., backing up structures to file, to be reloaded by QC and/or other apps), and never had to go through all of this.

@usefuldesign, no you aren't imagining it, x/y/z can get jumbled up, in relation to whether they are 1/2/3, even within QC, without backing up to file and reloading type activities. I can't think of where I've seen this offhand either, but it certainly can happen in complex scenarios. I know this happened to me in something involving pixel values, where I had to just go ahead and use 1/2/3 instead of R/G/B.

bernardo's picture
Re: XML exporter

yes and no gtoledo3. i am using it to render gl lines. where you where most helpull. the problem is a basic one.

What does "no xml plist" mean? No header? it means what it says... i guess... because xml plist are not editable as far as the tags go.

"I don't know why I'm still chiming in on this one at this point. I'm just puzzled because this is an activity I've done (eg., backing up structures to file, to be reloaded by QC and/or other apps), and never had to go through all of this."

what kind of apps where you using? i want to use 3dsmax to import geometry and linedrawings.... but there are several problems as far xml goes inside qc... will keep at it right now i am facing the tag problem from the plists... wich work perfect for property lists but... no tags means no reading from external prog....

it getting confusing....but simpler...

bernardo's picture
Re: XML exporter

dbl post....craking toast grommit!

bernardo's picture
Re: XML exporter

but should accept the values from the structure... if it had ones..

usefuldesign.au's picture
Re: XML exporter

gtoledo3 wrote:
Using numbering is exactly what I've been pointing out all this time.

Duck

usefuldesign.au's picture
Re: XML exporter

bernardo wrote:
ah thanks usefuldesgin will check it out late night... as for the main reason for this post is a XML exporter that is:

stick a Structure (NSCFDictionary) into a processor patch and save it to XML, no xml plist. simple plain XML.

I could be missing something here (?!) What's the problem with using Kineme Structure to File patch then opening the created file in Property List Editor.app.

From there you can press the Dump button and select all copy and paste into Dashcode or Text Wrangler or TextEdit.app.

Or also in Property List Editor you can do a Save As… to a other XML based file protocols.

The best way maybe is to just open the Kineme created plist directly into Text Wrangler (free download) and save it as a .txt file of .xml file.

If you're terribly interested, I used to make rough and ready QC XML exporters using the String Printer patch to create the tags. I don't remember doing large structures but you could easily setup a queue patch or a javascript patch to loop through a data structure, wrap it in tags and then export as strings to a text file exporter patch.

usefuldesign.au's picture
Re: XML exporter

bernardo wrote:
What does "no xml plist" mean?
I think you're meaning to say "not a binary plist file" (as exported by Kineme Structure to File patch). I also think your avoidance of this file type is unjustified.

bernardo wrote:
i guess... because xml plist are not editable as far as the tags go.


Sure they are, just open in a text editor (Text Wrangler is very good) and global Find and Replace. I have done a lot of that kind of thing. My avatar on this site came from point co-ordinate data exported from Blender (can't remember what file format!).

I just added basic tags in new columns between data elements "X","Y" & "Z". Then opened/pasted result in a text editor. Just global replaced tags eg/ Find "Y" and replace with to</X> new-line-char <Y>  new-line-char tab-char and so on…

There are different ways of tagging it up though… find out the way Max tags by exporting some points/vertexes from Max and just impliment the same tagging stlye.

Might be more along lines of

<dict>   
   <key>X</key>
   <float>0.48950345802345</float>
</dict>

This isn't great for an automated work flow but if it's a once or twice a day thing for a week it's okay. (you could Applescript the workflow I guess, boring!)

bernardo's picture
Re: XML exporter

yes i know about the patch struct to file from kineme and works really well but for the needs I have wich is to output a single XMl file (no binary) to use outside QC :) its no good i've learned alot from using it though.

right now i am trying to parse the NSDictionary like stated above or below ... wrappit in tags where the Tag = Key, and the Value = Object and maintain the tree from the Plist...

usefuldesign.au i am very interested in your solution if you have the time could you post something small for me to learn from?

thanks alot hugs Bernardo

bernardo's picture
Re: XML exporter

eat my toast grommit... i missed your post usefuldesing... very informative... the thing about max tabs is that i can format it the way i want it to and for the cocoa side i am having a bit of difficulty doing so. Recently i post XML for all the fonts inside my computer in a 3d space and the style was something like this:

<?xml version="1.0"\?>
<Object>
      <V1>
         <X>-0.311564</X>
         <Y>0.0</Y>
         <Z>-0.0731096</Z>
      </V1>
      <V2>
         <X>-0.278172</X>
         <Y>0.0920732</Y>
         <Z>-0.0731096</Z>
      </V2>
      <V3>
         <X>-0.148549</X>
         <Y>0.0920732</Y>
         <Z>-0.0731096</Z>
      </V3>
 
</Object>

but the importance of XML plugIn Exporter i think is to maintain some relationship with the structure (just like you see it when you hover your mouse in the output struc patch from QC yellownote thingy) with the human readable side of the XML... my english is kinda bad and maybe i am not explaining myself the best way though...

franz's picture
Re: XML exporter

you can easily convert a plist to an xml

bernardo's picture
Re: XML exporter

ducked... yes are you saying to use:?

id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj
                                                              format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
 
        NSString *path = self.inputPath;
        [plist writeToFile:path atomically:YES];

but the xml plist that resulted converted hung for the tags... i am working on a NSXMLDocument now... not using the plist writeToFile but building the xml inside the enumerator loop somewhere... i have the code on my mac ...not here goddamm... can you help Franz?

franz's picture
Re: XML exporter

plisteditpro maybe ? I used that, and after some tinkering, it just worked. From plist to Xml, back and forth, binary to ascii or plain text. Give it a go and see how it feels... perhaps it will do the job for you. Who knows...

http://www.fatcatsoftware.com/plisteditpro/

usefuldesign.au's picture
Re: XML exporter

Quote:
the importance of XML plugIn Exporter i think is to maintain some relationship with the structure (just like you see it when you hover your mouse in the output struc patch from QC yellownote thingy) with the human readable side of the XML...

That's the point, bernardo. The XML that Kineme Structure to File creates in the plist binary is structured, is readable (once converted to ascii) and is editable if you need to change the tags to get it into Max/3D app.

Any XML exporter patch you make is going to generate a very similar structure surely?

Often the problem of getting the XML file to get accepted by the host application is just a matter of fixing the header or the way the structure is organised. Post a demo composition and I'll look at showing you how to translate the plist to the example XML you posted.

It's really not as hard as you are making this — by rolling your own exporter plugin — but go ahead, it's a great learning exercise (I'm sure)!

bernardo's picture
Re: XML exporter

"it's really not as hard as you are making this — by rolling your own exporter plugin — but go ahead, it's a great learning exercise (I'm sure)!"

yes yes it is and its being awesome to do it... i never dived so deep into cocoa and its kinda making all some sense.... I don't want to make a special case plugin.... just to fix my needs.... i wanna make one that will do just that translate the "visual" Strucuture into an identical XML....

as far as the comp go ud.. i don't have on here but ill be back with on e soon...

jrs's picture
Re: XML exporter

Hi Bernardo - did you end up writing a plug-in for this?