Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Unwanted COFFEE Array Update

    SDK Help
    0
    2
    194
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

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

      On 06/01/2006 at 02:37, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   9.5 
      Platform:   Windows  ;   
      Language(s) :   C.O.F.F.E.E  ;

      ---------
      I've created a COFFEE expression to offset an object's points by storing them in an array, adding an offset to each array value and updating the object. The array is stored in a global variable which is only set when the array is empty. Point offset values are entered via User Data on the COFFEE tag.
       When I offset the points and undo the action, the array is updated with any offset point values e.g. User Data settings will return to zero but the points will remain in their new position as default. Undo seems to be overriding if(!pointArray) pointArray = op->GetPoints();
      Any suggestions on how to overcome this?

          
          
            
          
          
          
          var pointArray;
          
          
          
          
          main(doc,op)  
          {  
          if(!instanceof(op, PointObject)) return;  
          if(!pointArray) pointArray = op->GetPoints();  
          var tag = op->GetFirstTag();  
          var offset = tag#ID_USERDATA:1;  
          var p, i = 0;  
          var pointModified;  
          var pointCount = op->GetPointCount();  
          for(i=0; i < pointCount; i++)  
            {   
            p = pointArray[i];  
            pointModified = vector(p.x + offset.x, p.y + offset.y, p.z + offset.z);  
            op->SetPoint(i, pointModified);  
            }  
          op->Message(MSG_UPDATE);  
          }
          
          
          
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

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

        On 26/01/2006 at 12:22, xxxxxxxx wrote:

        Yes, global variables within C.O.F.F.E.E. tags are quite volatile. As you've noticed they go away when you undo anything. If you want your plugin to be undo safe you will have to redesign it without global variables.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post