doc Posted July 3, 2007 Share Posted July 3, 2007 Hi, I'm trying to make a sop where a user can create their own local variables (each variable has a user defined name and value). I had a look at the SOP_Star example, but it looks like the names of the local variables are established in the constructor. As far as I can tell this method won't allow for dynamic local variables names. Does anyone have some insight as to how I might get around this? Many thanks L Quote Link to comment Share on other sites More sharing options...
sibarrick Posted July 3, 2007 Share Posted July 3, 2007 (edited) This is actually very easy //function to read the user supplied name void USERATTNAME(UT_String &str) { evalString(str, 5, 0, 0); } //get the user named attribute UT_String username; USERATTNAME(username); //make it uppercase UT_String usernameUpper = username; usernameUpper.toUpper(); //add a local var map gdp->addVariableName(username, usernameUpper ); Then of course you have to do the usual to actually create the attributes and use the name defined in the code above Edited July 3, 2007 by sibarrick Quote Link to comment Share on other sites More sharing options...
doc Posted July 3, 2007 Author Share Posted July 3, 2007 Then of course you have to do the usual to actually create the attributes and use the name defined in the code above Hey Simon, Many thanks for your help, but I think I've explained myself poorly, I'm trying create some Local Variables (like $PT, $NPT, $ID) that the user can define via a string parameter(the value would be established via a seperate float field). And if I understand your example, it seems to be the setup for adding user defined attributes. Here's a bit more info about my problem: In the star sop example the local variable names seem to be established in the constructor: OP_StarOperator::OP_StarOperator() : OP_Operator("star", "Star", SOP_Star::myConstructor, SOP_Star::myTemplateList, 0, 0, SOP_Star::myVariables, OP_FLAG_GENERATOR) { } CH_LocalVariable SOP_Star::myVariables[] = { { "PT", VAR_PT, 0 }, // The table provides a mapping { "NPT", VAR_NPT, 0 }, // from text string to integer token { 0, 0, 0 }, }; Which doesn't seem to allow for dynamic local variable names. So I was just wondering if anybody new how to get around this issue. Many thanks and much gratitude. L Quote Link to comment Share on other sites More sharing options...
sibarrick Posted July 3, 2007 Share Posted July 3, 2007 (edited) You can define your own local variables to be used inside expressions in the current sop like this. These obviously aren't added as local variable mappings as I was decribing before, but do act in the same way as $PT etc. CH_LocalVariable SOP_PointSlide::myVariables[] = { { "PT0", VAR_PTS, 0 }, { "PT1", VAR_PTE, 0 }, { "EDGE", VAR_E, 0 }, { 0, 0, 0 }, }; float SOP_PointSlide::getVariableValue(int index, int) { if (myCurrPoint < 0) // Sorry, we're in an invalid state return 0; switch (index) { case VAR_PTS: return myCurrPoint; case VAR_PTE: return myCurrEndPoint; case VAR_E: return myCurrEdge; } return 0; //Whoops, forgot a variable } You then set myCurrPoint etc inside the cook method so they are available to be used in expressions in the parameters of the sop But make sure you also get the values from parameters for each point and not just once. Inside a loop that parses every point myCurrPoint = ppt0->getNum(); myCurrEndPoint = ppt1->getNum(); myCurrEdge = edgeCount; You define myCurrPoint etc in the header file so they are globally available. Is this any more help? Edited July 3, 2007 by sibarrick Quote Link to comment Share on other sites More sharing options...
doc Posted July 12, 2007 Author Share Posted July 12, 2007 I figured this out! The issue is that I wanted the user to define the names of their temporary variables. I realized that all I had to do was change the entries in myVariables and everything would be cool inside cookMySop evalString(tempVarNames],temp_var_names.getToken(),0,now); CH_LocalVariable entry={ tempVarNames], VAR_TMP1, 0 }; myVariables[1] = entry; L Quote Link to comment Share on other sites More sharing options...
Infernalspawn Posted October 21, 2007 Share Posted October 21, 2007 sorry to excavate this thread, but i have a basic understanding problem: are there two ways of creating Local Variables ? one time using gdp->addVariableName(attribName,LocalVarName)? and second time using the my variables array to register them and use getVariableValue(int index,int thread) to evaluate them ? thx for helping Sebastian Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.