stuck with simple script



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/02/2011 at 19:28, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:      Mac OSX  ; 
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    Here I thought I was slowly gaining some real COFFEE expertise and then this (to me) unexplainable is happening.

    This COFFEE Tag is attached to an Object. There is also a Material attached to the same Object. This Material has a movie in the Color Channel. My script looks up the current Frame from (doc) and copies this into the Movie Frame Start/End fields of the Color Channel so that the corresponding movie frame will display in preview. Maybe there is a much easier way to do this but I didn't find it.

    So far my script has worked fine.I tried to make it a little better by doing some checking (is there a Material? etc). And finally each time I render I have to reset the Movie Frame Start/End my hand to the correct range.

    To automate this somewhat I added some User Data to the COFFEE Tag with a Boolean On/Off switch.
    When the switch is on the script is supposed to copy the current frame to the Color Channel. When the switch is off the script is supposed to copy the first and last frame of the document to the Material - so as to restore the normal way.

    The problem is, even when the switch is Off, and the script executes the 'else' part (which I can verify by printing 'not doing it' to the Console) the movie frame will follow the document frame. Maybe there is a systematic error but after an afternoon of trying to troubleshoot this I am running out of ideas.

    _  myMaterialName = myTag#TEXTURETAG_MATERIAL->GetName();    // get name of the Material

    myMaterial = doc->FindMaterial(myMaterialName);        // find this material in the Material list
     if (!(myMaterial)) return;                                                    // abort if this Material is not there (shouldn't happen)

    myChannel = myMaterial->GetChannel(CHANNEL_COLOR);    // get the color channel
     myChannelBc = myChannel->GetContainer();                        // color channel into container for edit

    if (mySwitch)
     {
         println ("doing it");
         // here the actual transfer of start/end frames takes place
         myFrame = getCurrentFrame(doc);                                // get the frame counter
         myChannelBc->SetData(CH_TIME_FROM, myFrame);    // change Movie Start Frame in animation portion
         myChannelBc->SetData(CH_TIME_TO, myFrame);        // and Movie End Frame to current frame        
         
      } else {
          println ("not doing it");
          // if switch is off set material frame start/end to default
          myChannelBc->SetData(CH_TIME_FROM, getMinFrame(doc));
          myChannelBc->SetData(CH_TIME_TO, getMaxFrame(doc));

    println (myChannelBc->GetData(CH_TIME_FROM));
          println (myChannelBc->GetData(CH_TIME_TO));
         
      }
      myChannel->SetContainer(myChannelBc);                // write the edited container back to the color channel
      myMaterial->Update();_



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/02/2011 at 22:25, xxxxxxxx wrote:

    So what tells you the println (bc->GetData(CH_TIME_FROM)) ? Has the time been correctly set ? If yes, also try to reobtain the container again, after you've set it, and take *then* a look into it's Data. Also print if
    the Container has successfully been set. : println(MyChannel->SetContainer(bc))



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/02/2011 at 18:35, xxxxxxxx wrote:

    Hi nux95

    Thanks for the input. I stripped the whole function down and this remains. Apparently it is enough to find the Material and apply Update() to it. The Start/End Frames in the Material are not touched. No switch necessary. I guess KISS (keep it simple, stupid) always applies.

    Peter

    _main(doc,op)
    {
      var myTag, myMaterialName, myMaterial;

    // get the first texture tag from (op) this object
      myTag = op->GetFirstTag();                                            // get the first tag from this object
     
      while (myTag)                                                                    // loop until we find texture tag or run out of tags
      {
          if (instanceof(myTag, TextureTag)) break;        // is it a texture tag - then exit loop
          myTag = myTag->GetNext();                                        // no - on to next tag                   
      }
      if(!myTag) return;                                                        // abort if no texture tag found
     
      myMaterialName = myTag#TEXTURETAG_MATERIAL->GetName();    // get name of the Material

    myMaterial = doc->FindMaterial(myMaterialName);        // find this material in the Material list
      if (!(myMaterial)) return;                                                    // abort if this Material is not there (shouldn't happen)

    myMaterial->Update();

    }_



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/02/2011 at 21:07, xxxxxxxx wrote:

    myMaterialName = myTag#TEXTURETAG_MATERIAL

    This already returns the real Material.

    What is the Problem now ?
    And ya mean with "KISS" ?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 23/02/2011 at 05:38, xxxxxxxx wrote:

    I just meant to express my thanks to you to urge me to do some more troubleshooting - no problem now.
    Simply using the Update() on that Material has the effect I need without doing all the complicated stuff I tried to do before. KISS is a US acronym for "die einfachste Lösung ist meistens die beste" - ich glaube Bill Clinton hat das eingeführt.


Log in to reply