delay 1 frame when inserting new object



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

    On 23/10/2012 at 20:01, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13 
    Platform:      
    Language(s) :     C++  ;

    ---------
    i'm kinda new to sdk
    here's what i did to create a simple polygon just by clicking the icon in the plugin menu

    Bool MyPlugin::Execute(BaseDocument *doc)
    {
    BaseObject* mine = NULL;
    mine = BaseObject::Alloc( Opolygon );
    mine->SetName("MyPolygon");
    doc->InsertObject( mine , NULL , NULL );
    doc->AddUndo( UNDOTYPE_NEW, mine );
    doc->Message(MSG_UPDATE);
    return true;
    }

    problem is ...after i click...i need to press any where to update the document...help please :)



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

    On 23/10/2012 at 21:54, xxxxxxxx wrote:

    mine->Message(MSG_UPDATE); // Not doc->!  
    EventAdd(); // Let C4D know that it needs to update its managers
    

    Also note that you should always check memory allocations/class instance creation:

    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();  
    	return true;
    }
    

    Finally, remember that you will need to cast the BaseObject into a PolygonObject in order to add and manipulate vertices and polygons using the latter's methods.  Use PolygonObject* pmine = ToPoly(mine) to do that (for instance).



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

    On 24/10/2012 at 00:19, xxxxxxxx wrote:

    well thanks alot for this :D

    now for the next fail ...

    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->Alloc(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();
    
    
    return true;
    

    }

    program always crashes when i execute ....I'm sure im missing something ...



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

    On 24/10/2012 at 01:33, xxxxxxxx wrote:

    Alloc() is a static method that returns a newly allocated PolygonObject, but as you already have a PolygonObject (pmine) you should call ResizeObject() instead:

    pmine->ResizeObject(100,0);
    

    Also in the for-loop you have to assign points position with [] or pointer arithmetic:

    for (LONG i=0;i<100;i++)
        padr[i] = Vector(0,0,0);
    

    or

    for (LONG i=0;i<100;i++,padr++)
        *padr = Vector(0,0,0);
    


  • 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)



  • 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 :D
    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



  • 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.



  • 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 ...



  • 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.



  • 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 :D

    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 );
    

    };



  • 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



  • 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());
    


  • 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 :D
    thanks alot for the help ....keep the good support ^_^



  • 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



  • 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)



  • 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 :D

    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)


Log in to reply