find all cameras in a scene ?

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

On 05/08/2007 at 04:26, xxxxxxxx wrote:

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

---------I need to find all cameras in a scene ? how can I to do?

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

On 05/08/2007 at 20:29, xxxxxxxx wrote:

Hi ...

Will it do my friend?

void GetAllCameras(AtomArray *oCams,BaseObject *oCam)
{
     if(oCam)
     {
          if(oCam->GetType()==Ocamera)
               oCams->Append(oCam);

if(oCam->GetDown())
               GetAllCameras(oCams,oCam->GetDown());
          if(oCam->GetNext())
               GetAllCameras(oCams,oCam->GetNext());
     }
}

LONG GetAllCameras(AtomArray *oCams)
{
     if(!oCams) return 0;

BaseDocument *doc=GetActiveDocument();
     BaseObject *obj=doc->GetFirstObject();
     if(obj)
     {
          GetAllCameras(oCams,obj);
     }

return oCams->GetCount();
}

You need to call the second function and then all the cameras will be in the AtomArray parameter you passed ...
If you just want the count only ... you don't need that parameter ...
For example ... you are using a command plugin and you got a button ... Then your command function will be ... like below ...

Bool dlgYourPlugin::Command(LONG id,const BaseContainer &msg;)
{
     BaseDocument *doc=GetActiveDocument();
     switch(id)
     {
     case BTN_DISPLAY_CAMERAS:
          {
               LONG i;
               AtomArray *oCameras=AtomArray::Alloc();
               LONG lCamCnt=GetAllCameras(oCameras);
               for(i=0;i<lCamCnt;i++)
               {
                    BaseObject *obj=(BaseObject * )oCameras->GetIndex(i);
                    MessageDialog(obj->GetName());
               }
               AtomArray::Free(oCameras);
          }
          break;
     }
}

Wishing it can help you in a way ...
Zaw Min Tun

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

On 05/08/2007 at 22:30, xxxxxxxx wrote:

hi, Zaw Min Tun
thank you for your help?

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

On 06/08/2007 at 03:07, xxxxxxxx wrote:

I was added to two camera of target; but the return result is 0;  :)

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

On 06/08/2007 at 18:57, xxxxxxxx wrote:

Hi ...
I also tested before I post ... :) ... and it worked ...
So pls ... be sure to allocate the AtomArray before you pass to the LONG GetAllCameras(AtomArray *oCams) function ...
AtomArray *varX=AtomArray::Alloc();
LONG l=GetAllCameras(varX);
MessageDialog(LongToString(l)+ " cameras!");
 
It'll be more helpful if you can show me your code lines?
Regards ...
Zaw Min Tun

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

On 06/08/2007 at 22:41, xxxxxxxx wrote:

static void GetCameraSnapshoot( void );
void LauntchWindow()
{
 Bool bSingleModul = FALSE;
 LONG OldProc = 0;
 BaseDocument* doc = GetActiveDocument();
 BaseObject* null = doc->GetActiveObject();
 if (!null)
 {
  null = doc->GetFirstObject();
   if (!null)
   {
   return ;
   }
 }
 BaseTrack *track = null->GetTrack(Spla);
 if (!track )
 {
  //is picture
  nTypeObj = 0;
 }
 else
 {
  //is animal
  nTypeObj = 1;
 }
 
 for ( LONG num = 0 ; num< 4; num++ )
 {
  //set view to active
  SetActiveViewFromNum(num);
  LONG proc = doc->GetBaseDraw( num )->GetProjection();
  if ( OldProc == proc )
  {
   bSingleModul = TRUE;
   break;
  }
  switch(proc )
  {
  case Pperspective:
   {
    if ( nTypeObj == 0)
    {
     Snapshoot("0_perspective"); //perspective is snapshoot name
    }
    else
    {
     Snapshoot("1_perspective"); //perspective is snapshoot name
    }
    break;
   }
  case Ptop:
   {
    if ( nTypeObj == 0)
    {
     Snapshoot("0_top");        //top is snapshoot name
     
    }
    else
    {
     Snapshoot("1_top");        //top is snapshoot name
    }
    break;
   }
  case Pright:
   {
    if ( nTypeObj == 0)
    {
     Snapshoot("0_right");
    }
    else
    {
     Snapshoot("1_right");
    }
   break;
   }
  case Pfront:
   {
    if ( nTypeObj == 0)
    {
     Snapshoot("0_front");
    }
    else
    {
     Snapshoot("1_front");
    }
    break;
   }
  }
  OldProc = proc;
 }
 //is single view modul
 if ( bSingleModul == TRUE )
 {
  BaseDraw *bd = doc->GetActiveBaseDraw();
  for ( LONG num = 0 ; num< 4; num++ )
  {
   switch( num )
   {
   case 0:
    {     
     GeData da(BASEDRAW_PROJECTION_PERSPECTIVE);
     bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
     DrawViews(DA_ONLY_ACTIVE_VIEW);
     //get snapshoot
     if ( nTypeObj == 0)
     {
      Snapshoot("0_perspective"); //perspective is snapshoot name
     }
     else
     {
      Snapshoot("1_perspective"); //perspective is snapshoot name
     }
     break;
    }
         
   case 1:
    {     
     GeData da(BASEDRAW_PROJECTION_TOP);
     bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
     DrawViews(DA_ONLY_ACTIVE_VIEW);
     //get snapshoot
     if ( nTypeObj == 0)
     {
      Snapshoot("0_top");        //top is snapshoot name
      
     }
     else
     {
      Snapshoot("1_top");        //top is snapshoot name
     }
     break;
    }
   
   case 2:
    {     
     GeData da(BASEDRAW_PROJECTION_RIGHT);
     bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
     DrawViews(DA_ONLY_ACTIVE_VIEW);
     //get snapshoot
     if ( nTypeObj == 0)
     {
      Snapshoot("0_right");
     }
     else
     {
      Snapshoot("1_right");
     }
     break;
    }
     
   case 3:
    {     
     GeData da(BASEDRAW_PROJECTION_FRONT);
     bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
     DrawViews(DA_ONLY_ACTIVE_VIEW);
     //get snapshoot
     if ( nTypeObj == 0)
     {
      Snapshoot("0_front");
     }
     else
     {
      Snapshoot("1_front");
     }
     break;
    }
    
   }//end switch

}//end for
  //reset to PERSPECTIVE
  GeData da(BASEDRAW_PROJECTION_PERSPECTIVE);
  bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
  EventAdd();

}
 GetCameraSnapshoot();
}
 
void Snapshoot( char FileName[] )
{
 BaseDocument* doc = GetActiveDocument();
 if (!doc) return;
 String sFileName = String( FileName ) + String(".jpg");
 BaseObject* null = doc->GetActiveObject();
    if (!null)
 {
  null = doc->GetFirstObject();
  if (!null)
  {
   return;  //have't object
  }
 }
 BaseContainer rdata = doc->GetActiveRenderData()->GetData();
 //set to render as editor
 rdata.SetBool(RDATA_RENDERASEDITOR, TRUE);
 char* szPath = bNew CHAR[512];
 GetShadeImageDir( szPath );
 //MessageDialog(szPath);
    //char * szPath = "C:\\Documents and Settings\\Administrator\\Turbo Squid Tentacles\\Uploaded\\Shade";
 String sPath = String( szPath );
  bDelete(szPath);
   
 Filename renderpath = Filename( sPath ); // for instance
 rdata.SetFilename(RDATA_PATH, renderpath);
   
 //BaseBitmap* bmp = AllocBaseBitmap();
 BaseBitmap* bmp = BaseBitmap::Alloc();
 BaseBitmap* desbmp =  BaseBitmap::Alloc();
 
 bmp->Init(rdata.GetLong(RDATA_XRES),
    rdata.GetLong(RDATA_YRES));
 desbmp->Init(rdata.GetLong(RDATA_XRES),
    rdata.GetLong(RDATA_YRES));
 
 RenderDocument(doc, rdata, NULL, NULL, bmp, TRUE , NULL);
 String sFullPath = sPath + "\" + sFileName;
    //MessageDialog(sFullPath);
 bmp->Save( Filename(sFullPath), FILTER_JPG, NULL, SAVEBIT_32b*tchANNELS);
 
 BaseBitmap::Free( bmp );
 
    BaseBitmap::Free( desbmp );
}

static void SetActiveViewFromNum( LONG iNUM = 0 )
{
 BaseDocument* doc = GetActiveDocument();
 LONG lngIndex = 0;
 lngIndex = iNUM;
  
 BaseDraw *bd = doc->GetActiveBaseDraw();
  
 switch( lngIndex )
 {
 case 0:
  {
   //BaseDraw *bd = doc->GetBaseDraw( 0);
   //bd->SetBit( BIT_ACTIVE );
   //bd->SetBit( BIT_DOCUMENT_CHECKREWIND );
   //SendCoreMessage(EVMSG_ACTIVEVIEWCHANGED);
   //EventAdd(EVMSG_ACTIVEVIEWCHANGED);
      
   GeData da(BASEDRAW_PROJECTION_PERSPECTIVE);
   bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
  }
       break;
 case 1:
  {
   //BaseDraw *bd = doc->GetBaseDraw( 1 );
   //bd->SetBit( BIT_ACTIVE );
   //bd->SetBit( BIT_DOCUMENT_CHECKREWIND );
   //EventAdd(EVMSG_ACTIVEVIEWCHANGED);
   GeData da(BASEDRAW_PROJECTION_TOP);
   bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
  }
  break;
 case 2:
  {
   //BaseDraw *bd = doc->GetBaseDraw( 2);
   //bd->SetBit( BIT_ACTIVE );
   //bd->SetBit( BIT_DOCUMENT_CHECKREWIND );
   GeData da(BASEDRAW_PROJECTION_RIGHT);
   bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
  }
  
  break;
 case 3:
  {
   //BaseDraw *bd = doc->GetBaseDraw( 3);
   //bd->SetBit( BIT_ACTIVE );
   //bd->SetBit( BIT_DOCUMENT_CHECKREWIND );
  
   GeData da(BASEDRAW_PROJECTION_FRONT);
   bd->SetParameter(DescLevel(BASEDRAW_DATA_PROJECTION),da,NULL);
  }
  break;
 }
 
 EventAdd();
}

void GetAllCameras(AtomArray *oCams,BaseObject *oCam)
{
     if(oCam)
     {
          if(oCam->GetType()==Ocamera)
               oCams->Append(oCam);
          if(oCam->GetDown())
               GetAllCameras(oCams,oCam->GetDown());
          if(oCam->GetNext())
               GetAllCameras(oCams,oCam->GetNext());
     }
}
LONG GetAllCameras(AtomArray *oCams)
{
     if(!oCams)
  {
   //MessageDialog("Alloc AtomArray Fail that Can't get Camera ");
   return 0;
  }
     BaseDocument *doc=GetActiveDocument();
     BaseObject *obj=doc->GetFirstObject();
     if(obj)
     {
          GetAllCameras(oCams,obj);
     }
     return oCams->GetCount();
}
 
static void GetCameraSnapshoot( void )
{
 LONG nCount = 0;
 LONG nIndex[256] ={0};
 
 
 AtomArray *oCameras = AtomArray::Alloc();
 if ( !oCameras )
 {
  return ;
 }
  
    LONG lCamCnt = GetAllCameras(oCameras);
 BaseDocument* doc = GetActiveDocument();
 
 //MessageDialog( LongToString(lCamCnt) );
    for(LONG i = 0;i < lCamCnt; i++)
    {
        BaseObject *obj=(BaseObject * )oCameras->GetIndex(i);
        MessageDialog(obj->GetName());
  if ( !obj) break;
       
  String camname = obj->GetName();
  LONG iLen = camname.GetCStringLen(St8bit)+1;
  char* pName = bNew CHAR[iLen];
   
  camname.GetCString( pName,iLen);
  BaseObject * oldcam = doc->GetRenderBaseDraw()->GetSceneCamera( doc );
  doc->GetRenderBaseDraw()->SetSceneCamera( obj );
    
  Snapshoot( pName ); //perspective is snapshoot name
  bDelete(pName);
 
    }
 AtomArray::Free(oCameras) ;
 
 return ;
}

this is my some codes: to get snapshoot (viewport and cameras) when the plugin be clicked and launch my operation windonws

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

On 06/08/2007 at 22:43, xxxxxxxx wrote:

AtomArray *oCameras = AtomArray::Alloc();
   the oCamera is NULL  when testing.  it was alloc failed