PDA

View Full Version : using optionVar for dynamic variables?


ktpr
05-28-2003, 11:14 PM
I need/want to make dynamic variables. Essentially what I want is a really fast lookup table. Might as well use the program stack, right?

The eval statement has global scope. If I put the scope "{}" characters in the eval statement my dynamic variable code and its use has to be included.

The eval statement won't take a string longer than 76 characters. The code that deals with the dynamic variables is longer than 76 characters.

You can't delete normal variables.

But what about useing optionVar, which writes to the users preferences? Using something like that sounds really bad but I'll erase every variable when I'm done and I'll make a backup before I do anything. Is this acceptable? Is there a better way?

===
little example ... technically you should back up your user prefs although I delete the variable anyway...
===

string $varname = "zzz_myvar" + 9;
optionVar -sv $varname "any string I want here";

string $foo[] = `optionVar -list`;

print ("if you look at the end of this list zzz_myvar9 should be there...");
print ("\n...\n");
int $i = size( $foo ) - 5;

for (; $i < size ($foo); $i++){

print ("\n" + $foo[$i]);

}

print ("\n\ndeleting optionVar variable...\n");

optionVar -rm $varname;
string $foo[] = `optionVar -list`;

int $i = size( $foo ) - 5;

for (; $i < size ($foo); $i++){

print ("\n" + $foo[$i]);

}

print( "\n\n see?\n" );
===

ktpr
05-29-2003, 12:25 AM
I am retarded. :surprised::drool:

I should have merely used the 'createNode` command and used set/add/delAtrr to dynamically add, set and retrieve variable values.

oh well
cheers
ktpr

mark_wilkins
05-29-2003, 12:43 AM
I'm kind of at a loss about why you'd want to do this, but OK...

-- Mark

ktpr
05-29-2003, 02:09 AM
well if you wanted to organize some data you have a lot of options. You could use a hash table, you could use any of the many sorting algorithms, etc etc. But if all you want is to group data under uv values, a way to do it is dynamically create variables names that directly represent the uv values. This the fastest possible way because insert and retrievial are O(1), with no collisions like in a hash table. Fortunately I don't care about sorting.

// puesdocode
if ( exists(uv_Value0.45_0.32) ){

addToCurrentSetofCommonVerts( "poly1.vertex[0]" );

}
else{ ....// make a new var and add to that set }

// ... all done

now I know what vertices on any set of objects overlap and therefore correspond with another (given an intital default state, like duplicating) ... this all relates to a script I'm working on to convert uv edits to subd uv edits. I don't know if that makes sense.

cheers
ktpr

mark_wilkins
05-29-2003, 02:46 AM
This sounds like a perfect application of the API, where you can create whatever data structures you want...

-- Mark

ktpr
05-29-2003, 03:26 AM
yeah. To bad I have no money for VC++. :shrug:

ktpr

mark_wilkins
05-29-2003, 03:54 AM
hehe

you know, you can use the "learning edition" or "student edition" of Visual C++ to compile plug-ins. It's available bound into some reasonably-priced books on Visual C++.

It's limited in that when you write applications you get a dialog box that states that they were compiled with the learning edition, but you can compile Maya plug-ins, no problem.

At least this was true for VC++ 6.0.

-- Mark

CGTalk Moderation
01-15-2006, 06:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.