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

    delay 1 frame when inserting new object

    Scheduled Pinned Locked Moved SDK Help
    16 Posts 0 Posters 1.1k 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 24/10/2012 at 01:52, xxxxxxxx wrote:

      thanks alot for the help 🙂
      it worked...by the way....did i made any code mistakes ( i mean after the loop with msg update and c4d event)

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 25/10/2012 at 05:38, xxxxxxxx wrote:

        well ...it worked 😄
        but now i want to animate the points by giving them an array of vectors each frame ...

        here's the code...and it crashes always...

        Bool MyPlugin::Execute(BaseDocument *doc)
        {
        BaseObject* mine = BaseObject::Alloc( Opolygon );
        if (!mine)  return false;

        mine->SetName("MyPolygon");
        
        
        doc->InsertObject( mine , NULL , NULL );
        doc->AddUndo( UNDOTYPE_NEW, mine );
        
        
        mine->Message(MSG_UPDATE);
        EventAdd();
        
        
        PolygonObject\* pmine = ToPoly(mine);
        pmine->ResizeObject(100,0);
        
        
        Vector \*padr;
        padr = pmine->GetPointW();
        
        
        int i;
        for (i=0;i<100;i++){
        	padr _= Vector(0,0,0);
        };
        
        
        pmine->Message(MSG_UPDATE);
        EventAdd();
        
        
        
        
        BaseTime time = doc->GetTime();
        Real fps = doc->GetFps();
        Real frame = time.GetFrame(fps);
        
        
        CTrack \*MyTrack = mine->FindCTrack(DescID(DescLevel(CTpla,DTYPE_LONG,0)));
        CCurve \*MyCurve = MyTrack->GetCurve();
        CKey \*Key1 = MyCurve->AddKey(BaseTime(frame,fps));
        
        
        
        
        
        
        //GePrint(RealToString(frame));
        //GePrint(RealToString(fps));
        
        
        return true;
        

        }

        another question ( as i'm still new :D) .... i'm using the cinema4d sdk solution in vs 2010 ...win 8 64 bit (win 7 64 bit compiler) ... what should i add in c++ general properties ...linker ..to do debug...

        thanks in advance

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 25/10/2012 at 07:22, xxxxxxxx wrote:

          Originally posted by xxxxxxxx

          _another question ( as i'm still new :D) .... i'm using the cinema4d sdk solution in vs 2010 ...win 8 64 bit (win 7 64 bit compiler) ... what should i add in c++ general properties ...linker ..to do debug...
          _

          To debug a plugin you have to build it in Debug configuration and set CINEMA.exe as the executable for debug session in Configuration properties->Debugging:Command. See also the docs at the Debug Information's page.

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 25/10/2012 at 08:02, xxxxxxxx wrote:

            thanks 🙂
            still i need to know why the above code crashes (searched for pla data type...but didn't find any example...so i assumed it's long data type...though i think the fail isn't from data type ...

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 25/10/2012 at 08:59, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              thanks 🙂
              still i need to know why the above code crashes (searched for pla data type...but didn't find any example...so i assumed it's long data type...though i think the fail isn't from data type ...

              CTrack *MyTrack = mine->FindCTrack(DescID(DescLevel(CTpla,DTYPE_LONG,0)));
              CCurve *MyCurve = MyTrack->GetCurve();
              CKey *Key1 = MyCurve->AddKey(BaseTime(frame,fps));
              

              The track may be NULL. Have you tested that MyTrack isn't NULL?
              You should create a track and insert it with InsertTrackSorted() instead.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                On 25/10/2012 at 10:43, xxxxxxxx wrote:

                well at least now i know where it fails 😄

                but the test is false 😞

                CTrack *MyTrack = mine->FindCTrack(DescID(DescLevel(CTpla,DTYPE_LONG,0)));
                if (!MyTrack){

                MyTrack = CTrack::Alloc(mine,DescID(DescLevel(CTpla,DTYPE_LONG,0)));
                if(!MyTrack)  return FALSE;
                mine->InsertTrackSorted(MyTrack);
                doc->AddUndo( UNDOTYPE_NEW, MyTrack );
                

                };

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

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

                  On 25/10/2012 at 15:58, xxxxxxxx wrote:

                  well i tried...and still don't know why it can't Alloc(CTpla) ...here's the code...

                  Bool MyPlugin::Execute(BaseDocument *doc)
                  {
                  BaseObject* mine = BaseObject::Alloc( Opolygon );
                  if (!mine)  return false;

                  mine->SetName("MyPolygon");

                  doc->InsertObject( mine , NULL , NULL );
                  doc->AddUndo( UNDOTYPE_NEW, mine );

                  mine->Message(MSG_UPDATE);
                  EventAdd();

                  PolygonObject* pmine = ToPoly(mine);
                  pmine->ResizeObject(100,0);

                  Vector *padr;
                  padr = pmine->GetPointW();

                  int i;
                  for (i=0;i<100;i++){
                  padr = Vector(0,0,0);
                  };
                  pmine- >Message(MSG_UPDATE);
                  EventAdd();
                  BaseTime time = doc- >GetTime();
                  Real fps = doc- >GetFps();
                  Real frame = time.GetFrame(fps);
                  CTrack *MyTrack = mine->FindCTrack(DescID(DescLevel(CTpla,CUSTOMDATATYPE_PLA,0)));
                  if (!MyTrack){

                  MyTrack = CTrack::Alloc(mine,DescID(DescLevel(CTpla,CUSTOMDATATYPE_PLA,0)));
                  if(!MyTrack)  return FALSE;
                  mine->InsertTrackSorted(MyTrack);
                  doc->AddUndo( UNDOTYPE_NEW, MyTrack );

                  };
                  CCurve *MyCurve = MyTrack- >GetCurve();
                  CKey *Key1 = MyCurve- >AddKey(BaseTime(frame,fps));
                  mine- >Message(MSG_UPDATE);
                  EventAdd(EVENT_ANIMATE);
                  //GePrint(RealToString(frame));
                  //GePrint(RealToString(fps));
                  return true;
                  _}

                  edited : changed DTYPE_LONG to _ CUSTOMDATATYPE_PLA

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

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

                    On 26/10/2012 at 05:06, xxxxxxxx wrote:

                    Hi,

                    We can allocate a PLA track with the following DescID:

                    DescID descID = DescLevel(CTpla, CTpla, 0L);
                    

                    Anyway, here's a piece of code (mainly taken from Robert Templeton's code in this post) that shows how to animate the points of a PolygonObject:

                    // Allocate a polygon object with 4 points and 1 polygon
                    PolygonObject *polyObj = PolygonObject::Alloc(4, 1);
                    if (!polyObj) return FALSE;
                      
                    polyObj->SetName("MyPolygon");
                    doc->InsertObject(polyObj, NULL, NULL);
                      
                    // Get point buffer
                    Vector *dpoints = polyObj->GetPointW();
                      
                    // Get polygon buffer and initialize it
                    CPolygon *dpolygons = polyObj->GetPolygonW();
                    dpolygons[0].a = 0;
                    dpolygons[0].b = 1;
                    dpolygons[0].c = 2;
                    dpolygons[0].d = 3;
                      
                    // Update polygon object and document
                    polyObj->Message(MSG_UPDATE);
                    EventAdd();
                      
                    // Allocate PLA track
                      
                    DescID descID = DescLevel(CTpla, CTpla, 0L);
                    CTrack *track = CTrack::Alloc(polyObj, descID);
                    if (!track) return FALSE;
                    polyObj->InsertTrackSorted(track);
                      
                    // Get track curve to create keys for each frame
                      
                    CCurve *seq = track->GetCurve();
                    if (!seq) return FALSE;
                    CKey *key = NULL;
                      
                    // Sample Animation at each frame
                      
                    ModelingCommandData mcd;
                    mcd.doc = doc;
                    mcd.op = polyObj;
                    BaseContainer mbc;
                    mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);
                    mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, FALSE);
                    mcd.bc = &mbc;
                    mcd.flags = MODELINGCOMMANDFLAGS_0;
                      
                    BaseObject *csto = NULL;
                    PointObject *defd = NULL;
                      
                    LONG pointCount = polyObj->GetPointCount();
                    LONG pointSize = pointCount*sizeof(Vector);
                    const Vector *spoints = NULL;
                    Vector *points = NULL;
                      
                    BaseTime stime = doc->GetMinTime();
                    BaseTime etime = doc->GetMaxTime();
                    Real fps = doc->GetFps();
                    LONG startf = stime.GetFrame(fps);
                    LONG endf = etime.GetFrame(fps);
                    LONG currentf = 0L;
                      
                    for (; startf <= endf; startf += 1L)
                    {
                        stime = BaseTime::BaseTime(startf, fps);
                        currentf = stime.GetFrame(fps);
                      
                        // Animate document
                      
                        doc->SetTime(stime);
                        doc->ExecutePasses(NULL, TRUE, TRUE, TRUE, BUILDFLAGS_0);
                        EventAdd();
                      
                        // Current State to Object
                      
                        if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return FALSE;
                        csto = (BaseObject* )(mcd.result->GetIndex(0));
                        AtomArray::Free(mcd.result);
                        if (!csto) return FALSE;
                      
                        if (csto->IsInstanceOf(Onull))
                            defd = ToPoint(csto->GetDown());
                        else 
                            defd = ToPoint(csto);
                      
                        if (!defd) return FALSE;
                      
                        // Add key
                      
                        key = seq->AddKey(stime);
                        if (!key)
                        {
                            BaseObject::Free(csto);
                            return FALSE;
                        }
                      
                        // Add PLA key data
                      
                        spoints = defd->GetPointR();
                        if (!spoints)
                        {
                            BaseObject::Free(csto);
                            break;
                        }
                      
                        // Modify points for animation
                      
                        points = defd->GetPointW();
                        if (!points) return FALSE;
                      
                        points[0] = Vector(-1000*currentf,0,-1000*currentf);
                        points[1] = Vector(-1000*currentf,0,1000*currentf);
                        points[2] = Vector(1000*currentf,0,1000*currentf);
                        points[3] = Vector(1000*currentf,0,-1000*currentf);
                      
                        // Copy source points (read) to original polygon object points (write)
                        CopyMem(spoints, dpoints, pointSize);
                      
                        // Fill key with default values
                        if (!track->FillKey(doc, polyObj, key))
                        {
                            BaseObject::Free(csto);
                            return FALSE;
                        }
                      
                        // Do not forgot to free CSTO command's object
                        BaseObject::Free(csto);
                    }
                      
                    doc->SetTime(doc->GetMinTime());
                    
                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

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

                      On 26/10/2012 at 05:23, xxxxxxxx wrote:

                      wow 🙂
                      u made my day 😄
                      thanks alot for the help ....keep the good support ^_^

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

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

                        On 27/10/2012 at 02:18, xxxxxxxx wrote:

                        well i've found that size of vector is 24 bytes...this means vector data is considered (double)?which is real in c4d library

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

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

                          On 27/10/2012 at 02:19, xxxxxxxx wrote:

                          another question...does points have rotation? i've found in the sdk there's position and tangent tags...but when i try to rotate points it doesn't seem to rotate in viewport(resets gizmo rotation each time)

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            Helper
                            last edited by

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

                            On 31/10/2012 at 08:58, xxxxxxxx wrote:

                            well i've solved the problems and found answers 😄

                            just when i was reading the posts i noticed everytime i type a for loop and type the array brackets it doesnt appear (just for readers to notice that it's an iteration over array index)

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