Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    How do i create a plugin

    Scheduled Pinned Locked Moved SDK Help
    1 Posts 0 Posters 160 Views
    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 Offline
      Helper
      last edited by

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

      On 12/10/2006 at 07:40, xxxxxxxx wrote:

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

      ---------
      Hi,
      i study computer science at university of applied science in Regensburg Germany, but i am a beginner in programming for cinema.
      My question is relativ simple i think, why does this code do not work when i try it to execute in the script manager but it works when i save the code in win editor as .cof file?
      Error message in the console:
      [Fail] Script 'test': To many parameters What does this message mean exactly and where can i find a list with the meanings of the c4d messages?
      Thanks for help
      What should the code like therewith it works. The code ist a example from the sdk.
      var opers;
      var PLUGIN_ID = 1000001;
      var MENU_NAME = "Calculator";
      var HELP_STR =  "A Calculator";
      var PLUGIN_TITLE = "Calculator";
      enum
      {
           DLG_EDIT_BOX = 1000,
           DLG_NUM_0 = 1001,
           DLG_NUM_1,
           DLG_NUM_2,
           DLG_NUM_3,
           DLG_NUM_4,
           DLG_NUM_5,
           DLG_NUM_6,
           DLG_NUM_7,
           DLG_NUM_8,
           DLG_NUM_9,
           DLG_ADD,
           DLG_SUB,
           DLG_MUL,
           DLG_DIV,
           DLG_POINT,
           DLG_EQUAL,
           DLG_ROW1,
           DLG_ROW2,
           DLG_ROW3,
           DLG_ROW4,
           DLG_NUMPAD,
           DLG_OPERPAD,
           DLG_CALC,
           _DUMMY_
      } 
      class CalcDialog : GeModalDialog
      {
         private:
            var text;
           var stack;
            var op;
       public:
        CalcDialog();
        CreateLayout();
        Command(id, msg);
      }
      CalcDialog::CalcDialog()
      {
       super();
      }
      CalcDialog::CreateLayout()
      {
       SetTitle(PLUGIN_TITLE);
       AddEditText(DLG_EDIT_BOX, 0, 200, 0);
       
       AddGroupBeginH(DLG_CALC, BFH_SCALEFIT, 1, "", 0);
        AddGroupBeginV(DLG_NUMPAD, BFH_SCALEFIT, 1, "", 0);
         AddGroupBeginH(DLG_ROW1, BFH_SCALEFIT, 1, "", 0);
          AddButton(DLG_NUM_7, BFH_SCALEFIT, 0, 0, "7");
          AddButton(DLG_NUM_8, BFH_SCALEFIT, 0, 0, "8");
          AddButton(DLG_NUM_9, BFH_SCALEFIT, 0, 0, "9");
         AddGroupEnd();
         AddGroupBeginH(DLG_ROW2, BFH_SCALEFIT, 1, "", 0);
          AddButton(DLG_NUM_4, BFH_SCALEFIT, 0, 0, "4");
          AddButton(DLG_NUM_5, BFH_SCALEFIT, 0, 0, "5");
          AddButton(DLG_NUM_6, BFH_SCALEFIT, 0, 0, "6");
         AddGroupEnd();
         AddGroupBeginH(DLG_ROW3, BFH_SCALEFIT, 1, "", 0);
          AddButton(DLG_NUM_1, BFH_SCALEFIT, 0, 0, "1");
          AddButton(DLG_NUM_2, BFH_SCALEFIT, 0, 0, "2");
          AddButton(DLG_NUM_3, BFH_SCALEFIT, 0, 0, "3");
         AddGroupEnd();
         AddGroupBeginH(DLG_ROW4, BFH_SCALEFIT, 1, "", 0);
          AddButton(DLG_NUM_0, BFH_SCALEFIT, 0, 0, "0");
          AddButton(DLG_POINT, BFH_SCALEFIT, 0, 0, ".");
          AddButton(DLG_EQUAL, BFH_SCALEFIT, 0, 0, "=");
         AddGroupEnd();
        AddGroupEnd();
        AddGroupBeginV(DLG_OPERPAD, BFH_SCALEFIT, 1, "", 0);
         AddButton(DLG_ADD, BFH_SCALEFIT, 0, 0, "+");
         AddButton(DLG_SUB, BFH_SCALEFIT, 0, 0, "-");
         AddButton(DLG_MUL, BFH_SCALEFIT, 0, 0, "*");
         AddButton(DLG_DIV, BFH_SCALEFIT, 0, 0, "/");
        AddGroupEnd();
       AddGroupEnd();
       
       return;
      }
      //tests the passed value to see if number could be represented as an int
      TestInt(num)
      {
          if (float(int(num)) == float(num))
          {                         //num when passed is a float
                                  //(or it could be an int)
                                                     //we see make sure the passed value is
                                                     //an int by using int(num)
                                                     //this will remove any decimal
                                                     //percision i.e. 6.775 = 6
                                                     //converting this back to a float
                                                     //would give us 6.0 then we check to
                                                     //see if this is the same as the
                                                     //original value passed to us.
              return TRUE;                           //if so return TRUE.
          }
          else
          {  
           return FALSE;                         //otherwise return FALSE.
          }
      }
      //pass a number and get the string to display properly formated.
      //i.e. 7.645 will apear as 7.645 instead of 7.64500000
      Format(num)
      {
       var per, ans, inum;
       var format, str;
       
       inum = int(num);                         //find the non-decimal
                                    //part of the number i.e 7
       ans = num - inum;                        //take the non-decimal
                                    //number and subtract it
                                                //from the orginal to get the
                                                 //decimal part. i.e. 7.645 - 7 = 0.645.
       for (per = 0; !TestInt(ans); per++)
       {                                   //per records the amount of
                                                              //digits after the decimal
                                                               // point. Test to see if
                                                               //ans is not an integer if
                                                               //so follow through in the
                                                               //loop, if not bail.
              ans *= 10;                                       //multiply ans by 10 to
                                                               //reduce the percision by
                                                               //1. increment the per by
                                                               //1. Loop again.
       }
      //the idea behind the previous 'for loop' is this, say we had .5643:
      //1) test to see if .5643 is an int (a whole number with no fractional part)
      //2) if not multiply it by 10 to get 5.643, and increment per by 1 so per = 1.
      //3)keep going until .5643 becomes an int
      //example:
      //.5643 * 10 = 5.643      ;        per = 1     ;       5.643 is not an int
      //                                                     therefore continue
      //5.643 * 10 = 56.43      ;        per = 2     ;       56.43 is not an int
      //                                                     therefore continue
      //56.43 * 10 = 564.3      ;        per = 3     ;       564.3 is not an int
      //                                                     therefore continue
      //564.3 * 10 = 5643       ;        per = 4     ;       5643 is an int therefore
      //                                                     stop.
       format = "." + tostring(per, "d") + "f";          //creates the formatting string we need
                                                           //cinema allows you to combine
                                                           //two string together by using
                                                           //a '+' sign. So you could say:
                                                           //var name = "John" + " Doe";
                                                           //to get "John Doe". so we are
                                                           //taking a "." and adding the
                                                           //string we get from the
                                                           //tostring(per, "d") function.
                                                           //The "d" means to use per as
                                                           //an integer for string
                                                           //conversion. The format string
                                                           //now equals ".4" + "f", which
                                                           //as we
                                                           //know is ".4f", which we will
                                                           //use as the format string in
                                                           //the next tostring function.
       str = tostring(num, format);                        //this tostring function is used to
                                    //convert the number
                                                           //into the proper floating
                                                           //point format. ".4f" means        
                                                           //convert the number as a float
                                                           //with 4 digits after the
                                                           //decimal point.
       return str;                        //return newly formatted string.
      }

      CalcAdd(op1, op2) { return (op1 + op2); }         //function is called when calc needs
                                                        //to add
      CalcSub(op1, op2) { return (op1 - op2); }         //called when calc needs to subtract
      CalcMul(op1, op2) { return (op1 * op2); }         //called when calc needs to multiply
      CalcDiv(op1, op2)
      {                                        //called when calc needs to divide
         if (!op2)
         {                             //check to see if we are dividing by zero.
          return "Divide by Zero Error";
         }
       return (op1 / op2);                   //otherwise return result of operation.
      }

      CalcDialog::Command(id, msg)
      {
       var c = "0";

      if (id == DLG_EDIT_BOX)
       {                                     //we got input from the text
                                                         //edit box
        text = GetString(DLG_EDIT_BOX);                 //grab the string from the box
                                                        //and store it into text
            var len = sizeof(text);                       //find the size of the string
                                                          //(strlen for the C programmers)
         
            len = (len > 0) ? len-1 : 0;                    //subtract 1 from our
                                                             //length if we have
                                                             //length.
           
            if (sizeof(text) > 0)
            {                                     //check if we have
                                                           //characters in our
                                                           //string.
         if (!isdigit(text[len]) && text[len] != 46)
         {                           //grab the last letter on
                                                          //the string test to see
                                                             //if it is a letter AND
                                                           //isn't a decimalpoint(46)
               text = strmid(text, 0, len);                //if so set text equal to
                                                            //the string minus the
                                                           //character just typed in.
                SetString(DLG_EDIT_BOX, text);            //update the dialog's text
                                                          //edit box.
                                                           //we do this so letters
                                                           //can't be inputed into
                                                           //our calculator, because
                                                           //this would be bad.
          return;
         }
        }
       }
       if (id <= DLG_NUM_9 && id >= DLG_NUM_0)
       {                                //check to see if the id is
                                                            //within the num pad.
        var num = id - DLG_NUM_0;                         //since our ids are
                                                          //enumerated they go in
                                                          //order.
                                                            //meaning DLG_NUM_0 is 2
                                                             //less than DLG_NUM_2
                                                             //therefore we can subtract
                                                            //the id from DLG_NUM_0 to
                                                            //get the actual number. 
        text = GetString(DLG_EDIT_BOX);                   //get the text so we can
                                                            //add to it
        c = tostring(num, "d");                           //store the number as a
                                                             //string.
        
        text = text + c;                                  //add this number to the
                                                          //text.
         SetString(DLG_EDIT_BOX, text);                    //refresh the text edit
                                                             //box.
         } 
       if (id <= DLG_DIV && id >= DLG_ADD)
       {                                  //id is an operation (check
                                                           //enums).
        var num = id - DLG_ADD;                           //same as before instead
                                                          //use DLG_ADD.
        op = num;                                         //store as operator (0 is
                                                          //+, 1 is minus, etc).
        stack = text;                                     //stack now holds the value
                                                          //we are using for
        text = "";                                       //calculation. Clear the
                                                          //text.
        SetString(DLG_EDIT_BOX, text);                    //refresh text edit box
                                                          //(display).
       }
       if (id == DLG_POINT)
       {                                         //point has been clicked.
        text = GetString(DLG_EDIT_BOX);                   //get the string
        text = text + ".";                                //add the decimal point
        SetString(DLG_EDIT_BOX, text);                    //refresh the display.
       }
       if (id == DLG_EQUAL)
       {                                          //equals signs has been
                                                           //clicked.
        var func = opers[op];                             //get the function from our
                                                          //array.
                                                           //see main for a better
                                                           //explaination
        //func now contains the location of the function for the proper operator.
        //if op = 0 look up slot 0 which has CalcAdd in it.
        var ans = func(evaluate(stack), evaluate(text));  //call the function
                                                            //evaluating both the
                                                            //stack.
                                                              //and text parameters.
                                                              //evaluate will convert
                                                              //the strings into
                                                              //numbers, among other
                                                              //usefull things.
            if (typeof(ans) == DT_STRING)
            {                                  //check if the return
                                                           //value is a string
             stack = text = ans;                           //if so just print it to
                                                           //the display
            } else
            {
              
             stack = text = Format(ans);               //otherwise format it
                                                             //before you print it
            }
         SetString(DLG_EDIT_BOX, stack);                 //refresh display
       } 
       
      }

      class CalcMenu : MenuPlugin
      {
      public:
       CalcMenu();
       GetHelp();
       GetID();
       GetName();
       Execute(doc);
      }
      CalcMenu::CalcMenu()     { super(); }
      CalcMenu::GetID()        { return PLUGIN_ID; }
      CalcMenu::GetName()      { return MENU_NAME; }
      CalcMenu::GetHelp()      { return HELP_STR; }
      CalcMenu::Execute(doc)
      {
       var d = new(CalcDialog);
       d->Open(-1, -1);

      return;
      }
      main()
      {
       opers = new(array,4);
                          //opers is going to store the location of
                          //where our 4 main functions are going to go.
       opers[0] = CalcAdd;           //slot zero stores the add function.
       opers[1] = CalcSub;           //slot 1 stores the subtract function.
       opers[2] = CalcMul;           //slot 2 stores the multiply function.
       opers[3] = CalcDiv;           //slot 3 stores the division function.
       Register(CalcMenu);
      }

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